Skip to content

Commit

Permalink
Fix of connector and testcases to make them work
Browse files Browse the repository at this point in the history
everywhere(Windows, UnixODBC, Travis, Appveyor, iOdbc) - not guearantee
that it really does it, but approaches that goal for sure.
Fix of bug in conversion of utf8 to utf16 if utf8string contains character(s) resquiring 2 SQLWCHAR units in utf16 encoding.
Change of SQL_MAX_COLUMN_NAME_LEN to be 255(256-1), since that is
effectively the longest name len that c/c provides
  • Loading branch information
lawrinn committed Jan 10, 2019
1 parent 3111b4f commit 976a667
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ma_connection.c
Expand Up @@ -1313,7 +1313,7 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, 0, StringLengthPtr);
break;
case SQL_MAX_COLUMN_NAME_LEN:
MADB_SET_NUM_VAL(SQLUSMALLINT, InfoValuePtr, NAME_CHAR_LEN * SYSTEM_MB_MAX_CHAR_LENGTH, StringLengthPtr);
MADB_SET_NUM_VAL(SQLUSMALLINT, InfoValuePtr, NAME_CHAR_LEN * SYSTEM_MB_MAX_CHAR_LENGTH - 1, StringLengthPtr);
break;
case SQL_MAX_COLUMNS_IN_GROUP_BY:
MADB_SET_NUM_VAL(SQLUSMALLINT, InfoValuePtr, 0, StringLengthPtr);
Expand Down
16 changes: 11 additions & 5 deletions ma_platform_posix.c
Expand Up @@ -248,7 +248,7 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
SQLINTEGER RequiredLength;
SQLWCHAR *Tmp= UnicodeString;
int rc= 0, error;
size_t src_octet_len, dest_octet_len;
size_t SrcOctetLen, DestOctetLen;

if (LengthIndicator)
*LengthIndicator= 0;
Expand Down Expand Up @@ -280,13 +280,19 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
return 0;

if (RequiredLength > UnicodeLength)
{
Tmp= (SQLWCHAR *)malloc(RequiredLength * sizeof(SQLWCHAR));
}
else
{
RequiredLength= UnicodeLength;
}

src_octet_len= AnsiLength + IsNull;
dest_octet_len= sizeof(SQLWCHAR) * RequiredLength;
SrcOctetLen= AnsiLength + IsNull;
DestOctetLen= sizeof(SQLWCHAR) * RequiredLength;

RequiredLength= mariadb_convert_string(AnsiString, &src_octet_len, cc->cs_info,
(char*)Tmp, &dest_octet_len, DmUnicodeCs, &error);
RequiredLength= mariadb_convert_string(AnsiString, &SrcOctetLen, cc->cs_info,
(char*)Tmp, &DestOctetLen, DmUnicodeCs, &error);

if (RequiredLength < 1)
{
Expand Down
2 changes: 1 addition & 1 deletion ma_platform_win32.c
Expand Up @@ -222,7 +222,7 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
/* Returns required length for result string with(if dest and dest length are provided)
or without terminating NULL(otherwise). If cc is NULL, or not initialized(CodePage is 0),
then simply SrcLength is returned.
If Dest is not NULL, and DestLenth is 0, then error*/
If Dest is not NULL, and DestLenth is 0, then error */
SQLLEN MADB_SetString(Client_Charset* cc, void *Dest, SQLULEN DestLength,
const char *Src, SQLLEN SrcLength/*bytes*/, MADB_Error *Error)
{
Expand Down
2 changes: 1 addition & 1 deletion ma_statement.c
Expand Up @@ -2746,7 +2746,7 @@ SQLRETURN MADB_StmtGetData(SQLHSTMT StatementHandle,
return MADB_SetError(&Stmt->Error, MADB_ERR_HY001, NULL, 0);
}

CharLength= MADB_SetString(&Stmt->Connection->Charset, IrdRec->InternalBuffer, (SQLINTEGER)ReqBuffOctetLen,
CharLength= MADB_SetString(&Stmt->Connection->Charset, IrdRec->InternalBuffer, (SQLINTEGER)ReqBuffOctetLen / sizeof(SQLWCHAR),
ClientValue, Stmt->stmt->fields[Offset].max_length - Stmt->CharOffset[Offset], &Stmt->Error);
}
else
Expand Down
4 changes: 1 addition & 3 deletions test/catalog1.c
Expand Up @@ -531,9 +531,7 @@ ODBC_TEST(t_columns)

CHECK_STMT_RC(Stmt, SQLFetch(Stmt));

/* if you get -8 for col1 here - that's fine. depends on setup. the test probably needs
to be changed accordingly */
is_num(DataType, Values[i][0][0]);
is_num(DataType, GetDefaultCharType(Values[i][0][0], TRUE));
is_num(cbDataType, Values[i][0][1]);

is_num(ColumnSize, Values[i][1][0]);
Expand Down
4 changes: 2 additions & 2 deletions test/catalog2.c
Expand Up @@ -667,7 +667,7 @@ ODBC_TEST(t_sqlprocedurecolumns)
case SQL_TYPE_DATE: data_to_check[iter].c06_data_type= SQL_DATE; break;
}
}
is_num(my_fetch_int(Hstmt1, 6), data_to_check[iter].c06_data_type);
is_num(my_fetch_int(Hstmt1, 6), GetDefaultCharType(data_to_check[iter].c06_data_type,TRUE));

IS_STR(my_fetch_str(Hstmt1, buff, 7),
data_to_check[iter].c07_type_name,
Expand All @@ -684,7 +684,7 @@ ODBC_TEST(t_sqlprocedurecolumns)

is_num(my_fetch_int(Hstmt1, 11), data_to_check[iter].c11_num_prec_radix);

is_num(my_fetch_int(Hstmt1, 15), data_to_check[iter].c15_sql_data_type);
is_num(my_fetch_int(Hstmt1, 15), GetDefaultCharType(data_to_check[iter].c15_sql_data_type, TRUE));

is_num(my_fetch_int(Hstmt1, 16), data_to_check[iter].c16_sql_datetime_sub);

Expand Down
3 changes: 0 additions & 3 deletions test/info.c
Expand Up @@ -439,9 +439,6 @@ ODBC_TEST(t_bug11749093)
NULL, NULL, NULL, NULL));

/* Checking that name is trimmed to SQL_MAX_COLUMN_NAME_LEN including teminating NULL. */
#ifdef _WIN32
skip("This test currently fails on Windows becasue of the bug in current version of c/c");
#endif
is_num(colNameLen, maxColLen);
is_num(colNameLen, strlen(colName));
IS_STR(colName, "1234567890+2234567890+3234567890"
Expand Down
19 changes: 19 additions & 0 deletions test/tap.h
Expand Up @@ -1285,4 +1285,23 @@ BOOL UnixOdbc()
return FALSE;
}


int GetDefaultCharType(int WType, BOOL isAnsiConnection)
{
#ifdef _WIN32
if (isAnsiConnection != FALSE)
{
switch (WType) {
case SQL_WCHAR:
return SQL_CHAR;
case SQL_WVARCHAR:
return SQL_VARCHAR;
case SQL_WLONGVARCHAR:
return SQL_LONGVARCHAR;
}
}
#endif

return WType;
}
#endif /* #ifndef _tap_h_ */

0 comments on commit 976a667

Please sign in to comment.