Skip to content

Commit d506530

Browse files
committed
Fix and testcase of the bug, that was found during investigation on
ODBC-109. It's not clear atm if the bug causes the reported error in the connector's work, since I can't reproduce the bug. But looks probable. For the info type SQL_SCHEMA_TERM/SQL_OWNER_TERM the connector returned wrong length. Or more exactly - did not write anything into application's length buffer
1 parent d4d8c72 commit d506530

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

ma_connection.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,9 +1605,13 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
16051605
return Dbc->Error.ReturnValue;
16061606
}
16071607
if (isWChar && SLen)
1608+
{
16081609
SLen*= sizeof(SQLWCHAR);
1609-
if (StringLengthPtr && SLen)
1610+
}
1611+
if (IsString_GetInfo_Type(InfoType) && StringLengthPtr)
1612+
{
16101613
*StringLengthPtr= SLen;
1614+
}
16111615

16121616
return SQL_SUCCESS;
16131617
}

test/info.c

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ ODBC_TEST(test_need_long_data_len)
488488

489489
/* https://jira.mariadb.org/browse/ODBC-61
490490
Request of SQL_FILE_USAGE info crashes connector */
491-
ODBC_TEST(t_odbc61)
491+
ODBC_TEST(odbc61)
492492
{
493493
SQLUSMALLINT info= 0xef;
494494

@@ -502,7 +502,7 @@ ODBC_TEST(t_odbc61)
502502
Bug ODBC-84 and ODBC-62. For ODBC-84 we only tested, that SQLGetTypeInfo returns something for WCHAR types
503503
For ODBC-62 we need to check CREATE_PARAMS
504504
*/
505-
ODBC_TEST(t_odbc84_62)
505+
ODBC_TEST(odbc84_62)
506506
{
507507
SQLHANDLE henv1;
508508
SQLHANDLE Connection1;
@@ -637,7 +637,7 @@ ODBC_TEST(t_odbc84_62)
637637
}
638638

639639
/* Test for part of problems causing ODBC-71. Other part is tested in desc.c:t_set_explicit_copy*/
640-
ODBC_TEST(t_odbc71)
640+
ODBC_TEST(odbc71)
641641
{
642642
SQLINTEGER Info;
643643

@@ -662,7 +662,7 @@ ODBC_TEST(t_odbc71)
662662
/* ODBC-123 Test for SQL_CATALOG_LOCATION info type. The connector incorrectly wrote to the buffer SQLUINTEGER,
663663
while it has to be SQLUSMALLINT,
664664
Also testing SQL_GROUP_BY, which has the same problem */
665-
ODBC_TEST(t_odbc123)
665+
ODBC_TEST(odbc123)
666666
{
667667
SQLUSMALLINT Info;
668668

@@ -676,6 +676,43 @@ ODBC_TEST(t_odbc123)
676676
}
677677

678678

679+
/* ODBC-109 It's not clear atm if that is the reason behind the report, but it was found during work on this bug.
680+
For the info type SQL_SCHEMA_TERM/SQL_OWNER_TERM the connector returned wrong length. Or more exactly - did not
681+
write anything into application's length buffer */
682+
ODBC_TEST(odbc109)
683+
{
684+
SQLCHAR tn;
685+
SQLSMALLINT StrLen;
686+
SQLHANDLE henv1;
687+
SQLHANDLE Connection1;
688+
SQLCHAR conn[512];
689+
690+
/* SQL_OWNER_TERM is the same as SQL_SCHEMA_TERM */
691+
CHECK_DBC_RC(Connection, SQLGetInfo(Connection, SQL_OWNER_TERM, NULL, 0, &StrLen));
692+
is_num(StrLen, 0);
693+
CHECK_DBC_RC(Connection, SQLGetInfo(Connection, SQL_OWNER_TERM, &tn, 1, NULL));
694+
is_num(tn, 0);
695+
696+
/* odbc 2 */
697+
sprintf((char *)conn, "DRIVER=%s;SERVER=%s;UID=%s;PASSWORD=%s;PORT=%d",
698+
my_drivername, my_servername, my_uid, my_pwd, my_port);
699+
700+
CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv1));
701+
CHECK_ENV_RC(henv1, SQLSetEnvAttr(henv1, SQL_ATTR_ODBC_VERSION,
702+
(SQLPOINTER)SQL_OV_ODBC2, SQL_IS_INTEGER));
703+
CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_DBC, henv1, &Connection1));
704+
CHECK_DBC_RC(Connection1, SQLDriverConnect(Connection1, NULL, conn, (SQLSMALLINT)strlen(conn), NULL, 0,
705+
NULL, SQL_DRIVER_NOPROMPT));
706+
707+
CHECK_DBC_RC(Connection1, SQLGetInfo(Connection1, SQL_OWNER_TERM, NULL, 0, &StrLen));
708+
is_num(StrLen, 0);
709+
CHECK_DBC_RC(Connection1, SQLGetInfo(Connection1, SQL_OWNER_TERM, &tn, 1, NULL));
710+
is_num(tn, 0);
711+
712+
return OK;
713+
}
714+
715+
679716
MA_ODBC_TESTS my_tests[]=
680717
{
681718
{ t_gettypeinfo, "t_gettypeinfo", NORMAL },
@@ -692,10 +729,11 @@ MA_ODBC_TESTS my_tests[]=
692729
{ t_bug11749093, "t_bug11749093", NORMAL },
693730
{ bug_odbc15, "odbc15", NORMAL },
694731
{ test_need_long_data_len, "test_need_long_data_len", NORMAL },
695-
{ t_odbc61, "odbc61_SQL_FILE_USAGE", NORMAL },
696-
{ t_odbc84_62, "odbc84_WCHAR_types_odbc62_CREATE_PARAMS", NORMAL },
697-
{ t_odbc71, "odbc71_some_odbc2_types", NORMAL },
698-
{ t_odbc123, "odbc123_catalog_start", NORMAL },
732+
{ odbc61, "odbc61_SQL_FILE_USAGE", NORMAL },
733+
{ odbc84_62, "odbc84_WCHAR_types_odbc62_CREATE_PARAMS", NORMAL },
734+
{ odbc71, "odbc71_some_odbc2_types", NORMAL },
735+
{ odbc123, "odbc123_catalog_start", NORMAL },
736+
{ odbc109, "odbc109_shema_owner_term", NORMAL },
699737
{ NULL, NULL }
700738
};
701739

0 commit comments

Comments
 (0)