Skip to content

Commit e837015

Browse files
committed
separate tests for Date/Time
1 parent 8832c2e commit e837015

6 files changed

Lines changed: 118 additions & 28 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ XML/testsuite/rss.xml
5959
Icon?
6060
ehthumbs.db
6161
Thumbs.db
62+
*~
6263

6364
# VS generated files #
6465
######################

Data/MySQL/src/ResultMetadata.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ namespace
130130
case MYSQL_TYPE_LONGLONG:
131131
if (unsig) return Poco::Data::MetaColumn::FDT_UINT64;
132132
return Poco::Data::MetaColumn::FDT_INT64;
133+
133134
case MYSQL_TYPE_DATE:
135+
return Poco::Data::MetaColumn::FDT_DATE;
136+
134137
case MYSQL_TYPE_TIME:
138+
return Poco::Data::MetaColumn::FDT_TIME;
139+
135140
case MYSQL_TYPE_DATETIME:
136141
return Poco::Data::MetaColumn::FDT_TIMESTAMP;
137142

Data/MySQL/testsuite/src/MySQLTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ void MySQLTest::testDateTime()
423423

424424
recreatePersonDateTimeTable();
425425
_pExecutor->dateTime();
426+
recreatePersonDateTable();
427+
_pExecutor->date();
428+
recreatePersonTimeTable();
429+
_pExecutor->time();
426430
}
427431

428432

@@ -715,6 +719,24 @@ void MySQLTest::recreatePersonDateTimeTable()
715719
}
716720

717721

722+
void MySQLTest::recreatePersonDateTable()
723+
{
724+
dropTable("Person");
725+
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATE)", now; }
726+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
727+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
728+
}
729+
730+
731+
void MySQLTest::recreatePersonTimeTable()
732+
{
733+
dropTable("Person");
734+
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday TIME)", now; }
735+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
736+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
737+
}
738+
739+
718740
void MySQLTest::recreateIntsTable()
719741
{
720742
dropTable("Strings");

Data/MySQL/testsuite/src/MySQLTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class MySQLTest: public CppUnit::TestCase
130130
void recreatePersonTable();
131131
void recreatePersonBLOBTable();
132132
void recreatePersonDateTimeTable();
133+
void recreatePersonDateTable();
134+
void recreatePersonTimeTable();
133135
void recreateStringsTable();
134136
void recreateIntsTable();
135137
void recreateFloatsTable();

Data/MySQL/testsuite/src/SQLExecutor.cpp

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "Poco/Any.h"
4040
#include "Poco/Exception.h"
4141
#include "Poco/Data/LOB.h"
42+
#include "Poco/Data/Date.h"
43+
#include "Poco/Data/Time.h"
4244
#include "Poco/Data/StatementImpl.h"
4345
#include "Poco/Data/RecordSet.h"
4446
#include "Poco/Data/Transaction.h"
@@ -1253,58 +1255,69 @@ void SQLExecutor::emptyDB()
12531255
}
12541256

12551257

1256-
void SQLExecutor::blob(int bigSize)
1258+
void SQLExecutor::dateTime()
12571259
{
1258-
std::string funct = "blob()";
1259-
std::string lastName("lastname");
1260-
std::string firstName("firstname");
1261-
std::string address("Address");
1262-
1263-
Poco::Data::CLOB img("0123456789", 10);
1260+
std::string funct = "dateTime()";
1261+
std::string lastName("Bart");
1262+
std::string firstName("Simpson");
1263+
std::string address("Springfield");
1264+
DateTime birthday(1980, 4, 1, 5, 45, 12);
1265+
12641266
int count = 0;
1265-
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(img), now; }
1267+
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
12661268
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12671269
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
12681270
try { *_pSession << "SELECT COUNT(*) FROM Person", into(count), now; }
12691271
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12701272
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
12711273
assert (count == 1);
1272-
1273-
Poco::Data::CLOB res;
1274-
assert (res.size() == 0);
1275-
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
1274+
1275+
DateTime bd;
1276+
assert (bd != birthday);
1277+
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
12761278
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12771279
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1278-
assert (res == img);
1279-
1280-
Poco::Data::CLOB big;
1281-
std::vector<char> v(bigSize, 'x');
1282-
big.assignRaw(&v[0], (std::size_t) v.size());
1280+
assert (bd == birthday);
1281+
1282+
std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
1283+
}
12831284

1284-
assert (big.size() == (std::size_t) bigSize);
12851285

1286-
try { *_pSession << "DELETE FROM Person", now; }
1286+
void SQLExecutor::date()
1287+
{
1288+
std::string funct = "date()";
1289+
std::string lastName("Bart");
1290+
std::string firstName("Simpson");
1291+
std::string address("Springfield");
1292+
Date birthday(1980, 4, 1);
1293+
1294+
int count = 0;
1295+
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
12871296
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12881297
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1289-
1290-
try { *_pSession << "INSERT INTO Person VALUES(?,?,?,?)", use(lastName), use(firstName), use(address), use(big), now; }
1298+
try { *_pSession << "SELECT COUNT(*) FROM Person", into(count), now; }
12911299
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12921300
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1293-
1294-
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
1301+
assert (count == 1);
1302+
1303+
Date bd;
1304+
assert (bd != birthday);
1305+
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
12951306
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
12961307
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1297-
assert (res == big);
1308+
assert (bd == birthday);
1309+
1310+
std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
12981311
}
12991312

13001313

1301-
void SQLExecutor::dateTime()
1314+
void SQLExecutor::time()
13021315
{
1303-
std::string funct = "dateTime()";
1316+
std::string funct = "date()";
13041317
std::string lastName("Bart");
13051318
std::string firstName("Simpson");
13061319
std::string address("Springfield");
1307-
DateTime birthday(1980, 4, 1, 5, 45, 12);
1320+
Time birthday(1, 2, 3);
13081321

13091322
int count = 0;
13101323
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
@@ -1315,7 +1328,7 @@ void SQLExecutor::dateTime()
13151328
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
13161329
assert (count == 1);
13171330

1318-
DateTime bd;
1331+
Time bd;
13191332
assert (bd != birthday);
13201333
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
13211334
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
@@ -1326,6 +1339,51 @@ void SQLExecutor::dateTime()
13261339
}
13271340

13281341

1342+
void SQLExecutor::blob(int bigSize)
1343+
{
1344+
std::string funct = "blob()";
1345+
std::string lastName("lastname");
1346+
std::string firstName("firstname");
1347+
std::string address("Address");
1348+
1349+
Poco::Data::CLOB img("0123456789", 10);
1350+
int count = 0;
1351+
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(img), now; }
1352+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1353+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1354+
try { *_pSession << "SELECT COUNT(*) FROM Person", into(count), now; }
1355+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1356+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1357+
assert (count == 1);
1358+
1359+
Poco::Data::CLOB res;
1360+
assert (res.size() == 0);
1361+
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
1362+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1363+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1364+
assert (res == img);
1365+
1366+
Poco::Data::CLOB big;
1367+
std::vector<char> v(bigSize, 'x');
1368+
big.assignRaw(&v[0], (std::size_t) v.size());
1369+
1370+
assert (big.size() == (std::size_t) bigSize);
1371+
1372+
try { *_pSession << "DELETE FROM Person", now; }
1373+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1374+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1375+
1376+
try { *_pSession << "INSERT INTO Person VALUES(?,?,?,?)", use(lastName), use(firstName), use(address), use(big), now; }
1377+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1378+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1379+
1380+
try { *_pSession << "SELECT Image FROM Person", into(res), now; }
1381+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
1382+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
1383+
assert (res == big);
1384+
}
1385+
1386+
13291387
void SQLExecutor::blobStmt()
13301388
{
13311389
std::string funct = "blobStmt()";

Data/MySQL/testsuite/src/SQLExecutor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class SQLExecutor: public CppUnit::TestCase
103103
void blob(int bigSize = 1024);
104104
void blobStmt();
105105
void dateTime();
106+
void date();
107+
void time();
106108
void floats();
107109
void doubles();
108110
void tuples();

0 commit comments

Comments
 (0)