mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
#310 Connect to MySQL db without specifying database name.
This commit is contained in:
parent
9c66edfb6f
commit
248d52164d
@ -129,8 +129,9 @@ void SessionImpl::open(const std::string& connect)
|
|||||||
if (options["user"] == "")
|
if (options["user"] == "")
|
||||||
throw MySQLException("create session: specify user name");
|
throw MySQLException("create session: specify user name");
|
||||||
|
|
||||||
if (options["db"] == "")
|
const char * db = NULL;
|
||||||
throw MySQLException("create session: specify database");
|
if (!options["db"].empty())
|
||||||
|
db = options["db"].c_str();
|
||||||
|
|
||||||
unsigned int port = 0;
|
unsigned int port = 0;
|
||||||
if (!NumberParser::tryParseUnsigned(options["port"], port) || 0 == port || port > 65535)
|
if (!NumberParser::tryParseUnsigned(options["port"], port) || 0 == port || port > 65535)
|
||||||
@ -154,7 +155,7 @@ void SessionImpl::open(const std::string& connect)
|
|||||||
_handle.connect(options["host"].c_str(),
|
_handle.connect(options["host"].c_str(),
|
||||||
options["user"].c_str(),
|
options["user"].c_str(),
|
||||||
options["password"].c_str(),
|
options["password"].c_str(),
|
||||||
options["db"].c_str(),
|
db,
|
||||||
port);
|
port);
|
||||||
|
|
||||||
addFeature("autoCommit",
|
addFeature("autoCommit",
|
||||||
|
@ -90,6 +90,27 @@ MySQLTest::~MySQLTest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MySQLTest::testConnectNoDB()
|
||||||
|
{
|
||||||
|
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. Disconnecting ..." << std::endl;
|
||||||
|
session.close();
|
||||||
|
std::cout << "Disconnected." << std::endl;
|
||||||
|
}
|
||||||
|
catch (ConnectionFailedException& ex)
|
||||||
|
{
|
||||||
|
std::cout << ex.displayText() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MySQLTest::testBareboneMySQL()
|
void MySQLTest::testBareboneMySQL()
|
||||||
{
|
{
|
||||||
if (!_pSession) fail ("Test not available.");
|
if (!_pSession) fail ("Test not available.");
|
||||||
@ -778,6 +799,7 @@ 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);
|
||||||
|
@ -57,6 +57,7 @@ public:
|
|||||||
MySQLTest(const std::string& name);
|
MySQLTest(const std::string& name);
|
||||||
~MySQLTest();
|
~MySQLTest();
|
||||||
|
|
||||||
|
void testConnectNoDB();
|
||||||
void testBareboneMySQL();
|
void testBareboneMySQL();
|
||||||
|
|
||||||
void testSimpleAccess();
|
void testSimpleAccess();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user