fix mysql odbc tests

This commit is contained in:
Alex Fabijanic 2017-10-23 21:51:42 -05:00
parent 7295fe788e
commit a651a78c76
6 changed files with 54 additions and 19 deletions

View File

@ -38,7 +38,7 @@ using Poco::Tuple;
using Poco::NotFoundException;
#define MYSQL_ODBC_DRIVER "MySQL ODBC 5.2 Driver"
#define MYSQL_ODBC_DRIVER "MySQL ODBC 5.3 Unicode Driver"
#define MYSQL_DSN "PocoDataMySQLTest"
#define MYSQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
#define MYSQL_DB "test"
@ -52,6 +52,7 @@ std::string ODBCMySQLTest::_driver = MYSQL_ODBC_DRIVER;
std::string ODBCMySQLTest::_dsn = MYSQL_DSN;
std::string ODBCMySQLTest::_uid = MYSQL_UID;
std::string ODBCMySQLTest::_pwd = MYSQL_PWD;
std::string ODBCMySQLTest::_db = MYSQL_DB;
std::string ODBCMySQLTest::_connectString = "DRIVER={" MYSQL_ODBC_DRIVER "};"
"DATABASE=" MYSQL_DB ";"
"SERVER=" MYSQL_SERVER ";"
@ -162,7 +163,7 @@ void ODBCMySQLTest::testNull()
recreateNullsTable("NOT NULL");
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->notNulls("HYT00");
_pExecutor->notNulls("HY000");
i += 2;
}
@ -320,13 +321,22 @@ void ODBCMySQLTest::recreateStringsTable()
void ODBCMySQLTest::recreateFloatsTable()
{
dropObject("TABLE", ExecUtil::strings());
try { *_pSession << "CREATE TABLE " << ExecUtil::person() << " (str FLOAT)", now; }
dropObject("TABLE", ExecUtil::floats());
try { *_pSession << "CREATE TABLE " << ExecUtil::floats() << " (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCMySQLTest::recreateDoublesTable()
{
dropObject("TABLE", ExecUtil::doubles());
try { *_pSession << "CREATE TABLE " << ExecUtil::doubles() << " (str DOUBLE)", now; }
catch (ConnectionException& ce) { std::cout << ce.toString() << std::endl; fail("recreateFloatsTable()"); }
catch (StatementException& se) { std::cout << se.toString() << std::endl; fail("recreateFloatsTable()"); }
}
void ODBCMySQLTest::recreateTuplesTable()
{
dropObject("TABLE", ExecUtil::tuples());
@ -410,7 +420,7 @@ void ODBCMySQLTest::recreateLogTable()
CppUnit::Test* ODBCMySQLTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString, _db)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;

View File

@ -58,19 +58,21 @@ private:
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateDoublesTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateMiscTable();
void recreateLogTable();
void testInternalBulkExtraction() { std::cout << " disabled" << std::endl; }
static ODBCTest::SessionPtr _pSession;
static ODBCTest::ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _db;
static std::string _connectString;
};

View File

@ -910,7 +910,7 @@ void ODBCTest::testDouble()
for (int i = 0; i < 8;)
{
recreateFloatsTable();
recreateDoublesTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->doubles();

View File

@ -169,6 +169,7 @@ protected:
virtual void recreateStringsTable();
virtual void recreateIntsTable();
virtual void recreateFloatsTable();
virtual void recreateDoublesTable();
virtual void recreateTuplesTable();
virtual void recreateVectorsTable();
virtual void recreateAnysTable();
@ -328,6 +329,12 @@ inline void ODBCTest::recreateFloatsTable()
}
inline void ODBCTest::recreateDoublesTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateFloatsTable()");
}
inline void ODBCTest::recreateTuplesTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateTuplesTable()");

View File

@ -113,7 +113,7 @@ std::string idGen()
{
Poco::Checksum crc;
crc.update(host);
host = Poco::format("%s%X", host.substr(0, 4), crc.checksum());
host = Poco::format("%s%LX", host.substr(0, 4), crc.checksum());
}
std::replace(host.begin(), host.end(), '.', '_');
std::replace(host.begin(), host.end(), '-', '_');
@ -447,7 +447,7 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
sixth.day = 18;
sixth.hour = 5;
sixth.minute = 34;
sixth.second = 59;
sixth.second = 58;
// Fraction support is limited to milliseconds due to MS SQL Server limitation
// see http://support.microsoft.com/kb/263872
sixth.fraction = 997000000;
@ -738,9 +738,15 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
{
assert (5 == sixth.hour);
assert (34 == sixth.minute);
assert (59 == sixth.second);
if (sixth.fraction)//MySQL does not support fraction
assert (997000000 == sixth.fraction);
if (sixth.fraction) // MySQL rounds fraction
{
assert(58 == sixth.second);
assert(997000000 == sixth.fraction);
}
else
{
assert(59 == sixth.second);
}
}
rc = SQLCloseCursor(hstmt);
@ -1540,17 +1546,17 @@ void SQLExecutor::floats()
float data = 1.5f;
float ret = 0.0f;
try { session() << "INSERT INTO " << ExecUtil::strings() << " VALUES (?)", use(data), now; }
try { session() << "INSERT INTO " << ExecUtil::floats() << " VALUES (?)", use(data), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
try { session() << "SELECT COUNT(*) FROM " << ExecUtil::strings(), into(count), now; }
try { session() << "SELECT COUNT(*) FROM " << ExecUtil::floats(), into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (count == 1);
try { session() << "SELECT str FROM " << ExecUtil::strings(), into(ret), now; }
try { session() << "SELECT str FROM " << ExecUtil::floats(), into(ret), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (ret == data);
@ -1559,21 +1565,21 @@ void SQLExecutor::floats()
void SQLExecutor::doubles()
{
std::string funct = "floats()";
std::string funct = "doubles()";
double data = 1.5;
double ret = 0.0;
try { session() << "INSERT INTO " << ExecUtil::strings() << " VALUES (?)", use(data), now; }
try { session() << "INSERT INTO " << ExecUtil::doubles() << " VALUES (?)", use(data), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
try { session() << "SELECT COUNT(*) FROM " << ExecUtil::strings(), into(count), now; }
try { session() << "SELECT COUNT(*) FROM " << ExecUtil::doubles(), into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (count == 1);
try { session() << "SELECT str FROM " << ExecUtil::strings(), into(ret), now; }
try { session() << "SELECT str FROM " << ExecUtil::doubles(), into(ret), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (ret == data);

View File

@ -82,6 +82,16 @@ struct ExecUtil
return mangleTable("Person");
}
static std::string floats()
{
return mangleTable("Floats");
}
static std::string doubles()
{
return mangleTable("Doubles");
}
static std::string strings()
{
return mangleTable("Strings");