Skip to content

Commit

Permalink
Fix of display length calculation. Fixes and amndments in/to testcase…
Browse files Browse the repository at this point in the history
…s and testframework. Merge

Conflicts:
	odbc_3_api.c
  • Loading branch information
lawrinn committed Feb 15, 2015
2 parents 9b82f2c + b0672f3 commit 011e68a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
10 changes: 9 additions & 1 deletion ma_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,15 @@ size_t MADB_GetDisplaySize(MYSQL_FIELD Field)
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_VAR_STRING:
return Field.length;
if (Field.charsetnr != 63)
{
CHARSET_INFO *cs= mysql_get_charset_by_nr(Field.charsetnr);
return Field.length/(cs? cs->char_maxlen : 1);
}
else
{
return Field.length;
}
/*
if (Field.flags & BINARY_FLAG)
return Field.length * 2;
Expand Down
2 changes: 1 addition & 1 deletion ma_platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ size_t MADB_SetString(Client_Charset* cc, void *Dest, unsigned int DestLength,
}
}

if (!Src || !strlen(Src) || !SrcLength)
if (!SrcLength || !Src || !strlen(Src))
{
memset(p, 0, cc && cc ? sizeof(SQLWCHAR) : sizeof(SQLCHAR));
return 0;
Expand Down
4 changes: 2 additions & 2 deletions odbc_3_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2260,9 +2260,9 @@ SQLRETURN SQL_API SQLNativeSqlW(SQLHDBC ConnectionHandle,
{
MADB_Dbc *Conn= (MADB_Dbc *)ConnectionHandle;
SQLINTEGER Length= (TextLength1 == SQL_NTS) ? wcslen(InStatementText) : TextLength1;
if (!Dbc)
if (!Conn)
return SQL_INVALID_HANDLE;
MADB_CLEAR_ERROR(&Dbc->Error);
MADB_CLEAR_ERROR(&Conn->Error);

if (TextLength2Ptr)
*TextLength2Ptr= Length;
Expand Down
6 changes: 4 additions & 2 deletions test/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ODBC_TEST(test_CONO3)
return OK;
}


ODBC_TEST(simple_test)
{
SQLRETURN rc= SQL_SUCCESS;
Expand Down Expand Up @@ -94,17 +95,18 @@ ODBC_TEST(simple_test)
SQLGetData(Stmt, 1, SQL_C_USHORT, &value, sizeof(value), 0);
SQLGetData(Stmt, 2, SQL_C_WCHAR, Buffer, 20, 0);
FAIL_IF(value != 1, "Expected value=1");
FAIL_IF(sqlwcharcmp(Buffer, latin_as_sqlwchar("Row no 1", sqlwchar_buff)) != 0, "Expected Buffer = Row no 1");
is_wstr(Buffer, LW("Row no 1"), 9);

rc= SQLFetch(Stmt);
SQLGetData(Stmt, 1, SQL_C_USHORT, &value, sizeof(value), 0);
SQLGetData(Stmt, 2, SQL_C_WCHAR, Buffer, 20, 0);
FAIL_IF(value != 2, "Expected value=2");
FAIL_IF(sqlwcharcmp(Buffer, latin_as_sqlwchar("Row no 2", sqlwchar_buff)) != 0, "Expected Buffer = Row no 2");
is_wstr(Buffer, LW("Row no 2"), 9);

return OK;
}


ODBC_TEST(simple_test1)
{
SQLLEN nRowCount;
Expand Down
13 changes: 6 additions & 7 deletions test/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ ODBC_TEST(t_tables_bug)
ODBC_TEST(t_current_catalog_unicode)
{
SQLWCHAR db[255];
wchar_t cur_db[255];
SQLWCHAR cur_db[255];
SQLRETURN rc;
SQLINTEGER len;

Expand All @@ -648,7 +648,7 @@ ODBC_TEST(t_current_catalog_unicode)
CHECK_DBC_RC(Connection,rc);

is_num(len, strlen(my_schema) * sizeof(SQLWCHAR));
//is_wstr(sqlwchar_to_wchar_t(db), L"test", 5);
is_wstr(db, LW("test"), 5);

rc = SQLSetConnectAttrW(Connection, SQL_ATTR_CURRENT_CATALOG, db, SQL_NTS);
CHECK_DBC_RC(Connection,rc);
Expand All @@ -662,17 +662,15 @@ ODBC_TEST(t_current_catalog_unicode)
OK_SIMPLE_STMT(Stmt, "CREATE DATABASE test_odbc_current");
rc = SQLFreeStmt(Stmt,SQL_CLOSE);

wcscpy(cur_db, L"test_odbc_current");
latin_as_sqlwchar("test_odbc_current", cur_db);
rc = SQLSetConnectAttrW(Connection, SQL_ATTR_CURRENT_CATALOG, cur_db, SQL_NTS);
CHECK_DBC_RC(Connection,rc);

rc = SQLGetConnectAttrW(Connection, SQL_ATTR_CURRENT_CATALOG, db, 255, &len);
CHECK_DBC_RC(Connection,rc);

is_num(len, strlen("test_odbc_current") * sizeof(SQLWCHAR));
//is_wstr(sqlwchar_to_wchar_t(db), cur_db, 18);


is_wstr(db, cur_db, 18);

/* reset for further tests */
rc = SQLSetConnectAttr(Connection, SQL_ATTR_CURRENT_CATALOG, my_schema, SQL_NTS);
Expand Down Expand Up @@ -773,7 +771,8 @@ ODBC_TEST(t_sqltables)
sprintf(query, "CREATE SCHEMA %s", my_schema);
OK_SIMPLE_STMT(Stmt, query);

FAIL_IF(SQLSetConnectAttr(Connection, SQL_ATTR_CURRENT_CATALOG, my_schema, SQL_NTS) != SQL_SUCCESS, "Error occured while setting default db");
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));
CHECK_DBC_RC(Connection, SQLSetConnectAttr(Connection, SQL_ATTR_CURRENT_CATALOG, my_schema, SQL_NTS));

OK_SIMPLE_STMT(Stmt, "CREATE TABLE t1 (a int)");
OK_SIMPLE_STMT(Stmt, "CREATE TABLE t2 LIKE t1");
Expand Down
12 changes: 7 additions & 5 deletions test/tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ int my_fetch_int(SQLHANDLE Stmt, unsigned int ColumnNumber)


#define is_wstr(a, b, c) \
if (wcsncmp(a,b,c) != 0)\
if (sqlwcharcmp(a,b,c) != 0)\
{\
diag("Comparison failed in %s line %d", __FILE__, __LINE__);\
return FAIL;\
Expand Down Expand Up @@ -783,18 +783,20 @@ SQLWCHAR* latin_as_sqlwchar(char *str, SQLWCHAR *buffer)

#define LW(latin_str) latin_as_sqlwchar(latin_str, sqlwchar_buff)

int sqlwcharcmp(SQLWCHAR *s1, SQLWCHAR *s2)
/* @n[in] - number of characters to compare. Negative means treating of strings as null-terminated */
int sqlwcharcmp(SQLWCHAR *s1, SQLWCHAR *s2, int n)
{
if(s1 == NULL || s2 == NULL)
{
return s1!=s2;
}

while (*s1 && *s2 && *s1==*s2)
while (n != 0 && *s1 && *s2 && *s1==*s2)
{
++s1; ++s2;
++s1; ++s2; --n;
}

return *s1!=*s2;
return n != 0 && *s1!=*s2;
}

#endif /* #ifndef _tap_h_ */

0 comments on commit 011e68a

Please sign in to comment.