Skip to content

Commit 74d6447

Browse files
committed
ODBC-480 SQLDeAscribeCol did not return column len if buffer parameter
nd buffer len were 0. The fix + the test.
1 parent da0a1e4 commit 74d6447

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

ma_statement.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,13 +3800,18 @@ SQLRETURN MADB_StmtDescribeCol(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, void
38003800
if (NullablePtr)
38013801
*NullablePtr= Record->Nullable;
38023802

3803-
if ((ColumnName || BufferLength) && Record->ColumnName)
3803+
if ((ColumnName || NameLengthPtr) && Record->ColumnName)
38043804
{
3805-
size_t Length= MADB_SetString(isWChar ? &Stmt->Connection->Charset : 0, ColumnName, ColumnName ? BufferLength : 0, Record->ColumnName, SQL_NTS, &Stmt->Error);
3805+
size_t Length= MADB_SetString(isWChar ? &Stmt->Connection->Charset : 0, ColumnName,
3806+
ColumnName ? BufferLength : 0, Record->ColumnName, SQL_NTS, &Stmt->Error);
38063807
if (NameLengthPtr)
3808+
{
38073809
*NameLengthPtr= (SQLSMALLINT)Length;
3808-
if (!BufferLength)
3810+
}
3811+
if (ColumnName && !BufferLength)
3812+
{
38093813
MADB_SetError(&Stmt->Error, MADB_ERR_01004, NULL, 0);
3814+
}
38103815
}
38113816
return Stmt->Error.ReturnValue;
38123817
}

test/desc.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ ODBC_TEST(t_odbc216)
815815
return OK;
816816
}
817817

818-
/* */
818+
/* ODBC-211 SQLDescribeCol return precision=0 for field type decimal(1,0) */
819819
ODBC_TEST(t_odbc211)
820820
{
821821
SQLLEN Size= 0;
@@ -938,6 +938,26 @@ ODBC_TEST(t_odbc211)
938938
}
939939

940940

941+
/*
942+
ODBC-480 - SQLDescribeCol does not return column name length if if column name buf ptr
943+
and buffer lenght are not 0
944+
*/
945+
ODBC_TEST(t_odbc480)
946+
{
947+
SQLSMALLINT colNameLen;
948+
949+
CHECK_STMT_RC(Stmt, SQLExecDirect(Stmt,
950+
"SELECT 1 AS someColumnName1"
951+
, SQL_NTS));
952+
953+
CHECK_STMT_RC(Stmt, SQLDescribeCol(Stmt, 1, NULL, 0, &colNameLen,
954+
NULL, NULL, NULL, NULL));
955+
956+
is_num(colNameLen, sizeof("someColumnName1") - 1);
957+
958+
return OK;
959+
}
960+
941961
MA_ODBC_TESTS my_tests[]=
942962
{
943963
{t_desc_paramset,"t_desc_paramset"},
@@ -959,6 +979,7 @@ MA_ODBC_TESTS my_tests[]=
959979
{t_odbc213, "t_odbc213_param_type"},
960980
{t_odbc216, "t_odbc216_fixed_prec_scale"},
961981
{t_odbc211, "t_odbc211_zero_scale"},
982+
{t_odbc480, "t_odbc480_col_name_len"},
962983
{NULL, NULL}
963984
};
964985

0 commit comments

Comments
 (0)