Skip to content

Commit

Permalink
#2569: Added TIMESTAMP data type support on MySQL (#3471)
Browse files Browse the repository at this point in the history
* Unit test for TIMESTAMP data type in MySQL.

* Added support for TIMESTAMP data type.

Co-authored-by: Hector Toledo Soto <hsoto@transperfect.com>
  • Loading branch information
hectots and Hector Toledo Soto committed May 29, 2022
1 parent 1fe93ca commit 0f9a876
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Data/MySQL/src/ResultMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
return sizeof(MYSQL_TIME);

case MYSQL_TYPE_DECIMAL:
Expand Down Expand Up @@ -118,6 +119,7 @@ namespace
return Poco::Data::MetaColumn::FDT_TIME;

case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
return Poco::Data::MetaColumn::FDT_TIMESTAMP;

case MYSQL_TYPE_STRING:
Expand Down
11 changes: 11 additions & 0 deletions Data/MySQL/testsuite/src/MySQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ void MySQLTest::testDateTime()
_pExecutor->date();
recreatePersonTimeTable();
_pExecutor->time();
recreatePersonTimestampTable();
_pExecutor->timestamp();
}


Expand Down Expand Up @@ -769,6 +771,15 @@ void MySQLTest::recreatePersonTimeTable()
}


void MySQLTest::recreatePersonTimestampTable()
{
dropTable("Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday TIMESTAMP(6))", now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTimestampTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTimestampTable()"); }
}


void MySQLTest::recreatePersonLongBLOBTable()
{
dropTable("Person");
Expand Down
1 change: 1 addition & 0 deletions Data/MySQL/testsuite/src/MySQLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class MySQLTest: public CppUnit::TestCase
void recreatePersonDateTimeTable();
void recreatePersonDateTable();
void recreatePersonTimeTable();
void recreatePersonTimestampTable();
void recreatePersonLongBLOBTable();
void recreatePersonJSONTable();
void recreateStringsTable();
Expand Down
28 changes: 28 additions & 0 deletions Data/MySQL/testsuite/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,34 @@ void SQLExecutor::time()
}


void SQLExecutor::timestamp()
{
std::string funct = "timestamp()";
std::string lastName("Bart");
std::string firstName("Simpson");
std::string address("Springfield");
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; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
try { *_pSession << "SELECT COUNT(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assertTrue (count == 1);

DateTime bd;
assertTrue (bd != birthday);
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assertTrue (bd == birthday);

std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
}


void SQLExecutor::blob(unsigned int bigSize)
{
std::string funct = "blob()";
Expand Down
1 change: 1 addition & 0 deletions Data/MySQL/testsuite/src/SQLExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SQLExecutor: public CppUnit::TestCase
void dateTime();
void date();
void time();
void timestamp();
void longBlob();
void json();
void unsignedInts();
Expand Down

0 comments on commit 0f9a876

Please sign in to comment.