Document Type | Technical Information
Field | Interface/Integration
Applicable Product Version | 6FS07
Document Number | TIITI005
Overview
This is a scenario carried out using python odbc as a Tibero - Python integration method.
Method
NoteThis scenario was performed on Tibero version 6.
1. Check gcc and python versions
[root@std ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap
--enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array
--disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
[root@std ~]# python
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
2. Check Tibero startup and client library
[root@std ~]# ps -ef | grep tbsvr
tibero 3033 1 0 10:55 pts/1 00:00:00 tbsvr -t NORMAL -SVR_SID tibero
tibero 3035 3033 0 10:55 pts/1 00:00:00 tbsvr_MGWP -t NORMAL -SVR_SID tibero
tibero 3036 3033 0 10:55 pts/1 00:00:00 tbsvr_FGWP000 -t NORMAL -SVR_SID tibero
tibero 3037 3033 0 10:55 pts/1 00:00:00 tbsvr_FGWP001 -t NORMAL -SVR_SID tibero
tibero 3038 3033 0 10:55 pts/1 00:00:00 tbsvr_PEWP000 -t NORMAL -SVR_SID tibero
tibero 3039 3033 0 10:55 pts/1 00:00:00 tbsvr_PEWP001 -t NORMAL -SVR_SID tibero
tibero 3040 3033 0 10:55 pts/1 00:00:00 tbsvr_PEWP002 -t NORMAL -SVR_SID tibero
tibero 3041 3033 0 10:55 pts/1 00:00:00 tbsvr_PEWP003 -t NORMAL -SVR_SID tibero
tibero 3042 3033 0 10:55 pts/1 00:00:00 tbsvr_AGNT -t NORMAL -SVR_SID tibero
tibero 3043 3033 0 10:55 pts/1 00:00:00 tbsvr_DBWR -t NORMAL -SVR_SID tibero
tibero 3044 3033 0 10:55 pts/1 00:00:00 tbsvr_RCWP -t NORMAL -SVR_SID tibero
root 3245 2854 0 10:57 pts/1 00:00:00 grep --color=auto tbsvr
[root@std ~]# find / -name libtbodbc.so
/db/tibero6_FS07_CS1912/client/lib/libtbodbc.so
/db/tibero6/client/lib/libtbodbc.so
3. Install developer packages (using yum)
Developer packages are required to compile pyodbc. Install them using yum.
[root@std ~]# yum install python-devel
[root@std ~]# yum install unixODBC-devel
[root@std ~]# rpm -qa | grep unixODBC-devel; rpm -qa | grep python-devel
unixODBC-devel-2.3.1-14.el7.x86_64
python-devel-2.7.5-92.el7_9.x86_64
4. Install pyodbc (using yum)
[root@std ~]# yum list pyodbc
pyodbc.x86_64 3.0.10-1.el7 @epel
[root@std ~]# yum install pyodbc.x86_64
[root@std ~]# python
Python 2.7.5 (default, Jun 28 2022, 15:30:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
>>>
#. If import pyodbc executes successfully, no error message appears as above.
5. DSN Configuration
[root@std ~]# cat /etc/odbcinst.ini
[Tibero6]
Driver = /db/tibero6/client/lib/libtbodbc.so
Description = Tibero6 ODBC Datasource
SID = tibero
User = sys
Password = tibero
[root@std ~]# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
[root@std ~]# vi /etc/odbc.ini
[ODBC Data Sources]
tibero6 = Tibero6 ODBC driver
[ODBC]
Trace = 1
Tracefile = /tmp/odbc.trace
[tibero6]
Driver = /db/tibero6/client/lib/libtbodbc.so
Description = Tibero6 ODBC Datasource
SID = tibero
User = sys
Password = tibero
[root@std ~]# vi /root/.odbc.ini
[ODBC Data Sources]
tibero6 = Tibero6 ODBC driver
[ODBC]
Trace = 1
Tracefile = /tmp/odbc.trace
[tibero6]
Driver = /db/tibero6/client/lib/libtbodbc.so
Description = Tibero6 ODBC Datasource
SID = tibero
User = sys
Password = tibero
[root@std ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export JAVA_HOME=/usr/local/bin/java
export PATH=$JAVA_HOME/bin:$PATH
#---- TIBERO ENV
export TB_HOME=/db/tibero6
export TB_SID=tibero
export PATH=.:$TB_HOME/bin:$TB_HOME/client/bin:$JAVA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$TB_HOME/lib:$TB_HOME/client/lib:$LD_LIBRARY_PATH
#. Verify connection using unixODBC
[root@std ~]# isql -v tibero6
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
6. Verify Python Integration
[root@std ~]# vi test.py
#!/bin/python3
import pyodbc
try:
db = pyodbc.connect('DSN=tibero6')
sql = 'select instance_name, db_name from v$instance;'
cursor = db.cursor()
cursor.execute(sql)
data = cursor.fetchall()
for x in data:
print (x)
cursor.close()
db.close()
except Exception as ex:
print(ex)
#. Execution result
[root@std ~]# python test.py
('tibero', 'tibero')