From 05206c8a4dc7b409372203ff7d0984f3cf0c1b16 Mon Sep 17 00:00:00 2001 From: Lawrin Novitsky Date: Wed, 7 Sep 2016 18:25:13 +0200 Subject: [PATCH] Some amendments to ODBC-51 patch on *nix. Also connector returned 0 as available string length in case if application did not provide buffer for it. --- ma_platform_posix.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ma_platform_posix.c b/ma_platform_posix.c index b5f8d1a8..28c80e39 100644 --- a/ma_platform_posix.c +++ b/ma_platform_posix.c @@ -214,9 +214,9 @@ char *MADB_ConvertFromWChar(SQLWCHAR *Ptr, SQLINTEGER PtrLength, SQLULEN *Length AscLen= mariadb_convert_string((char*)Ptr, &PtrOctetLen, utf16, AscStr, &AscLen, cc->cs_info, Error); - if (AscLen != (size_t)-1 && AscLen != 0) + if (AscLen != (size_t)-1) { - if (PtrLength == -1) + if (PtrLength == -1 && AscLen > 0) { --AscLen; } @@ -345,7 +345,11 @@ SQLLEN MADB_SetString(Client_Charset* cc, void *Dest, SQLULEN DestLength, else { Length= MbstrCharLen(Src, SrcLength, cc->cs_info); - return Length; + + /* In case of !DestLength || !Dest(application didn't give buffer and probably wants to know required length) + * we most probably have empty Src, and Length will be equal 0 in this case. + * Taking source length as character length. MultiByteToWideChar on windows does that for us */ + return Length == 0 && SrcLength > 0 ? SrcLength : Length; } }