「unixODBCでDB2を使った時のnullの問題」の編集履歴(バックアップ)一覧に戻る
unixODBCでDB2を使った時のnullの問題 - (2017/05/27 (土) 22:10:13) の編集履歴(バックアップ)
何故かunixODBCでDB2を使った時に null値があるとうまく動かない
SQL> SELECT sid,sid_nk,pms_u_ymd,COALESCE(dummykbn,'') from syoyuki where sid=456; +------------+-------------+---------------------------+--+ | SID | SID_NK | PMS_U_YMD | 4| +------------+-------------+---------------------------+--+ | 456 | 456 | 456 | | +------------+-------------+---------------------------+--+ SQLRowCount returns -1 1 rows fetched
PMS_U_YMD 、dummykbnの2つがnullである。
dummykbnは強制的にCOALESCEでnullなら'' に変えている。as句をつけてないのでカラム名が4になっています。
しかし、PMS_U_YMDはnullのため、何故か1つ前の項目と同じ値が入っています。
英文のサイトを見ても解決策はなさそう。やっぱりCOALESCEを使えとか書いてある。
しかし、DB2のモジュールが合ってないとか書いてた英文のサイトもあったような気がする。
もう一度、検索してみよう。
http://www-01.ibm.com/support/docview.wss?uid=swg21689265
これじゃない?
As in the example above, the segmentation fault occurs because libdb2.so is specified (which is the 32-bit ODBC driver) whereas the application is 64-bit so the driver should be pointing to libdb2o.so (which is the 64-bit ODBC driver). The line should then read:
ふむふむ、32bitと64bitではドライバーが違う?え~っと、今のサーバーは64bitだ。odbcinst.iniを確かめる。
何と、32bit版になっている。早速64bit版に書き換えよう。
Type of application | DB2 driver to specify |
32-bit ODBC Driver Manager | libdb2.* |
64-bit ODBC Driver Manager | libdb2o.* (db2o.o for AIX) |
変更後、もう一度チャレンジ。
SQL> SELECT sid,sid_nk,pms_u_ymd,COALESCE(dummykbn,'') as dummykbn from syoyuki where sid=456; +------------+-------------+---------------------------+--+ | SID | SID_NK | PMS_U_YMD | 4| +------------+-------------+---------------------------+--+ | 456 | 456 | | | +------------+-------------+---------------------------+--+
SQL> SELECT sid,sid_nk,pms_u_ymd,dummykbn from syoyuki where sid=456; +------------+-------------+---------------------------+---------+ | SID | SID_NK | PMS_U_YMD | DUMMYKBN| +------------+-------------+---------------------------+---------+ | 456 | 456 | | | +------------+-------------+---------------------------+---------+ SQLRowCount returns -1 1 rows fetched