alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
348 stars 139 forks source link

Missing Error Message When Using Chinese Locale on Informix #155

Closed knight-ni closed 3 years ago

knight-ni commented 3 years ago

My odbc.ini

;---------------------------------------------------------------------------
; GBase dbt ODBC Sample File
;
; File:         odbc.ini
;
;---------------------------------------------------------------------------
[ODBC Data Sources]
Infdrv1=gbase8s
; Define ODBC Database Driver's Below - Driver Configuration Section
;

[gbase8s]
Driver=/opt/GBASE/gbase/lib/cli/iclit09b.so
Description=GBase ODBC DRIVER
Server=ol_gbasedbt10
Database=sysmaster
UID=gbasedbt
PWD=P@ssw0rd0LD
DB_LOCALE=zh_CN.utf8
CLIENT_LOCALE=zh_CN.utf8
GL_USEGLU=1
ISOLATIONLEVEL=1
TRANSLATIONDLL=/opt/GBASE/gbase/lib/esql/igo4a304.so

; UNICODE connection Section
;
[ODBC]
;uncomment the below line for UNICODE connection
;UNICODE=UCS-4
UNICODE=UCS-2

;
; Trace file Section
;
Trace=0
TraceFile=/tmp/odbctrace.out
InstallDir=/extra/informix
TRACEDLL=idmrs09a.so

isql works fine with LANG set to zh_CN.utf8

[root@gbasehost server]# isql -v gbase8s
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> ljaksjdf
[37000][GBasedbt][GBasedbt ODBC Driver][GBasedbt]发生语法错误。
[ISQL]ERROR: Could not SQLPrepare
SQL> select * from tttt;
[S0002][GBasedbt][GBasedbt ODBC Driver][GBasedbt]指定的表 "tttt" 不在数据库中。
[ISQL]ERROR: Could not SQLPrepare

but got messy codes as followed with programe

[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]䋷羧멃羧룠羧멢羧뇮羧]]]
[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]쁣羧쁮羧䌟羧뫥羧䌷羧䊸羧䋷羧멃羧룠羧멢羧뇮羧]]]
[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]쁣羧쁮羧䌟羧뫥羧䌷羧䊸羧䋷羧멃羧룠羧멢羧뇮羧]]]

and it works fine with en_US.utf8

[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]The specified table (asdfdual) is not in the database.]]]
[root@gbasehost client]# ./client -m sql -s "select 1111 from asdfdual"
[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]The specified table (asdfdual) is not in the database.]]]
[root@gbasehost client]# ./client -m sql -s "select 1111 from asdfdual"
[map[DB Error:[SQLPrepare: {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]The specified table (asdfdual) is not in the database.]]]

I also tried to reinstall unixODBC with --enable-iconv=yes --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE but not work actually i found Message in struct DiagRecord which generated by api.SQLGetDiagRec seems already wrong as chinese utf16 code, what can i do to fix this?

image

BTW i tried branch for_issue_88 but will truncate error message {42S02} [GBasedbt][GBasedbt ODBC Driver][GBasedbt]指定的表 "asdfdual" ] it should be looks like this in isql [S0002][GBasedbt][GBasedbt ODBC Driver][GBasedbt]指定的表 "asdfdual" 不在数据库中。

knight-ni commented 3 years ago

have beed fixed by assign msgptr to SQLGetDiagRec like this

        ret := api.SQLGetDiagRec(ht, h, api.SQLSMALLINT(i),
            (*api.SQLCHAR)(unsafe.Pointer(&state[0])), &ne,
            (*api.SQLCHAR)(unsafe.Pointer(&msg[0])),
            api.SQLSMALLINT(len(msg)), &SQLmsglen)
alexbrainman commented 3 years ago

@knight-ni I am glad you fixed your problem. I still do not know what your problem is, but should we change some code here for future users?

Alex