f Perl 存取 Tibero資料庫 ~ 迪貝之家

Perl 存取 Tibero資料庫

照原廠文件所述
Tibero Perl Integration
它是用一個叫iodbc的open source作為ODBC的介面
但底層還是要有Tibero給出來的odbc driver
$TB_HOME/client/lib/libtbodbc.so
這是我的環境
Perl : Ubuntu 18.04.4
Tibero: Tac on Debian 10
Client Config tbdsn.tbr:
tac =
((INSTANCE = (HOST = 192.168.56.12)
(PORT = 8629)
(DB_NAME = tac))
(INSTANCE = (HOST = 192.168.56.13)
(PORT = 8629)
(DB_NAME = tac))
(LOAD_BALANCE = Y)
(USE_FAILOVER = Y)
)
當下iodbc tarball是libiodbc-3.52.10.tar
這是安裝
export LDFLAGS="-brtl"
./configure --prefix=/root/tibero6/iodbc --with-iodbc-inidir=/root/tibero6/iodbc/etc --disable-gui
照原廠文件所述,brtl 加了上去
configure指令就出錯
configure: error: in `/root/libiodbc-3.52.12':
configure: error: C compiler cannot create executables
See `config.log' for more details
依照它的指示,去看了config.log的內容
嘿~~它不認得brtl flag
configure:3518: gcc -brtl conftest.c >&5
gcc: error: unrecognized command line option '-brtl'; did you mean '-mrtd'?
其實還沒執行configure之前
我就google 了LDFLAGS
就是沒查到brtl到底是什麼 ??
所以這裡我就把它給槓掉了
至於--with-iodbc-inidir=/root/tibero6/iodbc/etc
我後續再談
iODBC Driver Manager 3.52.12 configuration summary
==================================================
Installation variables
layout default
prefix /root/tibero6/iodbc
exec_prefix ${prefix}
Installation paths
programs ${exec_prefix}/bin
include files ${prefix}/include
libraries ${exec_prefix}/lib
manual pages ${datarootdir}/man
Configuration files
odbc.ini /root/tibero6/iodbc/etc/odbc.ini
odbcinst.ini /root/tibero6/iodbc/etc/odbcinst.ini
default FILEDSN path /root/tibero6/iodbc/etc/ODBCDataSources
Extensions
ODBC Version 3
GUI Extensions false
ThreadSafe true
Install libodbc.so true
接下來就是透過iodbctest工具來測試
這真是夢靨阿~~
照著文件指示去config dsn記錄
iodbctest怎麼測就是告訴你找不到你所設定的DSN記錄
不管參照的路徑是/etc/odbc.ini還是~/.odbc.ini
或者我compile所指定的設定檔目錄
--with-iodbc-inidir=/root/tibero6/iodbc/etc
都一樣找不到我所設定的DSN
一律的回覆你底下這個訊息
[iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded, SQLSTATE=IM002
我只好又上網去找資料了
恩............
要由環境變數指定odbcinst.ini
export ODBCINI=/root/tibero6/iodbc/etc/odbcinst.ini
真是不由得握緊了拳頭
算了~~ open source 嘛!!
我的odbcinst.ini的內容
iodbc tsn setup
iodbctest的測試結果
接下來就是安裝DBI 及DBD::ODBC
就照著iodbc 的installation guide吧~~
因為DBD::ODBC得去指定你所compile的iodbc home directory
不然應該找不到iodbc相應的library
我沒測過所有的步驟都透過deb 安裝
也許都用apt-get install來安裝預設封裝
會把所有的設定都搞定吧~~
安裝DBI :
bash# perl -MCPAN -e shell
cpan>install DBI
安裝DBD::ODBC
它是先用cpan把最新的source tarball下載回來
然後再進到相應的目錄進行compile
應該是為了指定iodbc的home directory
bash# perl -MCPAN -e shell
cpan>get DBD::ODBC
cpan的畫面會告訴你source tarball放在哪裡
我的環境如下
/root/.cpan/sources/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.61.tar.gz
進到/root/.cpan/sources/authors/id/M/MJ/MJEVANS
解tar
tar xvf DBD-ODBC-1.61.tar.gz
cd DBD-ODBC-1.61
指定odbc home directory
export ODBCHOME=/root/tibero6/iodbc
perl Makefile.PL
make
make install
到目前為止
環境已經搞定
接下來就是抄原廠文件上的perl script來進行測試
root@tbtools:~# cat test.pl
use strict;
use DBI;
my $dbh = DBI->connect("dbi:ODBC:tac","ot","ot");
my $sql = qq{select deptno,dname,loc from dept};
my $sth = $dbh->prepare($sql);
$sth->execute();
my ($deptno, $dname, $loc);
$sth->bind_columns(undef, \$deptno, \$dname, \$loc);
while($sth->fetch()) {
print "$deptno, $dname ,$loc\n";
}
$sth->finish();
$dbh->disconnect();
測試