Skip to content

Commit

Permalink
error handling when converting timestamp to time/date (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanw-bq authored Mar 25, 2021
1 parent 3c63291 commit de4e710
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/IntegrationTests/ITODBCResults/test_odbc_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2310,23 +2310,33 @@ TEST_F(TestSQLGetData, TIMESTAMP_TO_SQL_C_DATE) {
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
DATE_STRUCT ds1{2021, 1, 2};
CompareDateStruct(ds1, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 2, SQL_C_DATE, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
DATE_STRUCT ds{2021, 11, 20};
CompareDateStruct(ds, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 3, SQL_C_DATE, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
CompareDateStruct(ds, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 4, SQL_C_DATE, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
CompareDateStruct(ds, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 5, SQL_C_DATE, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
CompareDateStruct(ds, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 6, SQL_C_DATE, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(DATE_STRUCT), indicator);
Expand Down Expand Up @@ -2356,10 +2366,14 @@ TEST_F(TestSQLGetData, TIMESTAMP_TO_SQL_C_TIME) {
EXPECT_EQ((SQLLEN)sizeof(TIME_STRUCT), indicator);
TIME_STRUCT ts2{6, 39, 45};
CompareTimeStruct(ts2, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 3, SQL_C_TIME, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(TIME_STRUCT), indicator);
CompareTimeStruct(ts2, data);
EXPECT_TRUE(CheckSQLSTATE(SQL_HANDLE_STMT, m_hstmt,
SQLSTATE_FRACTIONAL_TRUNCATION));
ret = SQLGetData(m_hstmt, 4, SQL_C_TIME, &data, sizeof(data), &indicator);
EXPECT_TRUE(SQL_SUCCEEDED(ret));
EXPECT_EQ((SQLLEN)sizeof(TIME_STRUCT), indicator);
Expand Down
11 changes: 1 addition & 10 deletions src/odfesqlodbc/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,16 +1306,7 @@ int copy_and_convert_field(StatementClass *stmt, OID field_type, int atttypmod,
std_time.ss = 0;
}
if (strnicmp(value, "invalid", 7) != 0) {
BOOL bZone = field_type != TS_TYPE_TIMESTAMP_NO_TMZONE;
int zone;

/*
* sscanf(value, "%4d-%2d-%2d %2d:%2d:%2d", &std_time.y,
* &std_time.m, &std_time.d, &std_time.hh, &std_time.mm,
* &std_time.ss);
*/
bZone = FALSE; /* time zone stuff is unreliable */
timestamp2stime(value, &std_time, &bZone, &zone);
char2stime(value, &std_time, &result, fCType);
MYLOG(LOG_ALL, "2stime fr=%d\n", std_time.fr);
} else {
/*
Expand Down

0 comments on commit de4e710

Please sign in to comment.