Permalink
Browse files

Merge remote branch 'upstream/develop' into develop

  • Loading branch information...
2 parents aa260a8 + e837015 commit eab40cfd36916334153f4df6b71d4a18e01e9c22 @pprindeville committed Dec 15, 2012
View
@@ -59,6 +59,7 @@ XML/testsuite/rss.xml
Icon?
ehthumbs.db
Thumbs.db
+*~
# VS generated files #
######################
View
@@ -27,6 +27,8 @@ Release 1.5.0 (2012-12-17)
- fixed GH #26: Cannot compile on gcc
- merged SF #111: FTP Client logging (Marian Krivos)
- fixed GH #30: Poco::Path::home() throws when called from Windows Service
+- fixed GH #22: MySQL connection string lowercased
+- added MySQL support for Date/Time
Release 1.5.0 (2012-10-14)
==========================
@@ -130,7 +130,16 @@ namespace
case MYSQL_TYPE_LONGLONG:
if (unsig) return Poco::Data::MetaColumn::FDT_UINT64;
return Poco::Data::MetaColumn::FDT_INT64;
-
+
+ case MYSQL_TYPE_DATE:
+ return Poco::Data::MetaColumn::FDT_DATE;
+
+ case MYSQL_TYPE_TIME:
+ return Poco::Data::MetaColumn::FDT_TIME;
+
+ case MYSQL_TYPE_DATETIME:
+ return Poco::Data::MetaColumn::FDT_TIMESTAMP;
+
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING:
return Poco::Data::MetaColumn::FDT_STRING;
@@ -1,5 +1,5 @@
//
-// MySQLException.cpp
+// SessionImpl.cpp
//
// $Id: //poco/1.4/Data/MySQL/src/SessionImpl.cpp#1 $
//
@@ -67,7 +67,7 @@ const std::string SessionImpl::MYSQL_SERIALIZABLE = "SERIALIZABLE";
SessionImpl::SessionImpl(const std::string& connectionString, std::size_t loginTimeout) :
- Poco::Data::AbstractSessionImpl<SessionImpl>(toLower(connectionString), loginTimeout),
+ Poco::Data::AbstractSessionImpl<SessionImpl>(connectionString, loginTimeout),
_handle(0),
_connected(false),
_inTransaction(false)
@@ -417,6 +417,19 @@ void MySQLTest::testEmptyDB()
}
+void MySQLTest::testDateTime()
+{
+ if (!_pSession) fail ("Test not available.");
+
+ recreatePersonDateTimeTable();
+ _pExecutor->dateTime();
+ recreatePersonDateTable();
+ _pExecutor->date();
+ recreatePersonTimeTable();
+ _pExecutor->time();
+}
+
+
void MySQLTest::testBLOB()
{
if (!_pSession) fail ("Test not available.");
@@ -697,6 +710,33 @@ 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; }
+ catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
+ catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
+}
+
+
+void MySQLTest::recreatePersonDateTable()
+{
+ dropTable("Person");
+ try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATE)", now; }
+ catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
+ catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
+}
+
+
+void MySQLTest::recreatePersonTimeTable()
+{
+ dropTable("Person");
+ try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday TIME)", now; }
+ catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
+ catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
+}
+
+
void MySQLTest::recreateIntsTable()
{
dropTable("Strings");
@@ -833,6 +873,7 @@ CppUnit::Test* MySQLTest::suite()
CppUnit_addTest(pSuite, MySQLTest, testIllegalRange);
CppUnit_addTest(pSuite, MySQLTest, testSingleSelect);
CppUnit_addTest(pSuite, MySQLTest, testEmptyDB);
+ CppUnit_addTest(pSuite, MySQLTest, testDateTime);
//CppUnit_addTest(pSuite, MySQLTest, testBLOB);
CppUnit_addTest(pSuite, MySQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, MySQLTest, testFloat);
@@ -95,7 +95,7 @@ class MySQLTest: public CppUnit::TestCase
void testIllegalRange();
void testSingleSelect();
void testEmptyDB();
-
+ void testDateTime();
void testBLOB();
void testBLOBStmt();
@@ -129,6 +129,9 @@ class MySQLTest: public CppUnit::TestCase
void dropTable(const std::string& tableName);
void recreatePersonTable();
void recreatePersonBLOBTable();
+ void recreatePersonDateTimeTable();
+ void recreatePersonDateTable();
+ void recreatePersonTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
@@ -35,9 +35,12 @@
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Tuple.h"
+#include "Poco/DateTime.h"
#include "Poco/Any.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
+#include "Poco/Data/Date.h"
+#include "Poco/Data/Time.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/Transaction.h"
@@ -58,6 +61,7 @@ using Poco::Data::MySQL::ConnectionException;
using Poco::Data::MySQL::StatementException;
using Poco::format;
using Poco::Tuple;
+using Poco::DateTime;
using Poco::Any;
using Poco::AnyCast;
using Poco::NotFoundException;
@@ -1251,6 +1255,90 @@ void SQLExecutor::emptyDB()
}
+void SQLExecutor::dateTime()
+{
+ std::string funct = "dateTime()";
+ std::string lastName("Bart");
+ std::string firstName("Simpson");
+ std::string address("Springfield");
+ DateTime birthday(1980, 4, 1, 5, 45, 12);
+
+ 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); }
+ assert (count == 1);
+
+ DateTime bd;
+ assert (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); }
+ assert (bd == birthday);
+
+ std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
+}
+
+
+void SQLExecutor::date()
+{
+ std::string funct = "date()";
+ std::string lastName("Bart");
+ std::string firstName("Simpson");
+ std::string address("Springfield");
+ Date birthday(1980, 4, 1);
+
+ 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); }
+ assert (count == 1);
+
+ Date bd;
+ assert (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); }
+ assert (bd == birthday);
+
+ std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
+}
+
+
+void SQLExecutor::time()
+{
+ std::string funct = "date()";
+ std::string lastName("Bart");
+ std::string firstName("Simpson");
+ std::string address("Springfield");
+ Time birthday(1, 2, 3);
+
+ 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); }
+ assert (count == 1);
+
+ Time bd;
+ assert (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); }
+ assert (bd == birthday);
+
+ std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
+}
+
+
void SQLExecutor::blob(int bigSize)
{
std::string funct = "blob()";
@@ -1295,6 +1383,7 @@ void SQLExecutor::blob(int bigSize)
assert (res == big);
}
+
void SQLExecutor::blobStmt()
{
std::string funct = "blobStmt()";
@@ -1320,6 +1409,7 @@ void SQLExecutor::blobStmt()
poco_assert (res == blob);
}
+
void SQLExecutor::tuples()
{
typedef Tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int> TupleType;
@@ -1338,6 +1428,7 @@ void SQLExecutor::tuples()
assert (ret == t);
}
+
void SQLExecutor::tupleVector()
{
typedef Tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int> TupleType;
@@ -102,7 +102,9 @@ class SQLExecutor: public CppUnit::TestCase
void blob(int bigSize = 1024);
void blobStmt();
-
+ void dateTime();
+ void date();
+ void time();
void floats();
void doubles();
void tuples();
@@ -294,11 +294,11 @@ class TypeHandler<Nullable<T> >
poco_assert_dbg (pPreparator != 0);
if (obj.isNull())
{
- pPreparator->prepare(pos++, (Poco::Any&)Poco::Data::Keywords::null);
+ pPreparator->prepare(pos++, Poco::Data::Keywords::null);
}
else
{
- pPreparator->prepare(pos++, (T&)obj.value());
+ pPreparator->prepare(pos++, obj.value());
}
}
@@ -71,8 +71,10 @@ int main(int argc, char** argv)
session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3), Birthday DATE)", now;
// insert some rows
- session << "INSERT INTO Person VALUES('Bart Simpson', 'Springfield', 12, ?)", use(DateTime(1980, 4, 1)), now;
- session << "INSERT INTO Person VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(DateTime(1982, 5, 9)), now;
+ DateTime bd(1980, 4, 1);
+ DateTime ld(1982, 5, 9);
+ session << "INSERT INTO Person VALUES('Bart Simpson', 'Springfield', 12, ?)", use(bd), now;
+ session << "INSERT INTO Person VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(ld), now;
// a simple query
Statement select(session);
@@ -116,10 +116,14 @@ int main(int argc, char** argv)
session << "CREATE TABLE Simpsons (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3), Birthday DATE)", now;
// insert some rows
- session << "INSERT INTO Simpsons VALUES('Homer Simpson', 'Springfield', 42, ?)", use(DateTime(1956, 3, 1)), now;
- session << "INSERT INTO Simpsons VALUES('Marge Simpson', 'Springfield', 38, ?)", use(DateTime(1954, 10, 1)), now;
- session << "INSERT INTO Simpsons VALUES('Bart Simpson', 'Springfield', 12, ?)", use(DateTime(1980, 4, 1)), now;
- session << "INSERT INTO Simpsons VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(DateTime(1982, 5, 9)), now;
+ DateTime hd(1956, 3, 1);
+ session << "INSERT INTO Simpsons VALUES('Homer Simpson', 'Springfield', 42, ?)", use(hd), now;
+ DateTime md(1954, 10, 1);
+ session << "INSERT INTO Simpsons VALUES('Marge Simpson', 'Springfield', 38, ?)", use(md), now;
+ DateTime bd(1980, 4, 1);
+ session << "INSERT INTO Simpsons VALUES('Bart Simpson', 'Springfield', 12, ?)", use(bd), now;
+ DateTime ld(1982, 5, 9);
+ session << "INSERT INTO Simpsons VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(ld), now;
// create a statement and print the column names and data as HTML table
HTMLTableFormatter tf;

0 comments on commit eab40cf

Please sign in to comment.