Fixed binding and extraction of DateTime for MySQL database #1897 (#1898)

This commit is contained in:
Erbengi 2017-09-22 15:15:35 +02:00 committed by Aleksandar Fabijanic
parent 238306a6ed
commit 549867dad3
4 changed files with 9 additions and 9 deletions

View File

@ -169,7 +169,7 @@ void Binder::bind(std::size_t pos, const DateTime& val, Direction dir, const Whe
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;

View File

@ -208,7 +208,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

@ -796,7 +796,7 @@ void MySQLTest::recreatePersonLongTextTable()
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()"); }
}
@ -894,7 +894,7 @@ void MySQLTest::recreateAnyTable()
dropTable("Anys");
try {
*_pSession << "CREATE TABLE Anys (int_8 TINYINT, int_16 SMALLINT, int_32 MEDIUMINT, int_64 BIGINT, flt FLOAT, dbl DOUBLE, "
"str0 VARCHAR(255), str1 TEXT, date0 DATE, time0 TIME, date_time0 DATETIME, empty INTEGER)", now;
"str0 VARCHAR(255), str1 TEXT, date0 DATE, time0 TIME, date_time0 DATETIME(6), empty INTEGER)", now;
}
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateAnyTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateAnyTable()"); }

View File

@ -568,7 +568,7 @@ void SQLExecutor::any()
Any s = std::string("42");
Any date = Date(DateTime());
Any t = Time(DateTime());
Any dateTime = DateTime(2017, 9, 2, 18, 49, 15);
Any dateTime = DateTime(2017, 9, 2, 18, 49, 15, 227, 987);
Any e;
assert (e.empty());
@ -594,7 +594,7 @@ void SQLExecutor::any()
Any s2 = std::string("");
Any dateR = Date();
Any tR = Time();
Any dateTimeR = DateTime(2010, 5, 25);
Any dateTimeR = DateTime();
e = 1;
assert (!e.empty());
@ -655,7 +655,7 @@ void SQLExecutor::dynamicAny()
DynamicAny s2 = std::string("");
DynamicAny dateR = Date();
DynamicAny tR = Time();
DynamicAny dateTimeR = DateTime(2017, 9, 2);
DynamicAny dateTimeR = DateTime();
e = 1;
assert (!e.isEmpty());
@ -674,7 +674,7 @@ void SQLExecutor::dynamicAny()
assert ("42" == s2);
assert (date == dateR);
assert (t == tR);
assert (dateTimeR == dateTime);
assert (dateTimeR.convert<DateTime>() == dateTime.convert<DateTime>());
assert (e.isEmpty());
}
@ -1397,7 +1397,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; }