ODBC fixes and tests (Oracle, SQL Server, MySQL on Windows)

MySQL back-end compile fixes on Windows
Nullable/NullType
This commit is contained in:
Aleksandar Fabijanic
2012-09-17 00:18:13 +00:00
parent 7029c95e07
commit 32c5b6b998
21 changed files with 572 additions and 444 deletions

View File

@@ -42,7 +42,7 @@
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/MySQL/Connector.h"
#include "Poco/Data/MySQL/MySQLException.h"
#include "Poco/Data/Nullable.h"
#include "Poco/Nullable.h"
#include "Poco/Data/DataException.h"
#include <iostream>
@@ -53,7 +53,7 @@ using Poco::Data::MySQL::StatementException;
using Poco::format;
using Poco::NotFoundException;
using Poco::Int32;
using Poco::Data::Nullable;
using Poco::Nullable;
using Poco::Tuple;
using Poco::NamedTuple;
@@ -63,14 +63,15 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
//
// Parameters for barebone-test
#define MYSQL_USER "root"
#define MYSQL_PWD ""
#define MYSQL_PWD "poco"
#define MYSQL_HOST "localhost"
#define MYSQL_PORT 3306
#define MYSQL_DB "test"
//
// Connection string to POCO
std::string MySQLTest::_dbConnString = "user=" MYSQL_USER
// Connection string
std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST
";user=" MYSQL_USER
";password=" MYSQL_PWD
";db=" MYSQL_DB
";compress=true;auto-reconnect=true";
@@ -79,7 +80,7 @@ std::string MySQLTest::_dbConnString = "user=" MYSQL_USER
MySQLTest::MySQLTest(const std::string& name):
CppUnit::TestCase(name)
{
MySQL::Connector::registerConnector();
MySQL::Connector::registerConnector();
}
@@ -605,27 +606,27 @@ void MySQLTest::testTupleWithNullable()
typedef Poco::Tuple<Int32, Nullable<std::string>, Nullable<Int32> > Info;
Info info(0, std::string("Address"), 10);
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
*_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;
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
info.set<0>(info.get<0>()++);
info.set<1>(std::string("Address!"));
info.set<2>(null);
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
std::vector<Info> infos;
infos.push_back(Info(10, std::string("A"), 0));
infos.push_back(Info(11, null, 12));
infos.push_back(Info(12, std::string("B"), null));
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(infos), now;
*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(infos), now;
std::vector<Info> result;
*_pSession << "SELECT Id, Address, Age FROM NullableStringTest", into(result), now;
*_pSession << "SELECT Id, Address, Age FROM NullableStringTest", into(result), now;
assert(result[0].get<1>() == std::string("Address"));
assert(result[0].get<2>() == 10);
@@ -650,10 +651,10 @@ 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()"); }
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()"); }
}
@@ -718,7 +719,7 @@ void MySQLTest::recreateNullableIntTable()
{
dropTable("NullableIntTest");
try {
*_pSession << "CREATE TABLE NullableIntTest (Id INTEGER(10), Value INTEGER(10))", now;
*_pSession << "CREATE TABLE NullableIntTest (Id INTEGER(10), Value INTEGER(10))", now;
}
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateNullableIntTable()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateNullableIntTable()"); }
@@ -729,7 +730,7 @@ void MySQLTest::recreateNullableStringTable()
{
dropTable("NullableStringTest");
try {
*_pSession << "CREATE TABLE NullableStringTest (Id INTEGER(10), Address VARCHAR(30), Age INTEGER(10))", now;
*_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()"); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateNullableStringTable()"); }
@@ -765,7 +766,7 @@ CppUnit::Test* MySQLTest::suite()
{
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
}
catch (ConnectionFailedException& ex)
catch (ConnectionFailedException& ex)
{
std::cout << ex.displayText() << std::endl;
return 0;
@@ -775,55 +776,55 @@ CppUnit::Test* MySQLTest::suite()
_pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, MySQLTest, testComplexType);
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, MySQLTest, testComplexTypeVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, MySQLTest, testLimit);
CppUnit_addTest(pSuite, MySQLTest, testLimitOnce);
CppUnit_addTest(pSuite, MySQLTest, testLimitPrepare);
CppUnit_addTest(pSuite, MySQLTest, testLimitZero);
CppUnit_addTest(pSuite, MySQLTest, testPrepare);
CppUnit_addTest(pSuite, MySQLTest, testSetSimple);
CppUnit_addTest(pSuite, MySQLTest, testSetComplex);
CppUnit_addTest(pSuite, MySQLTest, testSetComplexUnique);
CppUnit_addTest(pSuite, MySQLTest, testMultiSetSimple);
CppUnit_addTest(pSuite, MySQLTest, testMultiSetComplex);
CppUnit_addTest(pSuite, MySQLTest, testMapComplex);
CppUnit_addTest(pSuite, MySQLTest, testMapComplexUnique);
CppUnit_addTest(pSuite, MySQLTest, testMultiMapComplex);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, MySQLTest, testLowerLimitOk);
CppUnit_addTest(pSuite, MySQLTest, testLowerLimitFail);
CppUnit_addTest(pSuite, MySQLTest, testCombinedLimits);
CppUnit_addTest(pSuite, MySQLTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, MySQLTest, testRange);
CppUnit_addTest(pSuite, MySQLTest, testIllegalRange);
CppUnit_addTest(pSuite, MySQLTest, testSingleSelect);
CppUnit_addTest(pSuite, MySQLTest, testEmptyDB);
//CppUnit_addTest(pSuite, MySQLTest, testBLOB);
CppUnit_addTest(pSuite, MySQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, MySQLTest, testFloat);
CppUnit_addTest(pSuite, MySQLTest, testDouble);
CppUnit_addTest(pSuite, MySQLTest, testTuple);
CppUnit_addTest(pSuite, MySQLTest, testTupleVector);
CppUnit_addTest(pSuite, MySQLTest, testInternalExtraction);
CppUnit_addTest(pSuite, MySQLTest, testNull);
CppUnit_addTest(pSuite, MySQLTest, testNullableInt);
CppUnit_addTest(pSuite, MySQLTest, testNullableString);
CppUnit_addTest(pSuite, MySQLTest, testTupleWithNullable);
CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, MySQLTest, testComplexType);
CppUnit_addTest(pSuite, MySQLTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, MySQLTest, testComplexTypeVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, MySQLTest, testLimit);
CppUnit_addTest(pSuite, MySQLTest, testLimitOnce);
CppUnit_addTest(pSuite, MySQLTest, testLimitPrepare);
CppUnit_addTest(pSuite, MySQLTest, testLimitZero);
CppUnit_addTest(pSuite, MySQLTest, testPrepare);
CppUnit_addTest(pSuite, MySQLTest, testSetSimple);
CppUnit_addTest(pSuite, MySQLTest, testSetComplex);
CppUnit_addTest(pSuite, MySQLTest, testSetComplexUnique);
CppUnit_addTest(pSuite, MySQLTest, testMultiSetSimple);
CppUnit_addTest(pSuite, MySQLTest, testMultiSetComplex);
CppUnit_addTest(pSuite, MySQLTest, testMapComplex);
CppUnit_addTest(pSuite, MySQLTest, testMapComplexUnique);
CppUnit_addTest(pSuite, MySQLTest, testMultiMapComplex);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, MySQLTest, testLowerLimitOk);
CppUnit_addTest(pSuite, MySQLTest, testLowerLimitFail);
CppUnit_addTest(pSuite, MySQLTest, testCombinedLimits);
CppUnit_addTest(pSuite, MySQLTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, MySQLTest, testRange);
CppUnit_addTest(pSuite, MySQLTest, testIllegalRange);
CppUnit_addTest(pSuite, MySQLTest, testSingleSelect);
CppUnit_addTest(pSuite, MySQLTest, testEmptyDB);
//CppUnit_addTest(pSuite, MySQLTest, testBLOB);
CppUnit_addTest(pSuite, MySQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, MySQLTest, testFloat);
CppUnit_addTest(pSuite, MySQLTest, testDouble);
CppUnit_addTest(pSuite, MySQLTest, testTuple);
CppUnit_addTest(pSuite, MySQLTest, testTupleVector);
CppUnit_addTest(pSuite, MySQLTest, testInternalExtraction);
CppUnit_addTest(pSuite, MySQLTest, testNull);
CppUnit_addTest(pSuite, MySQLTest, testNullableInt);
CppUnit_addTest(pSuite, MySQLTest, testNullableString);
CppUnit_addTest(pSuite, MySQLTest, testTupleWithNullable);
CppUnit_addTest(pSuite, MySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, MySQLTest, testTransaction);
CppUnit_addTest(pSuite, MySQLTest, testReconnect);
return pSuite;
return pSuite;
}

View File

@@ -1,125 +1,125 @@
//
// SQLExecutor.h
//
// $Id: //poco/1.4/Data/MySQL/testsuite/src/SQLExecutor.h#1 $
//
// Definition of the SQLExecutor class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// 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.
//
#ifndef SQLExecutor_INCLUDED
#define SQLExecutor_INCLUDED
#include "Poco/Data/MySQL/MySQL.h"
#include "Poco/Data/Session.h"
class SQLExecutor: public CppUnit::TestCase
{
public:
enum DataBinding
{
PB_IMMEDIATE,
PB_AT_EXEC
};
enum DataExtraction
{
DE_MANUAL,
DE_BOUND
};
SQLExecutor(const std::string& name, Poco::Data::Session* _pSession);
~SQLExecutor();
void bareboneMySQLTest(const char* host, const char* user, const char* pwd, const char* db, int port, const char* tableCreateString);
/// This function uses "bare bone" MySQL API calls (i.e. calls are not
/// "wrapped" in PocoData framework structures).
/// The purpose of the function is to verify that driver behaves
/// correctly. If this test passes, subsequent tests failures are likely ours.
void simpleAccess();
void complexType();
void simpleAccessVector();
void complexTypeVector();
void insertVector();
void insertEmptyVector();
void insertSingleBulk();
void insertSingleBulkVec();
void limits();
void limitOnce();
void limitPrepare();
void limitZero();
void prepare();
void setSimple();
void setComplex();
void setComplexUnique();
void multiSetSimple();
void multiSetComplex();
void mapComplex();
void mapComplexUnique();
void multiMapComplex();
void selectIntoSingle();
void selectIntoSingleStep();
void selectIntoSingleFail();
void lowerLimitOk();
void lowerLimitFail();
void combinedLimits();
void combinedIllegalLimits();
void ranges();
void illegalRange();
void singleSelect();
void emptyDB();
void blob(int bigSize = 1024);
void blobStmt();
void floats();
void doubles();
void tuples();
void tupleVector();
void internalExtraction();
void doNull();
//
// SQLExecutor.h
//
// $Id: //poco/1.4/Data/MySQL/testsuite/src/SQLExecutor.h#1 $
//
// Definition of the SQLExecutor class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// 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.
//
#ifndef SQLExecutor_INCLUDED
#define SQLExecutor_INCLUDED
#include "Poco/Data/MySQL/MySQL.h"
#include "Poco/Data/Session.h"
class SQLExecutor: public CppUnit::TestCase
{
public:
enum DataBinding
{
PB_IMMEDIATE,
PB_AT_EXEC
};
enum DataExtraction
{
DE_MANUAL,
DE_BOUND
};
SQLExecutor(const std::string& name, Poco::Data::Session* _pSession);
~SQLExecutor();
void bareboneMySQLTest(const char* host, const char* user, const char* pwd, const char* db, int port, const char* tableCreateString);
/// This function uses "bare bone" MySQL API calls (i.e. calls are not
/// "wrapped" in PocoData framework structures).
/// The purpose of the function is to verify that driver behaves
/// correctly. If this test passes, subsequent tests failures are likely ours.
void simpleAccess();
void complexType();
void simpleAccessVector();
void complexTypeVector();
void insertVector();
void insertEmptyVector();
void insertSingleBulk();
void insertSingleBulkVec();
void limits();
void limitOnce();
void limitPrepare();
void limitZero();
void prepare();
void setSimple();
void setComplex();
void setComplexUnique();
void multiSetSimple();
void multiSetComplex();
void mapComplex();
void mapComplexUnique();
void multiMapComplex();
void selectIntoSingle();
void selectIntoSingleStep();
void selectIntoSingleFail();
void lowerLimitOk();
void lowerLimitFail();
void combinedLimits();
void combinedIllegalLimits();
void ranges();
void illegalRange();
void singleSelect();
void emptyDB();
void blob(int bigSize = 1024);
void blobStmt();
void floats();
void doubles();
void tuples();
void tupleVector();
void internalExtraction();
void doNull();
void sessionTransaction(const std::string& connect);
void transaction(const std::string& connect);
void reconnect();
private:
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
Poco::Data::Session* _pSession;
};
#endif // SQLExecutor_INCLUDED
void transaction(const std::string& connect);
void reconnect();
private:
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
Poco::Data::Session* _pSession;
};
#endif // SQLExecutor_INCLUDED