@@ -3666,7 +3666,6 @@ static BOOL xstr_to_number(esodbc_stmt_st *stmt, void *data_ptr,
36663666SQLRETURN c2sql_null (esodbc_rec_st * arec ,
36673667 esodbc_rec_st * irec , char * dest , size_t * len )
36683668{
3669- assert (irec -> concise_type == ESODBC_SQL_NULL );
36703669 if (dest ) {
36713670 memcpy (dest , JSON_VAL_NULL , sizeof (JSON_VAL_NULL ) - /*\0*/ 1 );
36723671 }
@@ -4617,6 +4616,37 @@ SQLRETURN c2sql_interval(esodbc_rec_st *arec, esodbc_rec_st *irec,
46174616# undef ASSIGN_SIGNED
46184617}
46194618
4619+ static inline SQLLEN get_octet_len (SQLLEN * octet_len_ptr , void * data_ptr ,
4620+ BOOL wide )
4621+ {
4622+ SQLLEN cnt ;
4623+
4624+ assert (data_ptr );
4625+
4626+ if (! octet_len_ptr ) {
4627+ /* "If [...] is a null pointer, the driver assumes that all input
4628+ * parameter values are non-NULL and that character and binary data is
4629+ * null-terminated." */
4630+ cnt = wide ? wcslen ((wchar_t * )data_ptr ) : strlen ((char * )data_ptr );
4631+ } else {
4632+ cnt = * octet_len_ptr ;
4633+ switch (cnt ) {
4634+ case SQL_NTSL :
4635+ cnt = wide ? wcslen ((wchar_t * )data_ptr ) :
4636+ strlen ((char * )data_ptr );
4637+ break ;
4638+ case SQL_NULL_DATA :
4639+ BUG ("converting SQL_NULL_DATA" );
4640+ cnt = -1 ; /* UTF16/8 will fail */
4641+ break ;
4642+ default : /* get characters count from octets count */
4643+ cnt /= wide ? sizeof (SQLWCHAR ) : sizeof (SQLCHAR );
4644+ }
4645+ }
4646+
4647+ return cnt ;
4648+ }
4649+
46204650static SQLRETURN c2sql_cstr2qstr (esodbc_rec_st * arec , esodbc_rec_st * irec ,
46214651 SQLULEN pos , char * dest , size_t * len )
46224652{
@@ -4629,7 +4659,7 @@ static SQLRETURN c2sql_cstr2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
46294659 /* pointer to app's buffer */
46304660 data_ptr = deferred_address (SQL_DESC_DATA_PTR , pos , arec );
46314661
4632- cnt = octet_len_ptr ? * octet_len_ptr : strlen (( char * ) data_ptr );
4662+ cnt = get_octet_len ( octet_len_ptr , data_ptr , /*wide*/ FALSE );
46334663
46344664 if (dest ) {
46354665 * dest = '"' ;
@@ -4663,7 +4693,7 @@ static SQLRETURN c2sql_wstr2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
46634693 /* pointer to app's buffer */
46644694 data_ptr = deferred_address (SQL_DESC_DATA_PTR , pos , arec );
46654695
4666- cnt = octet_len_ptr ? * octet_len_ptr : wcslen (( wchar_t * ) data_ptr );
4696+ cnt = get_octet_len ( octet_len_ptr , data_ptr , /*wide*/ TRUE );
46674697
46684698 if (dest ) {
46694699 * dest = '"' ;
@@ -4682,7 +4712,7 @@ static SQLRETURN c2sql_wstr2qstr(esodbc_rec_st *arec, esodbc_rec_st *irec,
46824712 octets = U16WC_TO_MBU8 ((wchar_t * )data_ptr , cnt , dest + !!dest ,
46834713 dest ? INT_MAX : 0 );
46844714 if ((err = WAPI_ERRNO ()) != ERROR_SUCCESS ) {
4685- ERRH (stmt , "converting to multibyte string failed: %d " , err );
4715+ ERRH (stmt , "converting to multibyte string failed: 0x%x " , err );
46864716 RET_HDIAGS (stmt , SQL_STATE_HY000 );
46874717 }
46884718 assert (0 < octets ); /* shouldn't not fail and return negative */
0 commit comments