Skip to content

Commit

Permalink
[ODBC-115] Fix and the testcase. Wrong rc and sqlstate for numeric ov…
Browse files Browse the repository at this point in the history
…erflow(but not for fractional truncation). Now connectors returns 22003 and SQL_ERROR

Also changed int SQLFetch couple of switches to switch on Concise_Type,
and not Type, that was seemingly wrong.
Changed logo in the READMC.md
  • Loading branch information
lawrinn committed Oct 6, 2017
1 parent f673843 commit 6265daf
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# MariaDB Connector/ODBC 2.0
<p align="center">
<a href="http://mariadb.org/">
<img height="129" width="413" src="http://badges.mariadb.org/logo/Mariadb-seal-shaded-browntext.png">
<img src="https://mariadb.com/themes/custom/mariadb/logo.svg">
</a>
</p>


## Status
[![License (LGPL version 2.1)](https://img.shields.io/badge/license-GNU%20LGPL%20version%202.1-green.svg?style=flat-square)](http://opensource.org/licenses/LGPL-2.1)

Expand Down
49 changes: 49 additions & 0 deletions ma_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ SQLRETURN MADB_DaeStmt(MADB_Stmt *Stmt, SQLUSMALLINT Operation)

}


int MADB_FindNextDaeParam(MADB_Desc *Desc, int InitialParam, SQLSMALLINT RowNumber)
{
int i;
Expand All @@ -1243,3 +1244,51 @@ int MADB_FindNextDaeParam(MADB_Desc *Desc, int InitialParam, SQLSMALLINT RowNumb

return MADB_NOPARAM;
}


BOOL MADB_IsNumericType(SQLSMALLINT ConciseType)
{
switch (ConciseType)
{
case SQL_C_TINYINT:
case SQL_C_STINYINT:
case SQL_C_UTINYINT:
case SQL_C_SHORT:
case SQL_C_SSHORT:
case SQL_C_USHORT:
case SQL_C_LONG:
case SQL_C_SLONG:
case SQL_C_ULONG:
case SQL_C_UBIGINT:
case SQL_C_SBIGINT:
case SQL_BIGINT:
case SQL_C_DOUBLE:
case SQL_C_FLOAT:
case SQL_DECIMAL:
return TRUE;
}
return FALSE;
}


BOOL MADB_IsIntType(SQLSMALLINT ConciseType)
{
switch (ConciseType)
{
case SQL_C_TINYINT:
case SQL_C_STINYINT:
case SQL_C_UTINYINT:
case SQL_C_SHORT:
case SQL_C_SSHORT:
case SQL_C_USHORT:
case SQL_C_LONG:
case SQL_C_SLONG:
case SQL_C_ULONG:
case SQL_C_UBIGINT:
case SQL_C_SBIGINT:
case SQL_BIGINT:
return TRUE;
}
return FALSE;
}

3 changes: 3 additions & 0 deletions ma_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void MADB_NumericInit (SQL_NUMERIC_STRUCT *number, MADB_DescRecord
unsigned long MADB_StmtDataTell (MADB_Stmt *Stmt);
int MADB_FindNextDaeParam (MADB_Desc *Desc, int InitialParam, SQLSMALLINT RowNumber);

BOOL MADB_IsNumericType(SQLSMALLINT ConciseType);
BOOL MADB_IsIntType (SQLSMALLINT ConciseType);

/* for dummy binding */
extern my_bool DummyError;

Expand Down
13 changes: 9 additions & 4 deletions ma_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ SQLRETURN MADB_PrepareBind(MADB_Stmt *Stmt, int RowNumber)
/* We can't use application's buffer directly, as it has/can have different size, than C/C needs */
Stmt->result[i].length= &Stmt->result[i].length_value;

switch(ArdRec->Type) {
switch(ArdRec->ConciseType) {
case SQL_C_WCHAR:
/* In worst case for 2 bytes of UTF16 in result, we need 3 bytes of utf8.
For ASCII we need 2 times less(for 2 bytes of UTF16 - 1 byte UTF8,
Expand Down Expand Up @@ -1636,7 +1636,7 @@ SQLRETURN MADB_FixFetchedValues(MADB_Stmt *Stmt, int RowNumber, MYSQL_ROW_OFFSET
}
else
{
switch (ArdRec->Type)
switch (ArdRec->ConciseType)
{
case SQL_C_BIT:
{
Expand Down Expand Up @@ -1840,7 +1840,6 @@ SQLRETURN MADB_StmtFetch(MADB_Stmt *Stmt)
{
unsigned int row_num, j, rc;
SQLULEN Rows2Fetch= Stmt->Ard->Header.ArraySize, Processed, *ProcessedPtr= &Processed;
MADB_Desc *ArdDesc= Stmt->Ard;
MYSQL_ROW_OFFSET SaveCursor= NULL;
SQLRETURN Result= SQL_SUCCESS, RowResult;

Expand Down Expand Up @@ -1968,7 +1967,13 @@ SQLRETURN MADB_StmtFetch(MADB_Stmt *Stmt)
if (Stmt->stmt->bind[col].error && *Stmt->stmt->bind[col].error > 0 &&
!(Stmt->stmt->bind[col].flags & MADB_BIND_DUMMY))
{
RowResult= MADB_SetError(&Stmt->Error, MADB_ERR_01004, NULL, 0);
MADB_DescRecord *ArdRec= MADB_DescGetInternalRecord(Stmt->Ard, col, MADB_DESC_READ),
*IrdRec= MADB_DescGetInternalRecord(Stmt->Ird, col, MADB_DESC_READ);
/* For numeric types we return either 22003 or 01S07, 01004 for the rest.
if ird type is not fractional - we return 22003. But as a matter of fact, it's possible that we have 22003 if converting
from fractional types */
RowResult= MADB_SetError(&Stmt->Error, ArdRec != NULL && MADB_IsNumericType(ArdRec->ConciseType) ?
(MADB_IsIntType(IrdRec->ConciseType) ? MADB_ERR_22003 : MADB_ERR_01S07) : MADB_ERR_01004, NULL, 0);
/* One found such column is enough */
break;
}
Expand Down
42 changes: 41 additions & 1 deletion test/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ ODBC_TEST(t_bug13542600)
OK_SIMPLE_STMT(Stmt, "select 1 as i , null as j ");
CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 2, SQL_C_LONG, &i, 0, NULL));

FAIL_IF(SQLFetch(Stmt)!= SQL_ERROR, "error expected");
EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_ERROR);
CHECK_SQLSTATE(Stmt, "22002");

return OK;
Expand Down Expand Up @@ -635,6 +635,45 @@ ODBC_TEST(t_odbc94)
}


ODBC_TEST(t_odbc115)
{
SQLINTEGER Big;
SQLCHAR Str[8];

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));
OK_SIMPLE_STMT(Stmt, "select 9223372036854809");
CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 1, SQL_C_LONG, &Big, 0, NULL));

EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_ERROR);

CHECK_SQLSTATE(Stmt, "22003");

/* Now testing 01004 for strings */
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "select '123456789'");
CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 1, SQL_C_CHAR, &Str, sizeof(Str), NULL));

EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_SUCCESS_WITH_INFO);

CHECK_SQLSTATE(Stmt, "01004");

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

/* Now testing 01S07 for fractional truncation */
OK_SIMPLE_STMT(Stmt, "select 1.02");
CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 1, SQL_C_LONG, &Big, 0, NULL));

EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_SUCCESS_WITH_INFO);

CHECK_SQLSTATE(Stmt, "01S07");

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

return OK;
}


MA_ODBC_TESTS my_tests[]=
{
{t_odbc3_error, "t_odbc3_error"},
Expand All @@ -654,6 +693,7 @@ MA_ODBC_TESTS my_tests[]=
{t_bug14285620, "t_bug14285620"},
{t_bug49466, "t_bug49466"},
{t_odbc94, "t_odbc94"},
{t_odbc115, "t_odbc115"},
{NULL, NULL}
};

Expand Down

0 comments on commit 6265daf

Please sign in to comment.