gaucheでOracleにアクセスする

2019年

oracleのサイトから、以下のOracle Instant Clientのファイルをダウンロードする
 - instantclient-basic-linux.x64-11.2.0.4.0.zip
 - instantclient-sdk-linux.x64-11.2.0.4.0.zip

・/optに展開する
 # cd /opt
 # unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
 # unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip
 # cd /opt/instantclient_11_2/
 # ln -s libclntsh.so.11.1 libclntsh.so

・LD_LIBRARY_PATHの設定
 # LD_LIBRARY_PATH=/opt/instantclient_11_2
 # export LD_LIBRARY_PATH

・以下のサイトにアクセスし、Gauche-dbd-oracle-master.zipをダウンロードする
 https://github.com/kubo/Gauche-dbd-oracle

・tarballを作成する
 # unzip Gauche-dbd-oracle-master.zip
 # cd Gauche-dbd-oracle-master
 # ./DIST gen
 # ./DIST tgz

・インストールする
 # cd ..
 # gauche-package install -C --with-instant-client=/opt/instantclient_11_2 Gauche-dbd-oracle-0.0.1.tgz

oracleにアクセスしてみる
 $ gosh
 gosh> (use dbi)
 gosh> (use gauche.collection)
 gosh> (define conn (dbi-connect "dbi:oracle://192.168.0.15/xe" :username "hr" :password "hr"))
 conn
 gosh> (define res (dbi-do conn "select * from jobs"))
 res
 gosh> (d res)
 #< 0x168eef0> is an instance of class
 slots:
  columns : #("job_id" "job_title" "min_salary" "max_salary")
  rows : (#("AD_PRES" "President" 20080 40000) #("AD_VP" "Administrat
 gosh>

2016年

下のページからGauche-dbd-oracle-master.zipをダウンロードし、インストールする。
https://github.com/kubo/Gauche-dbd-oracle

$ unzip Gauche-dbd-oracle-master.zip
$ cd Gauche-dbd-oracle-master/
$ ./DIST tgz
$ cd ../
$ gauche-package install --install-as=root Gauche-dbd-oracle-0.0.1.tgz 
....
gcc -std=gnu99  '-L/usr/lib64/gauche-0.9/0.9.4/x86_64-redhat-linux-gnu' '-L/usr/lib64/gauche-0.9/site/x86_64-redhat-linux-gnu'  -shared -o dbd_oracle.so 'dbd_oracle.o' 'bind_handle.o' 'dbd_oraclelib.o' -lgauche-0.9 -ldl -lcrypt -lutil -lrt -lm  -lpthread -L/u01/app/oracle/product/11.2.0/xe/lib -lclntsh
gmake: `check' に対して行うべき事はありません.
[sudo] password for xxx: 
ERROR: command execution failed: cd "./Gauche-dbd-oracle-0.0.1"; "/usr/bin/sudo" -u "root" -S "/usr/bin/gmake" install
Stack Trace: _______________________________________ 0 (make-install config dir sudo-user sudo-pass) At line 157 of "/usr/share/gauche-0.9/0.9.4/lib/gauche/package/build.scm" 1 (x (cddr args)) [unknown location] $ su パスワード: # gauche-package install Gauche-dbd-oracle-0.0.1.tgz checking for gosh... /usr/bin/gosh checking for gauche-config... /usr/bin/gauche-config checking for gauche-package... /usr/bin/gauche-package checking for gauche-install... /usr/bin/gauche-install checking for gauche-cesconv... /usr/bin/gauche-cesconv configure: creating Gauche-dbd-oracle.gpd configure: creating ./config.status config.status: creating Makefile /usr/bin/gauche-package compile --local= --verbose \ --cflags="-I/u01/app/oracle/product/11.2.0/xe/rdbms/public -I/u01/app/oracle/product/11.2.0/xe/rdbms/demo" --libs="-L/u01/app/oracle/product/11.2.0/xe/lib -lclntsh" \ dbd_oracle ./dbd_oracle.c ./bind_handle.c ./dbd_oraclelib.stub gcc -std=gnu99 -c '-I/usr/lib64/gauche-0.9/0.9.4/include' '-I/usr/lib64/gauche-0.9/site/include' -I/u01/app/oracle/product/11.2.0/xe/rdbms/public -I/u01/app/oracle/product/11.2.0/xe/rdbms/demo -fPIC -o 'dbd_oracle.o' './dbd_oracle.c' gcc -std=gnu99 -c '-I/usr/lib64/gauche-0.9/0.9.4/include' '-I/usr/lib64/gauche-0.9/site/include' -I/u01/app/oracle/product/11.2.0/xe/rdbms/public -I/u01/app/oracle/product/11.2.0/xe/rdbms/demo -fPIC -o 'bind_handle.o' './bind_handle.c' gcc -std=gnu99 -c '-I/usr/lib64/gauche-0.9/0.9.4/include' '-I/usr/lib64/gauche-0.9/site/include' -I/u01/app/oracle/product/11.2.0/xe/rdbms/public -I/u01/app/oracle/product/11.2.0/xe/rdbms/demo -fPIC -o 'dbd_oraclelib.o' './dbd_oraclelib.c' gcc -std=gnu99 '-L/usr/lib64/gauche-0.9/0.9.4/x86_64-redhat-linux-gnu' '-L/usr/lib64/gauche-0.9/site/x86_64-redhat-linux-gnu' -shared -o dbd_oracle.so 'dbd_oracle.o' 'bind_handle.o' 'dbd_oraclelib.o' -lgauche-0.9 -ldl -lcrypt -lutil -lrt -lm -lpthread -L/u01/app/oracle/product/11.2.0/xe/lib -lclntsh gmake: `check' に対して行うべき事はありません. /usr/bin/gauche-install -C -m 444 -T /usr/lib/gauche-0.9/site/include /usr/bin/gauche-install -C -m 444 -T /usr/share/gauche-0.9/site/lib ./dbd/oracle.scm /usr/bin/gauche-install -C -m 555 -T /usr/lib/gauche-0.9/site/x86_64-redhat-linux-gnu dbd_oracle.so /usr/bin/gauche-install -C -m 444 -T /usr/share/gauche-0.9/site/lib/.packages Gauche-dbd-oracle.gpd

Oracleにアクセスする

$ gosh
gosh> (use dbi)
#
gosh> (use gauche.collection)
#
gosh> (define conn (dbi-connect "dbi:oracle://bros/XE" :username "hr" :password "hr"))
ERROR: Compile Error: can't find dlopen-able module "dbd_oracle"
Stack Trace: _______________________________________ 0 (eval `(require ,(path-sans-extension path)) (current-module)) At line 213 of "/usr/share/gauche-0.9/0.9.4/lib/dbi.scm" 1 (dbi-make-driver driver-name) At line 117 of "/usr/share/gauche-0.9/0.9.4/lib/dbi.scm" 2 (dbi-connect "dbi:oracle://bros/XE" :username "hr" :password "hr") At line 15 of "(standard input)" 3 (eval expr env) At line 179 of "/usr/share/gauche-0.9/0.9.4/lib/gauche/interactive.scm" gosh> (exit)
$ cd /usr/lib64/gauche-0.9/0.9.4/x86_64-redhat-linux-gnu/
$ sudo cp /usr/lib/gauche-0.9/site/x86_64-redhat-linux-gnu/dbd_oracle.so .
[sudo] password for xxx:
$ gosh
gosh> (use dbi)
#
gosh> (use gauche.collection)
#
gosh> (define conn (dbi-connect "dbi:oracle://bros/XE" :username "hr" :password "hr"))
conn
gosh> (define res (dbi-do conn "select * from jobs"))
res
gosh> (d res)
#< 0x1f74be0> is an instance of class 
slots:
  columns   : #("job_id" "job_title" "min_salary" "max_salary")
  rows      : (#("AD_PRES" "President" 20080 40000) #("AD_VP" "Administrat
gosh> 
ヽ(;´Д`)ノアクセスできた〜 参照したURL: http://www.atmarkit.co.jp/ait/articles/0901/16/news154_3.html