end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

unixODBC のインストール

ibm System i Access によるDB接続には、unixODBC が必要なので、インストールします。
unixODBCをインストールすることで、postgresのodbcドライバ(※)もインストールされます。

※/usr/lib/libodbcpsql.so , /usr/lib/libodbcpsqlS.so

g++

どうやらg++が必要らしいので...

# yum install gcc-c++

install

unixODBC-2.2.12/INSTALL によれば...

If you want to install any of the GUI components, you must have also
installed the Qt libraries from http://www.troll.no Version 3 or above
is now required.

Qtが必要だとX11も必要になるので、GUIなし( --disable-gui )でインストールします。

$ cd unixODBC-2.2.12
$ ./configure --disable-gui
$ make
# make install

用意したテストデータ

$ /usr/local/pgsql/bin/psql -U postgres test
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.

  :

test=# select * from test;
   col1   |   col2   
----------+----------
 Tokyo    | Shinjuku
 Fukuoka  | Fukuoka
 Kanagawa | 横浜
(3 rows)

~/.odbc.ini

unixODBCの設定ファイルには、/usr/local/etc/odbc.ini , /usr/local/etc/odbcinst.ini , ~/.odbc.ini がありますが、個人の設定内容は、.odbc.iniに記述します。

http://www.unixodbc.org/internals.html

[ODBC Data Sources]
pg_test  = PosrgreSQL ODBC Test

[pg_test]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib/libodbcpsql.so
Setup           = /usr/lib/libodbcpsqlS.so
Servername      = localhost
;Port            = 5432
Database        = test
;Protocol        = 6.4
;ReadOnly        = 0
;ConnSettings    = set client_encoding to euc_jp
FileUsage       = 1
;Debug           = 1
;CommLog         = 1

接続テスト

isql pg_test $DSN $USER P$ASSWD でtest用dbに接続します。

$ isql pg_test postgres postgres
                                                                                • +
Connected!
sql-statement
help [tablename]
quit
                                                                                • +
SQL> select * from test;
col1 col2
Tokyo Shinjuku
Fukuoka Fukuoka
Kanagawa 横浜
SQLRowCount returns 3 3 rows fetched SQL>