mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
mysql test db autocreate
This commit is contained in:
parent
5e1be8cee7
commit
3d36b0a8c5
@ -6,7 +6,27 @@
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
@ -48,20 +68,20 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
|
||||
#define MYSQL_PWD "poco"
|
||||
#define MYSQL_HOST "localhost"
|
||||
#define MYSQL_PORT 3306
|
||||
#define MYSQL_DB "test"
|
||||
#define MYSQL_DB "pocotestdb"
|
||||
|
||||
//
|
||||
// Connection string
|
||||
std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST
|
||||
";user=" MYSQL_USER
|
||||
";password=" MYSQL_PWD
|
||||
";db=" MYSQL_DB
|
||||
";password=" MYSQL_PWD
|
||||
";db=" MYSQL_DB
|
||||
";compress=true"
|
||||
";auto-reconnect=true"
|
||||
";secure-auth=true";
|
||||
|
||||
|
||||
MySQLTest::MySQLTest(const std::string& name):
|
||||
MySQLTest::MySQLTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
MySQL::Connector::registerConnector();
|
||||
@ -76,25 +96,25 @@ MySQLTest::~MySQLTest()
|
||||
|
||||
void MySQLTest::dbInfo(Session& session)
|
||||
{
|
||||
|
||||
std::cout << "Server Info: " << Utility::serverInfo(session) << std::endl;
|
||||
std::cout << "Server Version: " << Utility::serverVersion(session) << std::endl;
|
||||
std::cout << "Host Info: " << Utility::hostInfo(session) << std::endl;
|
||||
std::cout << "Server Info: " << Utility::serverInfo(session) << std::endl;
|
||||
std::cout << "Server Version: " << Utility::serverVersion(session) << std::endl;
|
||||
std::cout << "Host Info: " << Utility::hostInfo(session) << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void MySQLTest::testConnectNoDB()
|
||||
void MySQLTest::connectNoDB()
|
||||
{
|
||||
std::string dbConnString = "host=" MYSQL_HOST
|
||||
";user=" MYSQL_USER
|
||||
";password=" MYSQL_PWD
|
||||
";compress=true;auto-reconnect=true";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Session session(MySQL::Connector::KEY, dbConnString);
|
||||
std::cout << "Connected to [" << "MySQL" << "] without database." << std::endl;
|
||||
dbInfo(session);
|
||||
session << "CREATE DATABASE IF NOT EXISTS " MYSQL_DB ";", now;
|
||||
std::cout << "Disconnecting ..." << std::endl;
|
||||
session.close();
|
||||
std::cout << "Disconnected." << std::endl;
|
||||
@ -104,8 +124,8 @@ void MySQLTest::testConnectNoDB()
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MySQLTest::testBareboneMySQL()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
@ -217,7 +237,6 @@ void MySQLTest::testLimitOnce()
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -428,7 +447,7 @@ void MySQLTest::testDateTime()
|
||||
void MySQLTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
|
||||
recreatePersonBLOBTable();
|
||||
_pExecutor->blob();
|
||||
|
||||
@ -441,7 +460,7 @@ void MySQLTest::testBLOB()
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
@ -648,7 +667,7 @@ void MySQLTest::testTupleWithNullable()
|
||||
|
||||
Info info(0, std::string("Address"), 10);
|
||||
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
|
||||
|
||||
|
||||
info.set<0>(info.get<0>()++);
|
||||
info.set<1>(null);
|
||||
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
|
||||
@ -692,7 +711,6 @@ void MySQLTest::testTupleWithNullable()
|
||||
|
||||
void MySQLTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
|
||||
try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("dropTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("dropTable()"); }
|
||||
@ -795,7 +813,7 @@ void MySQLTest::recreateTuplesTable()
|
||||
void MySQLTest::recreateNullableIntTable()
|
||||
{
|
||||
dropTable("NullableIntTest");
|
||||
try {
|
||||
try {
|
||||
*_pSession << "CREATE TABLE NullableIntTest (Id INTEGER(10), Value INTEGER(10))", now;
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateNullableIntTable()"); }
|
||||
@ -806,7 +824,7 @@ void MySQLTest::recreateNullableIntTable()
|
||||
void MySQLTest::recreateNullableStringTable()
|
||||
{
|
||||
dropTable("NullableStringTest");
|
||||
try {
|
||||
try {
|
||||
*_pSession << "CREATE TABLE NullableStringTest (Id INTEGER(10), Address VARCHAR(30), Age INTEGER(10))", now;
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateNullableStringTable()"); }
|
||||
@ -846,7 +864,17 @@ CppUnit::Test* MySQLTest::suite()
|
||||
catch (ConnectionFailedException& ex)
|
||||
{
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
return 0;
|
||||
std::cout << "Trying to connect without DB and create one ..." << std::endl;
|
||||
connectNoDB();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
|
||||
}
|
||||
catch (ConnectionFailedException& ex)
|
||||
{
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "*** Connected to [" << "MySQL" << "] test database." << std::endl;
|
||||
@ -856,7 +884,6 @@ CppUnit::Test* MySQLTest::suite()
|
||||
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MySQLTest, testConnectNoDB);
|
||||
CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
|
||||
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, MySQLTest, testComplexType);
|
||||
|
@ -8,7 +8,27 @@
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
@ -37,7 +57,6 @@ public:
|
||||
MySQLTest(const std::string& name);
|
||||
~MySQLTest();
|
||||
|
||||
void testConnectNoDB();
|
||||
void testBareboneMySQL();
|
||||
|
||||
void testSimpleAccess();
|
||||
@ -106,6 +125,7 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
static void connectNoDB();
|
||||
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
|
Loading…
Reference in New Issue
Block a user