From 21f93e3e6a009756a47b80d38925c5b3cd5b3793 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Wed, 20 Nov 2024 09:22:53 -0600 Subject: [PATCH] enh(ODBC): ODBC: DataFormatException getting Time value from SQL Server #3801 (#4777) --- Data/ODBC/src/ODBCMetaColumn.cpp | 4 +++- Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp | 14 ++++++++++++++ Data/ODBC/testsuite/src/ODBCSQLServerTest.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Data/ODBC/src/ODBCMetaColumn.cpp b/Data/ODBC/src/ODBCMetaColumn.cpp index e870762cf..213bc9dfe 100644 --- a/Data/ODBC/src/ODBCMetaColumn.cpp +++ b/Data/ODBC/src/ODBCMetaColumn.cpp @@ -160,7 +160,9 @@ void ODBCMetaColumn::init() setType(MetaColumn::FDT_DATE); break; case SQL_TYPE_TIME: - case -154: //MS SQL Server custom type SQL_SS_TIME2 +#ifdef POCO_DATA_ODBC_HAVE_SQL_SERVER_EXT + case SQL_SS_TIME2: // MS SQL Server custom type +#endif setType(MetaColumn::FDT_TIME); break; case SQL_TYPE_TIMESTAMP: diff --git a/Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp b/Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp index de3d015b4..5f5bbbcb1 100644 --- a/Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp +++ b/Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp @@ -836,6 +836,19 @@ void ODBCSQLServerTest::testStoredFunction() } +void ODBCSQLServerTest::testSQLServerTime() +{ + Poco::Data::Time t; + dropObject("TABLE", "TimeTestTable"); + session() << "CREATE TABLE TimeTestTable (t time)", now; + session() << "INSERT INTO TimeTestTable (t) VALUES ('12:34:56')", now; + session() << "SELECT t FROM TimeTestTable", into(t), now; + std::ostringstream os; + os << t.hour() << ':' << t.minute() << ':' << t.second(); + assertEqual(os.str(), "12:34:56"s); +} + + void ODBCSQLServerTest::dropObject(const std::string& type, const std::string& name) { try @@ -1168,6 +1181,7 @@ CppUnit::Test* ODBCSQLServerTest::suite() CppUnit_addTest(pSuite, ODBCSQLServerTest, testUnicode); CppUnit_addTest(pSuite, ODBCSQLServerTest, testEncoding); CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect); + CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLServerTime); return pSuite; } diff --git a/Data/ODBC/testsuite/src/ODBCSQLServerTest.h b/Data/ODBC/testsuite/src/ODBCSQLServerTest.h index f5e21bcd5..724a8c652 100644 --- a/Data/ODBC/testsuite/src/ODBCSQLServerTest.h +++ b/Data/ODBC/testsuite/src/ODBCSQLServerTest.h @@ -62,6 +62,8 @@ public: void testStoredProcedureReturn(); void testStoredFunction() override; + void testSQLServerTime(); + static CppUnit::Test* suite(); private: