mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-24 09:08:43 +02:00
DateTime wrong binding/extraction for MySQL database #1897; add docker mysql runtests
This commit is contained in:
parent
17e9a335af
commit
c7f105d1cd
@ -169,7 +169,7 @@ void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
|
|||||||
mt.hour = val.hour();
|
mt.hour = val.hour();
|
||||||
mt.minute = val.minute();
|
mt.minute = val.minute();
|
||||||
mt.second = val.second();
|
mt.second = val.second();
|
||||||
mt.second_part = val.millisecond();
|
mt.second_part = val.millisecond() * 1000 + val.microsecond();
|
||||||
|
|
||||||
mt.time_type = MYSQL_TIMESTAMP_DATETIME;
|
mt.time_type = MYSQL_TIMESTAMP_DATETIME;
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ bool Extractor::extract(std::size_t pos, DateTime& val)
|
|||||||
if (!realExtractFixed(pos, MYSQL_TYPE_DATETIME, &mt))
|
if (!realExtractFixed(pos, MYSQL_TYPE_DATETIME, &mt))
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
Data/MySQL/testsuite/run-tests.sh
Executable file
23
Data/MySQL/testsuite/run-tests.sh
Executable 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
|
||||||
|
|
@ -44,7 +44,7 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
|
|||||||
// Parameters for barebone-test
|
// Parameters for barebone-test
|
||||||
#define MYSQL_USER "root"
|
#define MYSQL_USER "root"
|
||||||
#define MYSQL_PWD "poco"
|
#define MYSQL_PWD "poco"
|
||||||
#define MYSQL_HOST "localhost"
|
#define MYSQL_HOST "127.0.0.1"
|
||||||
#define MYSQL_PORT 3306
|
#define MYSQL_PORT 3306
|
||||||
#define MYSQL_DB "pocotestdb"
|
#define MYSQL_DB "pocotestdb"
|
||||||
|
|
||||||
@ -56,7 +56,8 @@ std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST
|
|||||||
";db=" MYSQL_DB
|
";db=" MYSQL_DB
|
||||||
";compress=true"
|
";compress=true"
|
||||||
";auto-reconnect=true"
|
";auto-reconnect=true"
|
||||||
";secure-auth=true";
|
";secure-auth=true"
|
||||||
|
";protocol=tcp";
|
||||||
|
|
||||||
|
|
||||||
MySQLTest::MySQLTest(const std::string& name):
|
MySQLTest::MySQLTest(const std::string& name):
|
||||||
@ -85,7 +86,7 @@ void MySQLTest::connectNoDB()
|
|||||||
std::string dbConnString = "host=" MYSQL_HOST
|
std::string dbConnString = "host=" MYSQL_HOST
|
||||||
";user=" MYSQL_USER
|
";user=" MYSQL_USER
|
||||||
";password=" MYSQL_PWD
|
";password=" MYSQL_PWD
|
||||||
";compress=true;auto-reconnect=true";
|
";compress=true;auto-reconnect=true;protocol=tcp";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -716,7 +717,7 @@ void MySQLTest::recreatePersonBLOBTable()
|
|||||||
void MySQLTest::recreatePersonDateTimeTable()
|
void MySQLTest::recreatePersonDateTimeTable()
|
||||||
{
|
{
|
||||||
dropTable("Person");
|
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(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
|
||||||
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
|
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
|
||||||
}
|
}
|
||||||
|
@ -1263,7 +1263,7 @@ void SQLExecutor::dateTime()
|
|||||||
std::string lastName("Bart");
|
std::string lastName("Bart");
|
||||||
std::string firstName("Simpson");
|
std::string firstName("Simpson");
|
||||||
std::string address("Springfield");
|
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;
|
int count = 0;
|
||||||
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
|
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user