mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-03 07:52:29 +02: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.
|
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// 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,7 +68,7 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
|
|||||||
#define MYSQL_PWD "poco"
|
#define MYSQL_PWD "poco"
|
||||||
#define MYSQL_HOST "localhost"
|
#define MYSQL_HOST "localhost"
|
||||||
#define MYSQL_PORT 3306
|
#define MYSQL_PORT 3306
|
||||||
#define MYSQL_DB "test"
|
#define MYSQL_DB "pocotestdb"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Connection string
|
// Connection string
|
||||||
@ -76,14 +96,13 @@ MySQLTest::~MySQLTest()
|
|||||||
|
|
||||||
void MySQLTest::dbInfo(Session& session)
|
void MySQLTest::dbInfo(Session& session)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::cout << "Server Info: " << Utility::serverInfo(session) << std::endl;
|
std::cout << "Server Info: " << Utility::serverInfo(session) << std::endl;
|
||||||
std::cout << "Server Version: " << Utility::serverVersion(session) << std::endl;
|
std::cout << "Server Version: " << Utility::serverVersion(session) << std::endl;
|
||||||
std::cout << "Host Info: " << Utility::hostInfo(session) << std::endl;
|
std::cout << "Host Info: " << Utility::hostInfo(session) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MySQLTest::testConnectNoDB()
|
void MySQLTest::connectNoDB()
|
||||||
{
|
{
|
||||||
std::string dbConnString = "host=" MYSQL_HOST
|
std::string dbConnString = "host=" MYSQL_HOST
|
||||||
";user=" MYSQL_USER
|
";user=" MYSQL_USER
|
||||||
@ -95,6 +114,7 @@ void MySQLTest::testConnectNoDB()
|
|||||||
Session session(MySQL::Connector::KEY, dbConnString);
|
Session session(MySQL::Connector::KEY, dbConnString);
|
||||||
std::cout << "Connected to [" << "MySQL" << "] without database." << std::endl;
|
std::cout << "Connected to [" << "MySQL" << "] without database." << std::endl;
|
||||||
dbInfo(session);
|
dbInfo(session);
|
||||||
|
session << "CREATE DATABASE IF NOT EXISTS " MYSQL_DB ";", now;
|
||||||
std::cout << "Disconnecting ..." << std::endl;
|
std::cout << "Disconnecting ..." << std::endl;
|
||||||
session.close();
|
session.close();
|
||||||
std::cout << "Disconnected." << std::endl;
|
std::cout << "Disconnected." << std::endl;
|
||||||
@ -217,7 +237,6 @@ void MySQLTest::testLimitOnce()
|
|||||||
|
|
||||||
recreateIntsTable();
|
recreateIntsTable();
|
||||||
_pExecutor->limitOnce();
|
_pExecutor->limitOnce();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -692,7 +711,6 @@ void MySQLTest::testTupleWithNullable()
|
|||||||
|
|
||||||
void MySQLTest::dropTable(const std::string& tableName)
|
void MySQLTest::dropTable(const std::string& tableName)
|
||||||
{
|
{
|
||||||
|
|
||||||
try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
|
try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
|
||||||
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("dropTable()"); }
|
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("dropTable()"); }
|
||||||
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("dropTable()"); }
|
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("dropTable()"); }
|
||||||
@ -839,6 +857,15 @@ CppUnit::Test* MySQLTest::suite()
|
|||||||
{
|
{
|
||||||
MySQL::Connector::registerConnector();
|
MySQL::Connector::registerConnector();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
|
||||||
|
}
|
||||||
|
catch (ConnectionFailedException& ex)
|
||||||
|
{
|
||||||
|
std::cout << ex.displayText() << std::endl;
|
||||||
|
std::cout << "Trying to connect without DB and create one ..." << std::endl;
|
||||||
|
connectNoDB();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
|
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
|
||||||
@ -848,6 +875,7 @@ CppUnit::Test* MySQLTest::suite()
|
|||||||
std::cout << ex.displayText() << std::endl;
|
std::cout << ex.displayText() << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "*** Connected to [" << "MySQL" << "] test database." << std::endl;
|
std::cout << "*** Connected to [" << "MySQL" << "] test database." << std::endl;
|
||||||
dbInfo(*_pSession);
|
dbInfo(*_pSession);
|
||||||
@ -856,7 +884,6 @@ CppUnit::Test* MySQLTest::suite()
|
|||||||
|
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, MySQLTest, testConnectNoDB);
|
|
||||||
CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
|
CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
|
||||||
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
|
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
|
||||||
CppUnit_addTest(pSuite, MySQLTest, testComplexType);
|
CppUnit_addTest(pSuite, MySQLTest, testComplexType);
|
||||||
|
@ -8,7 +8,27 @@
|
|||||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// 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(const std::string& name);
|
||||||
~MySQLTest();
|
~MySQLTest();
|
||||||
|
|
||||||
void testConnectNoDB();
|
|
||||||
void testBareboneMySQL();
|
void testBareboneMySQL();
|
||||||
|
|
||||||
void testSimpleAccess();
|
void testSimpleAccess();
|
||||||
@ -106,6 +125,7 @@ public:
|
|||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void connectNoDB();
|
||||||
|
|
||||||
void dropTable(const std::string& tableName);
|
void dropTable(const std::string& tableName);
|
||||||
void recreatePersonTable();
|
void recreatePersonTable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user