node.js - node-odbc causes error "CLI0002W Data truncated" -


i using node-odbc connect node.js-based application legacy ibm db2 database.

  • on windows 7
  • the db2 odbc drivers 32bit, therefore node-odbc binaries have been created node-gyp clean configure build --arch=ia32 --msvs_version=2015
  • node.js 4.4.5 in 32bit

this works fine. however, have unicode disabled in node-odbc binaries (flag unicode in binding.gyp) because of following problem:

if enable unicode, can

  1. correctly retrieve data simple sql statements (like query = select * sysibm.sysdummy1)
  2. run queries non-string parameter binding (like query = select * syscat.tables tableid = ?, bindings = [0];

however, if run query string parameters (like query = select * syscat.tables tabname = ?, bindings = ['sysdummy1']), odbc driver throws error message

{ [error: [ibm][cli driver] cli0002w data truncated. sqlstate=01004] errors: [ { message: '[ibm][cli driver] cli0002w data truncated. sqlstate=01004', state: '01004' } ], error: '[node-odbc] sql_error', message: '[ibm][cli driver] cli0002w data truncated. sqlstate=01004', state: '01004' }

its explanation @ ibm documentation doesn't me.

i looked @ unicode-enabled snippets in relevant node-odbc code write string buffer passed odbc driver:

#ifdef unicode       params[i].parametertype     = sql_wvarchar;       params[i].bufferlength      = (length * sizeof(uint16_t)) + sizeof(uint16_t); #else       params[i].parametertype     = sql_varchar;       params[i].bufferlength      = string->utf8length() + 1; #endif       params[i].parametervalueptr = malloc(params[i].bufferlength);       params[i].strlen_or_indptr  = sql_nts;//params[i].bufferlength;  #ifdef unicode       string->write((uint16_t *) params[i].parametervalueptr); #else       string->writeutf8((char *) params[i].parametervalueptr); #endif 

apparently, string->write writes string null-terminal buffer parametervalueptr. sql_nts means null-terminated string (see explanation of strlen_or_indptr @ ibm documentation).

judging error message, assume buffer not have correct size, calculated (length * sizeof(uint16_t)) + sizeof(uint16_t) (length of string in bytes unicode characters + 1 additional character, null terminator):

  1. either it's small, odbc driver cannot find null character terminates string
  2. or big, maybe drivers complains null character comes before end of buffer. really assumption!

so: wonder how code should corrected string-like parameters can passed odbc driver. ideas?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -