개요
tibero - python 연동 방안으로 python odbc를 이용하여 진행한 시나리오입니다.
방법
참고
Tibero 6 버전에서 진행한 시나리오 입니다.
1. gcc, python 버전 확인
[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.
SQL
복사
2. tibero 기동 확인 및 client lib확인
[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
SQL
복사
3. developer package 설치 (yum 이용)
pyodbc 컴파일을 위해 developer package가 필요합니다. 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
SQL
복사
4. pyodbc 설치 (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
>>>
#. import pyodbc가 정상 수행 되면 위와 같이 error 메시지가 남지 않음.
SQL
복사
5. DSN 설정
[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
#. unixODBC를 이용하여 connect 확인
[root@std ~]# isql -v tibero6
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL
복사
6. python 연동 확인
[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)
#. 수행 결과
[root@std ~]# python test.py
('tibero', 'tibero')
SQL
복사