DateTime wrong binding/extraction for MySQL database #1897; add docker mysql runtests

This commit is contained in:
Alex Fabijanic 2017-10-07 12:43:04 -05:00
parent 17e9a335af
commit c7f105d1cd
5 changed files with 34 additions and 10 deletions

View File

@ -169,7 +169,7 @@ void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
mt.hour = val.hour();
mt.minute = val.minute();
mt.second = val.second();
mt.second_part = val.millisecond();
mt.second_part = val.millisecond() * 1000 + val.microsecond();
mt.time_type = MYSQL_TIMESTAMP_DATETIME;
@ -191,7 +191,7 @@ void Binder::bind(std::size_t pos, const Date& val, Direction dir)
mt.time_type = MYSQL_TIMESTAMP_DATE;
_dates.push_back(new MYSQL_TIME(mt));
realBind(pos, MYSQL_TYPE_DATE, _dates.back(), sizeof(MYSQL_TIME));
}
@ -206,9 +206,9 @@ void Binder::bind(std::size_t pos, const Time& val, Direction dir)
mt.second = val.second();
mt.time_type = MYSQL_TIMESTAMP_TIME;
_dates.push_back(new MYSQL_TIME(mt));
realBind(pos, MYSQL_TYPE_TIME, _dates.back(), sizeof(MYSQL_TIME));
}

View File

@ -175,7 +175,7 @@ bool Extractor::extract(std::size_t pos, DateTime& val)
if (!realExtractFixed(pos, MYSQL_TYPE_DATETIME, &mt))
return false;
val.assign(mt.year, mt.month, mt.day, mt.hour, mt.minute, mt.second, mt.second_part, 0);
val.assign(mt.year, mt.month, mt.day, mt.hour, mt.minute, mt.second, mt.second_part / 1000, mt.second_part % 1000);
return true;
}

View File

@ -0,0 +1,23 @@
#!/bin/bash
# in order for this script to work, docker must be installed
MYSQL_DOCKER_VER=latest
# trying to conect prematurely will fail, 10s should be enough wait time
MYSQL_DB_START_WAIT=10
echo "running poco-test-mysql docker container"
docker run -p 3306:3306 --name poco-test-mysql -e MYSQL_ROOT_PASSWORD=poco -e MYSQL_DATABASE=pocotestdb -d mysql:$MYSQL_DOCKER_VER > /dev/null
echo "poco-test-mysql container up and running, sleeping $MYSQL_DB_START_WAIT seconds waiting for db to start ..."
sleep $MYSQL_DB_START_WAIT
echo "running tests ..."
./bin/Linux/x86_64/testrunner -all
echo "stopping poco-test-mysql docker container"
docker stop poco-test-mysql > /dev/null
echo "removing poco-test-mysql docker container"
docker rm poco-test-mysql > /dev/null

View File

@ -44,7 +44,7 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
// Parameters for barebone-test
#define MYSQL_USER "root"
#define MYSQL_PWD "poco"
#define MYSQL_HOST "localhost"
#define MYSQL_HOST "127.0.0.1"
#define MYSQL_PORT 3306
#define MYSQL_DB "pocotestdb"
@ -56,7 +56,8 @@ std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST
";db=" MYSQL_DB
";compress=true"
";auto-reconnect=true"
";secure-auth=true";
";secure-auth=true"
";protocol=tcp";
MySQLTest::MySQLTest(const std::string& name):
@ -85,7 +86,7 @@ void MySQLTest::connectNoDB()
std::string dbConnString = "host=" MYSQL_HOST
";user=" MYSQL_USER
";password=" MYSQL_PWD
";compress=true;auto-reconnect=true";
";compress=true;auto-reconnect=true;protocol=tcp";
try
{
@ -716,7 +717,7 @@ void MySQLTest::recreatePersonBLOBTable()
void MySQLTest::recreatePersonDateTimeTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATETIME)", now; }
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATETIME(6))", now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}

View File

@ -1263,7 +1263,7 @@ void SQLExecutor::dateTime()
std::string lastName("Bart");
std::string firstName("Simpson");
std::string address("Springfield");
DateTime birthday(1980, 4, 1, 5, 45, 12);
DateTime birthday(1980, 4, 1, 5, 45, 12, 354, 879);
int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }