1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-20 09:07:14 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@ -0,0 +1,28 @@
//
// Driver.cpp
//
// Console-based test driver for Poco SQLite.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "CppUnit/TestRunner.h"
#include "ODBCTestSuite.h"
#include "Poco/Data/ODBC/Connector.h"
int main(int ac, char **av)
{
Poco::Data::ODBC::Connector::registerConnector();
std::vector<std::string> args;
for (int i = 0; i < ac; ++i)
args.push_back(std::string(av[i]));
CppUnit::TestRunner runner;
runner.addTest("ODBCTestSuite", ODBCTestSuite::suite());
return runner.run(args) ? 0 : 1;
}

View File

@ -0,0 +1,213 @@
//
// ODBCAccessTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCAccessTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include <sqltypes.h>
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::Session;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::NotFoundException;
Session* ODBCAccessTest::_pSession = 0;
std::string ODBCAccessTest::_dbConnString;
Poco::Data::ODBC::Utility::DriverMap ODBCAccessTest::_drivers;
ODBCAccessTest::ODBCAccessTest(const std::string& name):
CppUnit::TestCase(name)
{
}
ODBCAccessTest::~ODBCAccessTest()
{
}
void ODBCAccessTest::testSimpleAccess()
{
if (!_pSession) fail ("Test not available.");
std::string lastName = "lastName";
int age = 133132;
int count = 0;
std::string result;
recreatePersonTable();
count = 0;
try { *_pSession << "INSERT INTO PERSON VALUES('lastName', 'firstName', 'Address', 133132)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()");}
try { *_pSession << "SELECT COUNT(*) FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
assertTrue (count == 1);
try { *_pSession << "SELECT LastName FROM PERSON", into(result), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
assertTrue (lastName == result);
try { *_pSession << "SELECT Age FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
assertTrue (count == age);
}
void ODBCAccessTest::dropTable(const std::string& tableName)
{
try
{
*_pSession << format("DROP TABLE %s", tableName), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (-1305 == it->_nativeError)//MS Access -1305 (table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCAccessTest::recreatePersonTable()
{
dropTable("Person");
*_pSession << "CREATE TABLE Person (LastName TEXT(30), FirstName TEXT(30), Address TEXT(30), Age INTEGER)", now;
}
bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& dsn)
{
Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv)
{
if (((itDrv->first).find(driver) != std::string::npos))
{
std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl;
break;
}
}
if (_drivers.end() == itDrv)
{
std::cout << driver << " driver NOT found, tests not available." << std::endl;
return false;
}
Utility::DSNMap dataSources;
Utility::dataSources(dataSources);
Utility::DSNMap::iterator itDSN = dataSources.begin();
for (; itDSN != dataSources.end(); ++itDSN)
{
if (itDSN->first == dsn && itDSN->second == driver)
{
std::cout << "DSN found: " << itDSN->first
<< " (" << itDSN->second << ')' << std::endl;
format(_dbConnString, "DSN=%s", dsn);
return true;
}
}
// DSN not found, try connect without it
format(_dbConnString, "DRIVER=%s;"
"UID=admin;"
"UserCommitSync=Yes;"
"Threads=3;"
"SafeTransactions=0;"
"PageTimeout=5;"
"MaxScanRows=8;"
"MaxBufferSize=2048;"
"FIL=MS Access;"
"DriverId=25;"
"DBQ=test.mdb;", driver);
return true;
}
void ODBCAccessTest::setUp()
{
}
void ODBCAccessTest::tearDown()
{
dropTable("Person");
}
bool ODBCAccessTest::init(const std::string& driver, const std::string& dsn)
{
Utility::drivers(_drivers);
if (!canConnect(driver, dsn)) return false;
try
{
_pSession = new Session(Poco::Data::ODBC::Connector::KEY, _dbConnString);
}catch (ConnectionException& ex)
{
std::cout << ex.toString() << std::endl;
return false;
}
//N.B. Access driver does not suport check for connection.
std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
return true;
}
CppUnit::Test* ODBCAccessTest::suite()
{
if (init("Microsoft Access Driver (*.mdb)", "PocoDataAccessTest"))
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCAccessTest");
CppUnit_addTest(pSuite, ODBCAccessTest, testSimpleAccess);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,58 @@
//
// ODBCAccessTest.h
//
// Definition of the ODBCAccessTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCAccessTest_INCLUDED
#define ODBCAccessTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/SharedPtr.h"
#include "CppUnit/TestCase.h"
#include "SQLExecutor.h"
class ODBCAccessTest: public CppUnit::TestCase
/// MS Access ODBC test class
/// Tested:
///
/// Driver | DB | OS
/// ------------+-----------+------------------------------------------
/// 4.00.6305.00| Jet 4.0 | MS Windows XP Professional x64 v.2003/SP1
{
public:
ODBCAccessTest(const std::string& name);
~ODBCAccessTest();
void testSimpleAccess();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
void dropTable(const std::string& tableName);
void recreatePersonTable();
static bool init(const std::string& driver, const std::string& dsn);
static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString;
static Poco::Data::Session* _pSession;
bool _owner;
};
#endif // ODBCAccessTest_INCLUDED

View File

@ -0,0 +1,679 @@
//
// ODBCDB2Test.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCDB2Test.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
#include "Poco/Tuple.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include <sqltypes.h>
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::DataException;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::Tuple;
using Poco::Any;
using Poco::AnyCast;
using Poco::DynamicAny;
using Poco::NotFoundException;
#define DB2_ODBC_DRIVER "IBM DB2 ODBC DRIVER - DB2COPY1"
#define DB2_DSN "PocoDataDB2Test"
#define DB2_SERVER POCO_ODBC_TEST_DATABASE_SERVER
#define DB2_PORT "50000"
#define DB2_DB "POCOTEST"
#define DB2_UID "db2admin"
#define DB2_PWD "db2admin"
ODBCTest::SessionPtr ODBCDB2Test::_pSession;
ODBCTest::ExecPtr ODBCDB2Test::_pExecutor;
std::string ODBCDB2Test::_driver = DB2_ODBC_DRIVER;
std::string ODBCDB2Test::_dsn = DB2_DSN;
std::string ODBCDB2Test::_uid = DB2_UID;
std::string ODBCDB2Test::_pwd = DB2_PWD;
std::string ODBCDB2Test::_connectString = "Driver=" DB2_ODBC_DRIVER ";"
"Database=" DB2_DB ";"
"Hostname=" DB2_SERVER ";"
"Port=" DB2_PORT ";"
"Protocol=TCPIP;"
"Uid=" DB2_UID ";"
"Pwd=" DB2_PWD ";";
ODBCDB2Test::ODBCDB2Test(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
}
ODBCDB2Test::~ODBCDB2Test()
{
}
void ODBCDB2Test::testBareboneODBC()
{
if (!_pSession) fail ("Test not available.");
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BLOB,"
"Fourth INTEGER,"
"Fifth FLOAT,"
"Sixth TIMESTAMP)";
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second INTEGER,"
"Third FLOAT)";
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
}
void ODBCDB2Test::testBLOB()
{
if (!_pSession) fail ("Test not available.");
const std::size_t maxFldSize = 1000000;
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
recreatePersonBLOBTable();
try
{
_pExecutor->blob(maxFldSize);
fail ("must fail");
}
catch (DataException&)
{
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
}
for (int i = 0; i < 8;)
{
recreatePersonBLOBTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->blob(maxFldSize);
i += 2;
}
recreatePersonBLOBTable();
try
{
_pExecutor->blob(maxFldSize+1);
fail ("must fail");
}
catch (DataException&) { }
}
void ODBCDB2Test::testFilter()
{
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreateVectorsTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->filter("SELECT * FROM Vectors ORDER BY i0 ASC", "i0");
i += 2;
}
}
void ODBCDB2Test::testStoredProcedure()
{
if (!_pSession) fail ("Test not available.");
for (int k = 0; k < 8;)
{
_pSession->setFeature("autoBind", bindValue(k));
_pSession->setFeature("autoExtract", bindValue(k+1));
dropObject("PROCEDURE", "storedProcedure");
*_pSession << "CREATE PROCEDURE storedProcedure(OUT outParam INTEGER) "
"BEGIN "
" SET outParam = -1; "
"END" , now;
int i = 0;
*_pSession << "{call storedProcedure(?)}", out(i), now;
assertTrue (-1 == i);
dropObject("PROCEDURE", "storedProcedure");
*_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
"BEGIN "
" SET outParam = inParam*inParam; "
"END" , now;
i = 2;
int j = 0;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
dropObject("PROCEDURE", "storedProcedure");
*_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
"BEGIN "
" SET ioParam = ioParam*ioParam; "
"END" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
//TIMESTAMP is not supported as stored procedure parameter in DB2
//(SQL0182N An expression with a datetime value or a labeled duration is not valid.)
*_pSession << "CREATE PROCEDURE storedProcedure(inParam VARCHAR(1000), OUT outParam VARCHAR(1000)) "
"BEGIN "
" SET outParam = inParam; "
"END" , now;
std::string inParam =
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
std::string outParam;
*_pSession << "{call storedProcedure(?,?)}", in(inParam), out(outParam), now;
assertTrue (inParam == outParam);
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCDB2Test::testStoredProcedureAny()
{
if (!_pSession) fail ("Test not available.");
for (int k = 0; k < 8;)
{
_pSession->setFeature("autoBind", bindValue(k));
_pSession->setFeature("autoExtract", bindValue(k+1));
Any i = 2;
Any j = 0;
*_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
"BEGIN "
" SET outParam = inParam*inParam; "
"END" , now;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == AnyCast<int>(j));
*_pSession << "DROP PROCEDURE storedProcedure;", now;
*_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
"BEGIN "
" SET ioParam = ioParam*ioParam; "
"END" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == AnyCast<int>(i));
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCDB2Test::testStoredProcedureDynamicAny()
{
if (!_pSession) fail ("Test not available.");
for (int k = 0; k < 8;)
{
_pSession->setFeature("autoBind", bindValue(k));
DynamicAny i = 2;
DynamicAny j = 0;
*_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
"BEGIN "
" SET outParam = inParam*inParam; "
"END" , now;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
*_pSession << "DROP PROCEDURE storedProcedure;", now;
*_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
"BEGIN "
" SET ioParam = ioParam*ioParam; "
"END" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCDB2Test::testStoredFunction()
{
if (!_pSession) fail ("Test not available.");
for (int k = 0; k < 8;)
{
_pSession->setFeature("autoBind", bindValue(k));
_pSession->setFeature("autoExtract", bindValue(k+1));
dropObject("PROCEDURE", "storedFunction");
*_pSession << "CREATE PROCEDURE storedFunction() "
"BEGIN "
" RETURN -1; "
"END" , now;
int i = 0;
*_pSession << "{? = call storedFunction()}", out(i), now;
assertTrue (-1 == i);
dropObject("PROCEDURE", "storedFunction");
*_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER) "
"BEGIN "
" RETURN inParam*inParam; "
"END" , now;
i = 2;
int result = 0;
*_pSession << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == result);
dropObject("PROCEDURE", "storedFunction");
*_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER, OUT outParam INTEGER) "
"BEGIN "
" SET outParam = inParam*inParam; "
" RETURN outParam; "
"END" , now;
i = 2;
int j = 0;
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
assertTrue (4 == j);
assertTrue (j == result);
dropObject("PROCEDURE", "storedFunction");
*_pSession << "CREATE PROCEDURE storedFunction(INOUT param1 INTEGER, INOUT param2 INTEGER) "
"BEGIN "
" DECLARE temp INTEGER;"
" SET temp = param1; "
" SET param1 = param2; "
" SET param2 = temp; "
" RETURN param1 + param2; "
"END" , now;
i = 1;
j = 2;
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
assertTrue (1 == j);
assertTrue (2 == i);
assertTrue (3 == result);
Tuple<int, int> params(1, 2);
assertTrue (1 == params.get<0>());
assertTrue (2 == params.get<1>());
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
assertTrue (1 == params.get<1>());
assertTrue (2 == params.get<0>());
assertTrue (3 == result);
dropObject("PROCEDURE", "storedFunction");
_pSession->setFeature("autoBind", true);
*_pSession << "CREATE PROCEDURE storedFunction(inParam VARCHAR(10), OUT outParam VARCHAR(10)) "
"BEGIN "
" SET outParam = inParam; "
" RETURN LENGTH(outParam);"//DB2 allows only integer as return type
"END" , now;
std::string inParam = "123456789";
std::string outParam;
int ret;
*_pSession << "{? = call storedFunction(?,?)}", out(ret), in(inParam), out(outParam), now;
assertTrue (inParam == outParam);
assertTrue (ret == inParam.size());
dropObject("PROCEDURE", "storedFunction");
k += 2;
}
}
void ODBCDB2Test::dropObject(const std::string& type, const std::string& name)
{
try
{
*_pSession << format("DROP %s %s", type, name), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (-204 == it->_nativeError)//(table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCDB2Test::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat FLOAT NULL , EmptyDateTime TIMESTAMP NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCDB2Test::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCDB2Test::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCDB2Test::recreatePersonDateTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
}
void ODBCDB2Test::recreatePersonTimeTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornTime TIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
}
void ODBCDB2Test::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCDB2Test::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCDB2Test::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCDB2Test::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCDB2Test::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { *_pSession << "CREATE TABLE Tuples "
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCDB2Test::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCDB2Test::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { *_pSession << "CREATE TABLE Anys (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCDB2Test::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCDB2Test::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try
{
session() << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
"Second BLOB,"
"Third INTEGER,"
"Fourth FLOAT,"
"Fifth TIMESTAMP)", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
}
void ODBCDB2Test::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR(100),"
"Name VARCHAR(100),"
"ProcessId INTEGER,"
"Thread VARCHAR(100), "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR(100),"
"DateTime TIMESTAMP)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
CppUnit::Test* ODBCDB2Test::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");
CppUnit_addTest(pSuite, ODBCDB2Test, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCDB2Test, testZeroRows);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexType);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertList);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertDeque);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCDB2Test, testAffectedRows);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCDB2Test, testLimit);
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitOnce);
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitZero);
CppUnit_addTest(pSuite, ODBCDB2Test, testPrepare);
CppUnit_addTest(pSuite, ODBCDB2Test, testBulk);
CppUnit_addTest(pSuite, ODBCDB2Test, testBulkPerformance);
CppUnit_addTest(pSuite, ODBCDB2Test, testSetSimple);
CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplex);
CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplex);
CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCDB2Test, testRange);
CppUnit_addTest(pSuite, ODBCDB2Test, testIllegalRange);
CppUnit_addTest(pSuite, ODBCDB2Test, testSingleSelect);
CppUnit_addTest(pSuite, ODBCDB2Test, testEmptyDB);
CppUnit_addTest(pSuite, ODBCDB2Test, testBLOB);
CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCDB2Test, testDate);
CppUnit_addTest(pSuite, ODBCDB2Test, testTime);
CppUnit_addTest(pSuite, ODBCDB2Test, testDateTime);
CppUnit_addTest(pSuite, ODBCDB2Test, testFloat);
CppUnit_addTest(pSuite, ODBCDB2Test, testDouble);
CppUnit_addTest(pSuite, ODBCDB2Test, testTuple);
CppUnit_addTest(pSuite, ODBCDB2Test, testTupleVector);
CppUnit_addTest(pSuite, ODBCDB2Test, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCDB2Test, testFilter);
CppUnit_addTest(pSuite, ODBCDB2Test, testInternalBulkExtraction);
CppUnit_addTest(pSuite, ODBCDB2Test, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedure);
CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedureAny);
CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedureDynamicAny);
CppUnit_addTest(pSuite, ODBCDB2Test, testStoredFunction);
CppUnit_addTest(pSuite, ODBCDB2Test, testNull);
CppUnit_addTest(pSuite, ODBCDB2Test, testRowIterator);
CppUnit_addTest(pSuite, ODBCDB2Test, testAsync);
CppUnit_addTest(pSuite, ODBCDB2Test, testAny);
CppUnit_addTest(pSuite, ODBCDB2Test, testDynamicAny);
CppUnit_addTest(pSuite, ODBCDB2Test, testMultipleResults);
CppUnit_addTest(pSuite, ODBCDB2Test, testSQLChannel);
CppUnit_addTest(pSuite, ODBCDB2Test, testSQLLogger);
CppUnit_addTest(pSuite, ODBCDB2Test, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransactor);
CppUnit_addTest(pSuite, ODBCDB2Test, testNullable);
CppUnit_addTest(pSuite, ODBCDB2Test, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,73 @@
//
// ODBCDB2Test.h
//
// Definition of the ODBCDB2Test class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCDB2Test_INCLUDED
#define ODBCDB2Test_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
class ODBCDB2Test: public ODBCTest
/// IBM DB2 UDB ODBC test class
/// Tested:
///
/// Driver | DB | OS
/// ------------+-------------------+------------------------------------------
/// 9.01.00.356 | DB2 Express-C 9.1 | MS Windows XP Professional x64 v.2003/SP1
{
public:
ODBCDB2Test(const std::string& name);
~ODBCDB2Test();
void testBareboneODBC();
void testBLOB();
void testFilter();
void testStoredProcedure();
void testStoredProcedureAny();
void testStoredProcedureDynamicAny();
void testStoredFunction();
static CppUnit::Test* suite();
private:
void dropObject(const std::string& type, const std::string& tableName);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTable();
void recreatePersonTimeTable();
void recreatePersonDateTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateMiscTable();
void recreateLogTable();
static ODBCTest::SessionPtr _pSession;
static ODBCTest::ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _connectString;
};
#endif // ODBCDB2Test_INCLUDED

View File

@ -0,0 +1,504 @@
//
// ODBCMySQLTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCMySQLTest.h"
#include "ODBCTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Tuple.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include <sqltypes.h>
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::DataException;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::Tuple;
using Poco::NotFoundException;
#define MYSQL_ODBC_DRIVER "MySQL ODBC 5.3 Unicode Driver"
#define MYSQL_DSN "PocoDataMySQLTest"
#define MYSQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
#define MYSQL_DB "test"
#define MYSQL_UID "root"
#define MYSQL_PWD "poco"
#define MYSQL_DB "test"
ODBCTest::SessionPtr ODBCMySQLTest::_pSession;
ODBCTest::ExecPtr ODBCMySQLTest::_pExecutor;
std::string ODBCMySQLTest::_driver = MYSQL_ODBC_DRIVER;
std::string ODBCMySQLTest::_dsn = MYSQL_DSN;
std::string ODBCMySQLTest::_uid = MYSQL_UID;
std::string ODBCMySQLTest::_pwd = MYSQL_PWD;
std::string ODBCMySQLTest::_db = MYSQL_DB;
std::string ODBCMySQLTest::_connectString = "DRIVER={" MYSQL_ODBC_DRIVER "};"
"DATABASE=" MYSQL_DB ";"
"SERVER=" MYSQL_SERVER ";"
"UID=" MYSQL_UID ";"
"PWD=" MYSQL_PWD ";";
ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
_pExecutor->execute("SET @@global.sql_mode= '';"); // disable strict mode
}
ODBCMySQLTest::~ODBCMySQLTest()
{
}
void ODBCMySQLTest::testBareboneODBC()
{
if (!_pSession) fail ("Test not available.");
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third VARBINARY(30),"
"Fourth INTEGER,"
"Fifth FLOAT,"
"Sixth DATETIME)";
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
/*
MySQL supports batch statements as of 3.51.18
(http://bugs.mysql.com/bug.php?id=7445)
has different SQL syntax for it and behaves differently
compared to other DBMS systems in regards to SQLMoreResults.
So, we skip this test.
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second INTEGER,"
"Third FLOAT)";
std::string MULTI_INSERT = "INSERT INTO Test VALUES "
"('1', 2, 3.5),"
"('2', 3, 4.5),"
"('3', 4, 5.5),"
"('4', 5, 6.5),"
"('5', 6, 7.5);";
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, MULTI_INSERT);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, MULTI_INSERT);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, MULTI_INSERT);
_pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, MULTI_INSERT);
*/
}
void ODBCMySQLTest::testBLOB()
{
if (!_pSession) fail ("Test not available.");
const std::size_t maxFldSize = 65534;
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
recreatePersonBLOBTable();
try
{
_pExecutor->blob(maxFldSize);
fail ("must fail");
}
catch (DataException&)
{
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
}
for (int i = 0; i < 8;)
{
recreatePersonBLOBTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->blob(maxFldSize);
i += 2;
}
recreatePersonBLOBTable();
try
{
_pExecutor->blob(maxFldSize+1);
fail ("must fail");
}
catch (DataException&) { }
}
void ODBCMySQLTest::testNull()
{
if (!_pSession) fail ("Test not available.");
// test for NOT NULL violation exception
for (int i = 0; i < 8;)
{
recreateNullsTable("NOT NULL");
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->notNulls("HY000");
i += 2;
}
// test for null insertion
for (int i = 0; i < 8;)
{
recreateNullsTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->nulls();
i += 2;
}
}
void ODBCMySQLTest::testStoredProcedure()
{
//MySQL is currently buggy in this area:
// http://bugs.mysql.com/bug.php?id=17898
// http://bugs.mysql.com/bug.php?id=27632
// Additionally, the standard ODBC stored procedure call syntax
// {call storedProcedure(?)} is currently (3.51.12.00) not supported.
// See http://bugs.mysql.com/bug.php?id=26535
// Poco::Data support for MySQL ODBC is postponed until the above
// issues are resolved.
}
void ODBCMySQLTest::testStoredFunction()
{
//MySQL is currently buggy in this area:
// http://bugs.mysql.com/bug.php?id=17898
// http://bugs.mysql.com/bug.php?id=27632
// Additionally, the standard ODBC stored procedure call syntax
// {call storedProcedure(?)} is currently (3.51.12.00) not supported.
// See http://bugs.mysql.com/bug.php?id=26535
// Poco::Data support for MySQL ODBC is postponed until the above
// issues are resolved.
}
void ODBCMySQLTest::testMultipleResults()
{
/*
MySQL supports batch statements as of 3.51.18
http://bugs.mysql.com/bug.php?id=7445
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreatePersonTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->multipleResults();
i += 2;
}
*/
}
void ODBCMySQLTest::testFilter()
{
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreateVectorsTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->filter("SELECT * FROM Vectors ORDER BY i0 ASC", "i0");
i += 2;
}
}
void ODBCMySQLTest::dropObject(const std::string& type, const std::string& name)
{
*_pSession << format("DROP %s IF EXISTS %s", type, name), now;
}
void ODBCMySQLTest::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat FLOAT NULL , EmptyDateTime TIMESTAMP NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCMySQLTest::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCMySQLTest::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCMySQLTest::recreatePersonDateTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
}
void ODBCMySQLTest::recreatePersonTimeTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornTime TIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
}
void ODBCMySQLTest::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born DATETIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCMySQLTest::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCMySQLTest::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCMySQLTest::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCMySQLTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { *_pSession << "CREATE TABLE Tuples "
"(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
"i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
"i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCMySQLTest::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCMySQLTest::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { *_pSession << "CREATE TABLE Anys (i0 INTEGER, flt0 DOUBLE, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCMySQLTest::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCMySQLTest::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try { *_pSession << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
"Second VARBINARY(30),"
"Third INTEGER,"
"Fourth FLOAT,"
"Fifth DATETIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCMySQLTest::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR(100),"
"Name VARCHAR(100),"
"ProcessId INTEGER,"
"Thread VARCHAR(100), "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR(100),"
"DateTime DATETIME)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
CppUnit::Test* ODBCMySQLTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString, _db)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCMySQLTest, testZeroRows);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertList);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertDeque);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCMySQLTest, testAffectedRows);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimit);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
CppUnit_addTest(pSuite, ODBCMySQLTest, testBulk);
CppUnit_addTest(pSuite, ODBCMySQLTest, testBulkPerformance);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCMySQLTest, testRange);
CppUnit_addTest(pSuite, ODBCMySQLTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCMySQLTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOB);
CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCMySQLTest, testDate);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTime);
CppUnit_addTest(pSuite, ODBCMySQLTest, testDateTime);
CppUnit_addTest(pSuite, ODBCMySQLTest, testFloat);
CppUnit_addTest(pSuite, ODBCMySQLTest, testDouble);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTuple);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredProcedure);
CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredFunction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testFilter);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalBulkExtraction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCMySQLTest, testNull);
CppUnit_addTest(pSuite, ODBCMySQLTest, testRowIterator);
CppUnit_addTest(pSuite, ODBCMySQLTest, testAsync);
CppUnit_addTest(pSuite, ODBCMySQLTest, testAny);
CppUnit_addTest(pSuite, ODBCMySQLTest, testDynamicAny);
//CppUnit_addTest(pSuite, ODBCMySQLTest, testMultipleResults);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSQLChannel);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCMySQLTest, testNullable);
CppUnit_addTest(pSuite, ODBCMySQLTest, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,79 @@
//
// ODBCMySQLTest.h
//
// Definition of the ODBCMySQLTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCMySQLTest_INCLUDED
#define ODBCMySQLTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
class ODBCMySQLTest: public ODBCTest
/// MySQL ODBC test class
/// Tested:
///
/// Driver | DB | OS | Driver Manager
/// ----------------+---------------------------+-------------------------------------------+---------------------
/// 03.51.12.00 | MySQL 5.0.27-community-nt | MS Windows XP Professional x64 v.2003/SP1 | 3.526.3959.0
/// 3.51.11.-6 | MySQL 5.0.27-community-nt | Ubuntu 7.04 (2.6.20-15-generic #2 SMP) | unixODBC 2.2.11.-13
///
{
public:
ODBCMySQLTest(const std::string& name);
~ODBCMySQLTest();
void testBareboneODBC();
void testBLOB();
void testStoredProcedure();
void testStoredFunction();
void testNull();
void testMultipleResults();
void testFilter();
static CppUnit::Test* suite();
private:
void dropObject(const std::string& type, const std::string& name);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTable();
void recreatePersonTimeTable();
void recreatePersonDateTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateMiscTable();
void recreateLogTable();
static ODBCTest::SessionPtr _pSession;
static ODBCTest::ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _db;
static std::string _connectString;
};
#endif // ODBCMySQLTest_INCLUDED

View File

@ -0,0 +1,943 @@
//
// ODBCOracleTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCOracleTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Tuple.h"
#include "Poco/Format.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
#include "Poco/DateTime.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/AutoTransaction.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
using namespace Poco::Data::Keywords;
using Poco::Data::DataException;
using Poco::Data::Statement;
using Poco::Data::RecordSet;
using Poco::Data::AutoTransaction;
using Poco::Data::Session;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::Tuple;
using Poco::Any;
using Poco::AnyCast;
using Poco::DynamicAny;
using Poco::DateTime;
#define ORACLE_ODBC_DRIVER "Oracle in XE"
#define ORACLE_DSN "PocoDataOracleTest"
#define ORACLE_SERVER POCO_ODBC_TEST_DATABASE_SERVER
#define ORACLE_PORT "1521"
#define ORACLE_SID "XE"
#define ORACLE_UID "poco"
#define ORACLE_PWD "poco"
ODBCTest::SessionPtr ODBCOracleTest::_pSession;
ODBCTest::ExecPtr ODBCOracleTest::_pExecutor;
std::string ODBCOracleTest::_driver = ORACLE_ODBC_DRIVER;
std::string ODBCOracleTest::_dsn = ORACLE_DSN;
std::string ODBCOracleTest::_uid = ORACLE_UID;
std::string ODBCOracleTest::_pwd = ORACLE_PWD;
std::string ODBCOracleTest::_connectString = "DRIVER={" ORACLE_ODBC_DRIVER "};"
"DBQ=" ORACLE_SERVER ":" ORACLE_PORT "/" ORACLE_SID ";"
"UID=" ORACLE_UID ";"
"PWD=" ORACLE_PWD ";"
"TLO=O;" // translation option
"FBS=60000;" // fetch buffer size (bytes), default 60000
"FWC=F;" // force SQL_WCHAR support (T/F), default F
"CSR=F;" // close cursor (T/F), default F
"MDI=T;" // metadata ID (SQL_ATTR_METADATA_ID) (T/F), default T
"MTS=F;" // Microsoft Transaction Server support (T/F)
"DPM=F;" // disable SQLDescribeParam (T/F), default F
"NUM=NLS;" // numeric settings (NLS implies Globalization Support)
"BAM=IfAllSuccessful;" // batch autocommit, (IfAllSuccessful/UpToFirstFailure/AllSuccessful), default IfAllSuccessful
"BTD=F;" // bind timestamp as date (T/F), default F
"RST=T;" // resultsets (T/F), default T
"LOB=T;" // LOB writes (T/F), default T
"FDL=0;" // failover delay (default 10)
"FRC=0;" // failover retry count (default 10)
"QTO=T;" // query timout option (T/F), default T
"FEN=F;" // failover (T/F), default T
"XSM=Default;" // schema field (Default/Database/Owner), default Default
"EXC=F;" // EXEC syntax (T/F), default F
"APA=T;" // thread safety (T/F), default T
"DBA=W;"; // write access (R/W)
const std::string ODBCOracleTest::MULTI_INSERT =
"BEGIN "
"INSERT INTO Test VALUES ('1', 2, 3.5);"
"INSERT INTO Test VALUES ('2', 3, 4.5);"
"INSERT INTO Test VALUES ('3', 4, 5.5);"
"INSERT INTO Test VALUES ('4', 5, 6.5);"
"INSERT INTO Test VALUES ('5', 6, 7.5);"
"END;";
const std::string ODBCOracleTest::MULTI_SELECT =
"{CALL multiResultsProcedure()}";
ODBCOracleTest::ODBCOracleTest(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
}
ODBCOracleTest::~ODBCOracleTest()
{
}
void ODBCOracleTest::testBarebone()
{
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BLOB,"
"Fourth INTEGER,"
"Fifth NUMBER,"
"Sixth TIMESTAMP)";
_pExecutor->bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
_pExecutor->bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
_pExecutor->bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second INTEGER,"
"Third NUMBER)";
*_pSession << "CREATE OR REPLACE "
"PROCEDURE multiResultsProcedure(ret1 OUT SYS_REFCURSOR, "
"ret2 OUT SYS_REFCURSOR,"
"ret3 OUT SYS_REFCURSOR,"
"ret4 OUT SYS_REFCURSOR,"
"ret5 OUT SYS_REFCURSOR) IS "
"BEGIN "
"OPEN ret1 FOR SELECT * FROM Test WHERE First = '1';"
"OPEN ret2 FOR SELECT * FROM Test WHERE First = '2';"
"OPEN ret3 FOR SELECT * FROM Test WHERE First = '3';"
"OPEN ret4 FOR SELECT * FROM Test WHERE First = '4';"
"OPEN ret5 FOR SELECT * FROM Test WHERE First = '5';"
"END multiResultsProcedure;" , now;
_pExecutor->bareboneODBCMultiResultTest(_connectString,
tableCreateString,
SQLExecutor::PB_IMMEDIATE,
SQLExecutor::DE_MANUAL,
MULTI_INSERT,
MULTI_SELECT);
_pExecutor->bareboneODBCMultiResultTest(_connectString,
tableCreateString,
SQLExecutor::PB_IMMEDIATE,
SQLExecutor::DE_BOUND,
MULTI_INSERT,
MULTI_SELECT);
_pExecutor->bareboneODBCMultiResultTest(_connectString,
tableCreateString,
SQLExecutor::PB_AT_EXEC,
SQLExecutor::DE_MANUAL,
MULTI_INSERT,
MULTI_SELECT);
_pExecutor->bareboneODBCMultiResultTest(_connectString,
tableCreateString,
SQLExecutor::PB_AT_EXEC,
SQLExecutor::DE_BOUND,
MULTI_INSERT,
MULTI_SELECT);
}
void ODBCOracleTest::testBLOB()
{
const std::size_t maxFldSize = 1000000;
session().setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
recreatePersonBLOBTable();
try
{
executor().blob(maxFldSize);
fail ("must fail");
}
catch (DataException&)
{
session().setProperty("maxFieldSize", Poco::Any(maxFldSize));
}
for (int i = 0; i < 8;)
{
recreatePersonBLOBTable();
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().blob(maxFldSize);
i += 2;
}
recreatePersonBLOBTable();
try
{
executor().blob(maxFldSize+1);
fail ("must fail");
}
catch (DataException&) { }
}
void ODBCOracleTest::testNull()
{
// test for NOT NULL violation exception
for (int i = 0; i < 8;)
{
recreateNullsTable("NOT NULL");
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().notNulls("HY000");
i += 2;
}
// test for null insertion
for (int i = 0; i < 8;)
{
recreateNullsTable();
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().nulls();
i += 2;
}
}
void ODBCOracleTest::testStoredProcedure()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(outParam OUT NUMBER) IS "
" BEGIN outParam := -1; "
"END storedProcedure;" , now;
int i = 0;
*_pSession << "{call storedProcedure(?)}", out(i), now;
assertTrue (-1 == i);
dropObject("PROCEDURE", "storedProcedure");
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(inParam IN NUMBER, outParam OUT NUMBER) IS "
" BEGIN outParam := inParam*inParam; "
"END storedProcedure;" , now;
i = 2;
int j = 0;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
*_pSession << "DROP PROCEDURE storedProcedure;", now;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(ioParam IN OUT NUMBER) IS "
" BEGIN ioParam := ioParam*ioParam; "
" END storedProcedure;" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(ioParam IN OUT DATE) IS "
" BEGIN ioParam := ioParam + 1; "
" END storedProcedure;" , now;
DateTime dt(1965, 6, 18, 5, 35, 1);
*_pSession << "{call storedProcedure(?)}", io(dt), now;
assertTrue (19 == dt.day());
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
//strings only work with auto-binding
session().setFeature("autoBind", true);
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(inParam IN VARCHAR2, outParam OUT VARCHAR2) IS "
" BEGIN outParam := inParam; "
"END storedProcedure;" , now;
std::string inParam =
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
std::string outParam;
*_pSession << "{call storedProcedure(?,?)}", in(inParam), out(outParam), now;
assertTrue (inParam == outParam);
dropObject("PROCEDURE", "storedProcedure");
}
void ODBCOracleTest::testStoredProcedureAny()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
Any i = 2;
Any j = 0;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(inParam IN NUMBER, outParam OUT NUMBER) IS "
" BEGIN outParam := inParam*inParam; "
"END storedProcedure;" , now;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == AnyCast<int>(j));
*_pSession << "DROP PROCEDURE storedProcedure;", now;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(ioParam IN OUT NUMBER) IS "
" BEGIN ioParam := ioParam*ioParam; "
" END storedProcedure;" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == AnyCast<int>(i));
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCOracleTest::testStoredProcedureDynamicAny()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
DynamicAny i = 2;
DynamicAny j = 0;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(inParam IN NUMBER, outParam OUT NUMBER) IS "
" BEGIN outParam := inParam*inParam; "
"END storedProcedure;" , now;
*_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
*_pSession << "DROP PROCEDURE storedProcedure;", now;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedProcedure(ioParam IN OUT NUMBER) IS "
" BEGIN ioParam := ioParam*ioParam; "
" END storedProcedure;" , now;
i = 2;
*_pSession << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCOracleTest::testCursorStoredProcedure()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
recreatePersonTable();
typedef Tuple<std::string, std::string, std::string, int> Person;
std::vector<Person> people;
people.push_back(Person("Simpson", "Homer", "Springfield", 42));
people.push_back(Person("Simpson", "Bart", "Springfield", 12));
people.push_back(Person("Simpson", "Lisa", "Springfield", 10));
*_pSession << "INSERT INTO Person VALUES (?, ?, ?, ?)", use(people), now;
*_pSession << "CREATE OR REPLACE "
"PROCEDURE storedCursorProcedure(ret OUT SYS_REFCURSOR, ageLimit IN NUMBER) IS "
" BEGIN "
" OPEN ret FOR "
" SELECT * "
" FROM Person "
" WHERE Age < ageLimit "
" ORDER BY Age DESC; "
" END storedCursorProcedure;" , now;
people.clear();
int age = 13;
*_pSession << "{call storedCursorProcedure(?)}", in(age), into(people), now;
assertTrue (2 == people.size());
assertTrue (Person("Simpson", "Bart", "Springfield", 12) == people[0]);
assertTrue (Person("Simpson", "Lisa", "Springfield", 10) == people[1]);
Statement stmt = ((*_pSession << "{call storedCursorProcedure(?)}", in(age), now));
RecordSet rs(stmt);
assertTrue (rs["LastName"] == "Simpson");
assertTrue (rs["FirstName"] == "Bart");
assertTrue (rs["Address"] == "Springfield");
assertTrue (rs["Age"] == 12);
dropObject("TABLE", "Person");
dropObject("PROCEDURE", "storedCursorProcedure");
k += 2;
}
}
void ODBCOracleTest::testStoredFunction()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
try{
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedFunction RETURN NUMBER IS "
" BEGIN return(-1); "
" END storedFunction;" , now;
}catch(StatementException& se) { std::cout << se.toString() << std::endl; }
int i = 0;
*_pSession << "{? = call storedFunction()}", out(i), now;
assertTrue (-1 == i);
dropObject("FUNCTION", "storedFunction");
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedFunction(inParam IN NUMBER) RETURN NUMBER IS "
" BEGIN RETURN(inParam*inParam); "
" END storedFunction;" , now;
i = 2;
int result = 0;
*_pSession << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == result);
dropObject("FUNCTION", "storedFunction");
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedFunction(inParam IN NUMBER, outParam OUT NUMBER) RETURN NUMBER IS "
" BEGIN outParam := inParam*inParam; RETURN(outParam); "
" END storedFunction;" , now;
i = 2;
int j = 0;
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
assertTrue (4 == j);
assertTrue (j == result);
dropObject("FUNCTION", "storedFunction");
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedFunction(param1 IN OUT NUMBER, param2 IN OUT NUMBER) RETURN NUMBER IS "
" temp NUMBER := param1; "
" BEGIN param1 := param2; param2 := temp; RETURN(param1+param2); "
" END storedFunction;" , now;
i = 1;
j = 2;
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
assertTrue (1 == j);
assertTrue (2 == i);
assertTrue (3 == result);
Tuple<int, int> params(1, 2);
assertTrue (1 == params.get<0>());
assertTrue (2 == params.get<1>());
result = 0;
*_pSession << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
assertTrue (1 == params.get<1>());
assertTrue (2 == params.get<0>());
assertTrue (3 == result);
dropObject("FUNCTION", "storedFunction");
k += 2;
}
session().setFeature("autoBind", true);
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedFunction(inParam IN VARCHAR2, outParam OUT VARCHAR2) RETURN VARCHAR2 IS "
" BEGIN outParam := inParam; RETURN outParam;"
"END storedFunction;" , now;
std::string inParam = "123";
std::string outParam;
std::string ret;
*_pSession << "{? = call storedFunction(?,?)}", out(ret), in(inParam), out(outParam), now;
assertTrue ("123" == inParam);
assertTrue (inParam == outParam);
assertTrue (ret == outParam);
dropObject("PROCEDURE", "storedFunction");
}
void ODBCOracleTest::testCursorStoredFunction()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
recreatePersonTable();
typedef Tuple<std::string, std::string, std::string, int> Person;
std::vector<Person> people;
people.push_back(Person("Simpson", "Homer", "Springfield", 42));
people.push_back(Person("Simpson", "Bart", "Springfield", 12));
people.push_back(Person("Simpson", "Lisa", "Springfield", 10));
*_pSession << "INSERT INTO Person VALUES (?, ?, ?, ?)", use(people), now;
*_pSession << "CREATE OR REPLACE "
"FUNCTION storedCursorFunction(ageLimit IN NUMBER) RETURN SYS_REFCURSOR IS "
" ret SYS_REFCURSOR; "
" BEGIN "
" OPEN ret FOR "
" SELECT * "
" FROM Person "
" WHERE Age < ageLimit "
" ORDER BY Age DESC; "
" RETURN ret; "
" END storedCursorFunction;" , now;
people.clear();
int age = 13;
*_pSession << "{call storedCursorFunction(?)}", in(age), into(people), now;
assertTrue (2 == people.size());
assertTrue (Person("Simpson", "Bart", "Springfield", 12) == people[0]);
assertTrue (Person("Simpson", "Lisa", "Springfield", 10) == people[1]);
Statement stmt = ((*_pSession << "{call storedCursorFunction(?)}", in(age), now));
RecordSet rs(stmt);
assertTrue (rs["LastName"] == "Simpson");
assertTrue (rs["FirstName"] == "Bart");
assertTrue (rs["Address"] == "Springfield");
assertTrue (rs["Age"] == 12);
dropObject("TABLE", "Person");
dropObject("FUNCTION", "storedCursorFunction");
k += 2;
}
}
void ODBCOracleTest::testMultipleResults()
{
std::string sql = "CREATE OR REPLACE "
"PROCEDURE multiResultsProcedure(paramAge1 IN NUMBER,"
" paramAge2 IN NUMBER,"
" paramAge3 IN NUMBER,"
" ret1 OUT SYS_REFCURSOR, "
" ret2 OUT SYS_REFCURSOR,"
" ret3 OUT SYS_REFCURSOR) IS "
"BEGIN "
" OPEN ret1 FOR SELECT * FROM Person WHERE Age = paramAge1;"
" OPEN ret2 FOR SELECT Age FROM Person WHERE FirstName = 'Bart';"
" OPEN ret3 FOR SELECT * FROM Person WHERE Age = paramAge2 OR Age = paramAge3 ORDER BY Age;"
"END multiResultsProcedure;";
for (int i = 0; i < 8;)
{
recreatePersonTable();
*_pSession << sql, now;
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().multipleResults("{call multiResultsProcedure(?, ?, ?)}");
i += 2;
}
}
void ODBCOracleTest::testAutoTransaction()
{
Session localSession("ODBC", _connectString);
bool ac = session().getFeature("autoCommit");
int count = 0;
recreateIntsTable();
session().setFeature("autoCommit", true);
session() << "INSERT INTO Strings VALUES (1)", now;
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (1 == count);
session() << "INSERT INTO Strings VALUES (2)", now;
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (2 == count);
session() << "INSERT INTO Strings VALUES (3)", now;
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (3 == count);
session() << "DELETE FROM Strings", now;
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (0 == count);
session().setFeature("autoCommit", false);
try
{
AutoTransaction at(session());
session() << "INSERT INTO Strings VALUES (1)", now;
session() << "INSERT INTO Strings VALUES (2)", now;
session() << "BAD QUERY", now;
} catch (Poco::Exception&) {}
session() << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (0 == count);
AutoTransaction at(session());
session() << "INSERT INTO Strings VALUES (1)", now;
session() << "INSERT INTO Strings VALUES (2)", now;
session() << "INSERT INTO Strings VALUES (3)", now;
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (0 == count);
at.commit();
localSession << "SELECT count(*) FROM Strings", into(count), now;
assertTrue (3 == count);
session().setFeature("autoCommit", ac);
}
void ODBCOracleTest::dropObject(const std::string& type, const std::string& name)
{
try
{
*_pSession << format("DROP %s %s", type, name), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (4043 == it->_nativeError || //ORA-04043 (object does not exist)
942 == it->_nativeError)//ORA-00942 (table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCOracleTest::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR2(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat NUMBER NULL , EmptyDateTime TIMESTAMP NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCOracleTest::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR2(30), FirstName VARCHAR2(30), Address VARCHAR2(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCOracleTest::recreatePersonTupleTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName1 VARCHAR2(30), FirstName1 VARCHAR2(30), Address1 VARCHAR2(30), Age1 INTEGER,"
"LastName2 VARCHAR2(30), FirstName2 VARCHAR2(30), Address2 VARCHAR2(30), Age2 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTupleTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTupleTable()"); }
}
void ODBCOracleTest::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCOracleTest::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCOracleTest::recreatePersonDateTable()
{
dropObject("TABLE", "Person");
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
}
void ODBCOracleTest::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCOracleTest::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCOracleTest::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { *_pSession << "CREATE TABLE Strings (str NUMBER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCOracleTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { *_pSession << "CREATE TABLE Tuples "
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCOracleTest::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 NUMBER(5,2), str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCOracleTest::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { *_pSession << "CREATE TABLE Anys (int0 INTEGER, flt0 NUMBER, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCOracleTest::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r NUMBER %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCOracleTest::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try
{
session() << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
"Second BLOB,"
"Third INTEGER,"
"Fourth NUMBER,"
"Fifth TIMESTAMP)", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
}
void ODBCOracleTest::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR(100),"
"Name VARCHAR(100),"
"ProcessId INTEGER,"
"Thread VARCHAR(100), "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR(100),"
"DateTime TIMESTAMP)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
void ODBCOracleTest::recreateUnicodeTable()
{
#if defined (POCO_ODBC_UNICODE)
dropObject("TABLE", "UnicodeTable");
try { session() << "CREATE TABLE UnicodeTable (str NVARCHAR2(30))", now; }
catch (ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail("recreateUnicodeTable()"); }
catch (StatementException& se){ std::cout << se.toString() << std::endl; fail("recreateUnicodeTable()"); }
#endif
}
CppUnit::Test* ODBCOracleTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");
CppUnit_addTest(pSuite, ODBCOracleTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCOracleTest, testZeroRows);
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexType);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeTuple);
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertList);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertDeque);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCOracleTest, testAffectedRows);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCOracleTest, testLimit);
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCOracleTest, testPrepare);
CppUnit_addTest(pSuite, ODBCOracleTest, testBulk);
CppUnit_addTest(pSuite, ODBCOracleTest, testBulkPerformance);
CppUnit_addTest(pSuite, ODBCOracleTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCOracleTest, testRange);
CppUnit_addTest(pSuite, ODBCOracleTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCOracleTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCOracleTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCOracleTest, testBLOB);
CppUnit_addTest(pSuite, ODBCOracleTest, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCOracleTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCOracleTest, testDate);
CppUnit_addTest(pSuite, ODBCOracleTest, testDateTime);
CppUnit_addTest(pSuite, ODBCOracleTest, testFloat);
CppUnit_addTest(pSuite, ODBCOracleTest, testDouble);
CppUnit_addTest(pSuite, ODBCOracleTest, testTuple);
CppUnit_addTest(pSuite, ODBCOracleTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCOracleTest, testStoredProcedure);
CppUnit_addTest(pSuite, ODBCOracleTest, testCursorStoredProcedure);
CppUnit_addTest(pSuite, ODBCOracleTest, testStoredProcedureAny);
CppUnit_addTest(pSuite, ODBCOracleTest, testStoredProcedureDynamicAny);
CppUnit_addTest(pSuite, ODBCOracleTest, testStoredFunction);
CppUnit_addTest(pSuite, ODBCOracleTest, testCursorStoredFunction);
CppUnit_addTest(pSuite, ODBCOracleTest, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCOracleTest, testFilter);
CppUnit_addTest(pSuite, ODBCOracleTest, testInternalBulkExtraction);
CppUnit_addTest(pSuite, ODBCOracleTest, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCOracleTest, testNull);
CppUnit_addTest(pSuite, ODBCOracleTest, testRowIterator);
CppUnit_addTest(pSuite, ODBCOracleTest, testAsync);
CppUnit_addTest(pSuite, ODBCOracleTest, testAny);
CppUnit_addTest(pSuite, ODBCOracleTest, testDynamicAny);
CppUnit_addTest(pSuite, ODBCOracleTest, testMultipleResults);
CppUnit_addTest(pSuite, ODBCOracleTest, testSQLChannel);
CppUnit_addTest(pSuite, ODBCOracleTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCOracleTest, testAutoTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransactor);
CppUnit_addTest(pSuite, ODBCOracleTest, testNullable);
CppUnit_addTest(pSuite, ODBCOracleTest, testUnicode);
CppUnit_addTest(pSuite, ODBCOracleTest, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,93 @@
//
// ODBCOracleTest.h
//
// Definition of the ODBCOracleTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCOracleTest_INCLUDED
#define ODBCOracleTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
class ODBCOracleTest: public ODBCTest
/// Oracle ODBC test class
/// Tested:
///
/// Driver | DB | OS
/// ------------+-------------------------------+------------------------------------------
/// 10.02.00.01 | Oracle9i Release 9.2.0.4.0 | MS Windows XP Professional x64 v.2003/SP1
/// 10.02.00.01 | Oracle XE Release 10.2.0.1.0 | MS Windows XP Professional x64 v.2003/SP1
/// 11.02.00.02 | Oracle XE Release 11.2.0.2.0 | MS Windows 7 Professional x64 v.2009/SP1
{
public:
ODBCOracleTest(const std::string& name);
~ODBCOracleTest();
void testBareboneODBC();
void testBLOB();
void testMultipleResults();
void testStoredProcedure();
void testCursorStoredProcedure();
void testStoredFunction();
void testCursorStoredFunction();
void testStoredProcedureAny();
void testStoredProcedureDynamicAny();
void testAutoTransaction();
void testNull();
static CppUnit::Test* suite();
private:
static void testBarebone();
void dropObject(const std::string& type, const std::string& name);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonTupleTable();
void recreatePersonBLOBTable();
void recreatePersonDateTable();
void recreatePersonDateTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateMiscTable();
void recreateLogTable();
void recreateUnicodeTable();
static ODBCTest::SessionPtr _pSession;
static ODBCTest::ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _connectString;
static const std::string MULTI_INSERT;
static const std::string MULTI_SELECT;
};
inline void ODBCOracleTest::testBareboneODBC()
{
return testBarebone();
}
#endif // ODBCOracleTest_INCLUDED

View File

@ -0,0 +1,685 @@
//
// ODBCPostgreSQLTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCPostgreSQLTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "ODBCTest.h"
#include "Poco/Format.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
#include "Poco/DateTime.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::DataException;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::Any;
using Poco::AnyCast;
using Poco::DynamicAny;
using Poco::DateTime;
#ifdef POCO_ODBC_USE_MAMMOTH_NG
#define POSTGRESQL_ODBC_DRIVER "Mammoth ODBCng Beta"
#elif defined (POCO_ODBC_UNICODE)
#ifdef POCO_PTR_IS_64_BIT
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode(x64)"
#else
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode"
#endif
#define POSTGRESQL_DSN "PocoDataPgSQLTestW"
#else
#ifdef POCO_PTR_IS_64_BIT
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI(x64)"
#else
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI"
#endif
#define POSTGRESQL_DSN "PocoDataPgSQLTest"
#endif
#if defined(POCO_OS_FAMILY_WINDOWS)
#pragma message ("Using " POSTGRESQL_ODBC_DRIVER " driver.")
#endif
#define POSTGRESQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
#define POSTGRESQL_PORT "5432"
#define POSTGRESQL_DB "postgres"
#define POSTGRESQL_UID "postgres"
#define POSTGRESQL_PWD "poco"
#define POSTGRESQL_VERSION "10"
#ifdef POCO_OS_FAMILY_WINDOWS
const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\pg" POSTGRESQL_VERSION "\\\\lib\\\\";
#else
const std::string ODBCPostgreSQLTest::_libDir = "/usr/local/pgsql/lib/";
#endif
ODBCTest::SessionPtr ODBCPostgreSQLTest::_pSession;
ODBCTest::ExecPtr ODBCPostgreSQLTest::_pExecutor;
std::string ODBCPostgreSQLTest::_driver = POSTGRESQL_ODBC_DRIVER;
std::string ODBCPostgreSQLTest::_dsn = POSTGRESQL_DSN;
std::string ODBCPostgreSQLTest::_uid = POSTGRESQL_UID;
std::string ODBCPostgreSQLTest::_pwd = POSTGRESQL_PWD;
std::string ODBCPostgreSQLTest::_connectString =
"DRIVER=" POSTGRESQL_ODBC_DRIVER ";"
"DATABASE=" POSTGRESQL_DB ";"
"SERVER=" POSTGRESQL_SERVER ";"
"PORT=" POSTGRESQL_PORT ";"
"UID=" POSTGRESQL_UID ";"
"PWD=" POSTGRESQL_PWD ";"
"SSLMODE=prefer;"
"LowerCaseIdentifier=0;"
"UseServerSidePrepare=0;"
"ByteaAsLongVarBinary=1;"
"BI=0;"
"TrueIsMinus1=0;"
"DisallowPremature=0;"
"UpdatableCursors=0;"
"LFConversion=1;"
"CancelAsFreeStmt=0;"
"Parse=0;"
"BoolsAsChar=1;"
"UnknownsAsLongVarchar=0;"
"TextAsLongVarchar=1;"
"UseDeclareFetch=0;"
"Ksqo=1;"
"Optimizer=1;"
"CommLog=0;"
"Debug=0;"
"MaxLongVarcharSize=8190;"
"MaxVarcharSize=254;"
"UnknownSizes=0;"
"Socket=8192;"
"Fetch=100;"
"ConnSettings=;"
"ShowSystemTables=0;"
"RowVersioning=0;"
"ShowOidColumn=0;"
"FakeOidIndex=0;"
"ReadOnly=0;";
ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
}
ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
{
}
void ODBCPostgreSQLTest::testBareboneODBC()
{
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BYTEA,"
"Fourth INTEGER,"
"Fifth FLOAT,"
"Sixth TIMESTAMP)";
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BYTEA,"
"Fourth INTEGER,"
"Fifth FLOAT,"
"Sixth DATE)";
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, false);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, false);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, false);
executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, false);
//neither pSQL ODBC nor Mammoth drivers support multiple results properly
/*
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second INTEGER,"
"Third FLOAT)";
executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
*/
}
void ODBCPostgreSQLTest::testBLOB()
{
const std::size_t maxFldSize = 1000000;
session().setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
recreatePersonBLOBTable();
try
{
executor().blob(maxFldSize);
fail ("must fail");
}
catch (DataException&)
{
session().setProperty("maxFieldSize", Poco::Any(maxFldSize));
}
for (int i = 0; i < 8;)
{
recreatePersonBLOBTable();
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().blob(1000000);
i += 2;
}
}
void ODBCPostgreSQLTest::testStoredFunction()
{
configurePLPgSQL();
std::string func("testStoredFunction()");
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
dropObject("FUNCTION", "storedFunction()");
try
{
session() << "CREATE FUNCTION storedFunction() RETURNS INTEGER AS '"
"BEGIN "
" return -1; "
"END;'"
"LANGUAGE 'plpgsql'", now;
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
int i = 0;
session() << "{? = call storedFunction()}", out(i), now;
assertTrue (-1 == i);
dropObject("FUNCTION", "storedFunction()");
try
{
session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
"BEGIN "
" RETURN $1 * $1; "
"END;'"
"LANGUAGE 'plpgsql'" , now;
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
i = 2;
int result = 0;
session() << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == result);
dropObject("FUNCTION", "storedFunction(INTEGER)");
dropObject("FUNCTION", "storedFunction(TIMESTAMP)");
try
{
session() << "CREATE FUNCTION storedFunction(TIMESTAMP) RETURNS TIMESTAMP AS '"
"BEGIN "
" RETURN $1; "
"END;'"
"LANGUAGE 'plpgsql'" , now;
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
DateTime dtIn(1965, 6, 18, 5, 35, 1);
DateTime dtOut;
session() << "{? = call storedFunction(?)}", out(dtOut), in(dtIn), now;
assertTrue (dtOut == dtIn);
dropObject("FUNCTION", "storedFunction(TIMESTAMP)");
dropObject("FUNCTION", "storedFunction(TEXT, TEXT)");
try
{
session() << "CREATE FUNCTION storedFunction(TEXT,TEXT) RETURNS TEXT AS '"
"BEGIN "
" RETURN $1 || '', '' || $2 || ''!'';"
"END;'"
"LANGUAGE 'plpgsql'" , now;
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
std::string param1 = "Hello";
std::string param2 = "world";
std::string ret;
try
{
session() << "{? = call storedFunction(?,?)}", out(ret), in(param1), in(param2), now;
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
assertTrue (ret == "Hello, world!");
dropObject("FUNCTION", "storedFunction(TEXT, TEXT)");
k += 2;
}
}
void ODBCPostgreSQLTest::testStoredFunctionAny()
{
session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
"BEGIN "
" RETURN $1 * $1; "
"END;'"
"LANGUAGE 'plpgsql'" , now;
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
Any i = 2;
Any result = 0;
session() << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == AnyCast<int>(result));
k += 2;
}
dropObject("FUNCTION", "storedFunction(INTEGER)");
}
void ODBCPostgreSQLTest::testStoredFunctionDynamicAny()
{
session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
"BEGIN "
" RETURN $1 * $1; "
"END;'"
"LANGUAGE 'plpgsql'" , now;
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
DynamicAny i = 2;
DynamicAny result = 0;
session() << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == result);
k += 2;
}
dropObject("FUNCTION", "storedFunction(INTEGER)");
}
void ODBCPostgreSQLTest::configurePLPgSQL()
{
try
{
session() << format("CREATE FUNCTION plpgsql_call_handler () "
"RETURNS OPAQUE "
"AS '%splpgsql.dll' "
"LANGUAGE 'C';", _libDir), now;
session() << "CREATE LANGUAGE 'plpgsql' "
"HANDLER plpgsql_call_handler "
"LANCOMPILER 'PL/pgSQL'", now;
}catch(StatementException& ex)
{
if (1 != ex.diagnostics().nativeError(0))
throw;
}
return;
}
void ODBCPostgreSQLTest::dropObject(const std::string& type, const std::string& name)
{
try
{
session() << format("DROP %s %s", type, name), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (1 == it->_nativeError)//(table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCPostgreSQLTest::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat FLOAT NULL , EmptyDateTime TIMESTAMP NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCPostgreSQLTest::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCPostgreSQLTest::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BYTEA)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCPostgreSQLTest::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCPostgreSQLTest::recreatePersonDateTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
}
void ODBCPostgreSQLTest::recreatePersonTimeTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornTime TIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
}
void ODBCPostgreSQLTest::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCPostgreSQLTest::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCPostgreSQLTest::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCPostgreSQLTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { session() << "CREATE TABLE Tuples "
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCPostgreSQLTest::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { session() << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCPostgreSQLTest::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { session() << "CREATE TABLE Anys (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCPostgreSQLTest::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCPostgreSQLTest::recreateBoolTable()
{
dropObject("TABLE", "BoolTest");
try { session() << "CREATE TABLE BoolTest (b BOOLEAN)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateBoolTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateBoolTable()"); }
}
void ODBCPostgreSQLTest::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try
{
// Mammoth does not bind columns properly
session() << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
"Second BYTEA,"
"Third INTEGER,"
"Fourth FLOAT,"
"Fifth TIMESTAMP)", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
}
void ODBCPostgreSQLTest::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR,"
"Name VARCHAR,"
"ProcessId INTEGER,"
"Thread VARCHAR, "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR,"
"DateTime TIMESTAMP)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
void ODBCPostgreSQLTest::recreateUnicodeTable()
{
#if defined (POCO_ODBC_UNICODE)
dropObject("TABLE", "UnicodeTable");
try { session() << "CREATE TABLE UnicodeTable (str TEXT)", now; }
catch (ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail("recreateUnicodeTable()"); }
catch (StatementException& se){ std::cout << se.toString() << std::endl; fail("recreateUnicodeTable()"); }
#endif
}
CppUnit::Test* ODBCPostgreSQLTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testZeroRows);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertList);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertDeque);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAffectedRows);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimit);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testPrepare);
//On Linux, PostgreSQL driver returns SQL_NEED_DATA on SQLExecute (see ODBCStatementImpl::bindImpl() )
//this behavior is not expected and not handled for automatic binding
#ifdef POCO_OS_FAMILY_WINDOWS
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBulk);
#endif
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBulkPerformance);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRange);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOB);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDate);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTime);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDateTime);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFloat);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDouble);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTuple);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFilter);
//On Linux, PostgreSQL driver returns SQL_NEED_DATA on SQLExecute (see ODBCStatementImpl::bindImpl() )
//this behavior is not expected and not handled for automatic binding
#ifdef POCO_OS_FAMILY_WINDOWS
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalBulkExtraction);
#endif
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunctionAny);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunctionDynamicAny);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNull);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRowIterator);
#ifdef POCO_ODBC_USE_MAMMOTH_NG
// psqlODBC driver returns string for bool fields
// even when field is explicitly cast to boolean,
// so this functionality seems to be untestable with it
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStdVectorBool);
#endif
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAsync);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAny);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDynamicAny);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultipleResults);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLChannel);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
// (postgres bug?)
// local session claims to be capable of reading uncommitted changes,
// but fails to do so
//CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
//CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNullable);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testUnicode);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,96 @@
//
// ODBCPostgreSQLTest.h
//
// Definition of the ODBCPostgreSQLTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCPostgreSQLTest_INCLUDED
#define ODBCPostgreSQLTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
// uncomment to use Mammoth ODBCng driver
//#define POCO_ODBC_USE_MAMMOTH_NG
class ODBCPostgreSQLTest: public ODBCTest
/// PostgreSQL ODBC test class
/// Tested:
///
/// Driver | DB | OS | Driver Manager |Notes
/// ---------------+----------------------+-------------------------------------------+--------------------+--------------------------
/// 07.03.02.60 | PostgreSQL 7.4.6 | MS Windows XP Professional x64 v.2003/SP1 | 3.526.3959.0 | BLOB fails (missing 'lo')
/// 08.01.02.00 | PostgreSQL 8.1.5-1 | MS Windows XP Professional x64 v.2003/SP1 | 3.526.3959.0 |
/// 1:08.01.0200-2 | PostgreSQL 8.1.5-1 | Ubuntu 7.04 (2.6.20-15-generic #2 SMP) | unixODBC 2.2.11.-13|
/// Mammoth ODBCng | | | |
/// (0.99.00.122) | PostgreSQL 8.1.5-1 | MS Windows XP Professional x64 v.2003/SP1 | 3.526.3959.0 |
///
{
public:
ODBCPostgreSQLTest(const std::string& name);
~ODBCPostgreSQLTest();
void testBareboneODBC();
void testBLOB();
void testStoredFunction();
void testStoredFunctionAny();
void testStoredFunctionDynamicAny();
static CppUnit::Test* suite();
private:
void dropObject(const std::string& type, const std::string& name);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTimeTable();
void recreatePersonDateTable();
void recreatePersonTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull="");
void recreateBoolTable();
void recreateMiscTable();
void recreateLogTable();
void recreateUnicodeTable();
void configurePLPgSQL();
/// Configures PL/pgSQL in the database. A reasonable defaults
/// for the interpreter location on WIN32 and POSIX platforms are
/// supplied (see installDir member variable).
/// If these do not work, user must determine the proper location,
/// modify the function and recompile.
/// Alternative is direct database configuration for PL/pgSQL usage.
static const std::string _libDir;
/// Varible determining the location of the library directory
/// on the database installation system.
/// Used to enable PLpgSQL language programmaticaly when
/// it is not enabled.
static SessionPtr _pSession;
static ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _connectString;
};
#endif // ODBCPostgreSQLTest_INCLUDED

View File

@ -0,0 +1,821 @@
//
// ODBCSQLServerTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCSQLServerTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
#include "Poco/Tuple.h"
#include "Poco/DateTime.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::DataException;
using Poco::Data::Statement;
using Poco::Data::RecordSet;
using Poco::Data::CLOB;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::Tuple;
using Poco::Any;
using Poco::AnyCast;
using Poco::DynamicAny;
using Poco::DateTime;
// uncomment to force FreeTDS on Windows
//#define FORCE_FREE_TDS
// uncomment to use native SQL driver
//#define POCO_ODBC_USE_SQL_NATIVE
// FreeTDS version selection guide (from http://www.freetds.org/userguide/choosingtdsprotocol.htm)
// (see #define FREE_TDS_VERSION below)
// Product TDS Version Comment
// ---------------------------------------------------+------------+------------------------------------------------------------
// Sybase before System 10, Microsoft SQL Server 6.x 4.2 Still works with all products, subject to its limitations.
// Sybase System 10 and above 5.0 Still the most current protocol used by Sybase.
// Sybase System SQL Anywhere 5.0 only Originally Watcom SQL Server, a completely separate codebase.
// Our best information is that SQL Anywhere first supported TDS
// in version 5.5.03 using the OpenServer Gateway (OSG), and native
// TDS 5.0 support arrived with version 6.0.
// Microsoft SQL Server 7.0 7.0 Includes support for the extended datatypes in SQL Server 7.0
// (such as char/varchar fields of more than 255 characters), and
// support for Unicode.
// Microsoft SQL Server 2000 8.0 Include support for bigint (64 bit integers), variant and collation
// on all fields. variant is not supported; collation is not widely used.
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(FORCE_FREE_TDS)
#ifdef POCO_ODBC_USE_SQL_NATIVE
#define MS_SQL_SERVER_ODBC_DRIVER "SQL Server Native Client 10.0"
#else
#define MS_SQL_SERVER_ODBC_DRIVER "SQL Server"
#endif
#pragma message ("Using " MS_SQL_SERVER_ODBC_DRIVER " driver")
#else
#define MS_SQL_SERVER_ODBC_DRIVER "FreeTDS"
#define FREE_TDS_VERSION "8.0"
#if defined(POCO_OS_FAMILY_WINDOWS)
#pragma message ("Using " MS_SQL_SERVER_ODBC_DRIVER " driver, version " FREE_TDS_VERSION)
#endif
#endif
#define MS_SQL_SERVER_DSN "PocoDataSQLServerTest"
#define MS_SQL_SERVER_SERVER POCO_ODBC_TEST_DATABASE_SERVER "\\SQLEXPRESS"
#define MS_SQL_SERVER_PORT "1433"
#define MS_SQL_SERVER_DB "poco"
#define MS_SQL_SERVER_UID "poco"
#define MS_SQL_SERVER_PWD "poco"
ODBCTest::SessionPtr ODBCSQLServerTest::_pSession;
ODBCTest::ExecPtr ODBCSQLServerTest::_pExecutor;
std::string ODBCSQLServerTest::_driver = MS_SQL_SERVER_ODBC_DRIVER;
std::string ODBCSQLServerTest::_dsn = MS_SQL_SERVER_DSN;
std::string ODBCSQLServerTest::_uid = MS_SQL_SERVER_UID;
std::string ODBCSQLServerTest::_pwd = MS_SQL_SERVER_PWD;
std::string ODBCSQLServerTest::_db = MS_SQL_SERVER_DB;
std::string ODBCSQLServerTest::_connectString = "DRIVER=" MS_SQL_SERVER_ODBC_DRIVER ";"
"UID=" MS_SQL_SERVER_UID ";"
"PWD=" MS_SQL_SERVER_PWD ";"
"DATABASE=" MS_SQL_SERVER_DB ";"
"SERVER=" MS_SQL_SERVER_SERVER ";"
"PORT=" MS_SQL_SERVER_PORT ";"
#ifdef FREE_TDS_VERSION
"TDS_Version=" FREE_TDS_VERSION ";"
#endif
;
ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
}
ODBCSQLServerTest::~ODBCSQLServerTest()
{
}
void ODBCSQLServerTest::testBareboneODBC()
{
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third VARBINARY(30),"
"Fourth INTEGER,"
"Fifth FLOAT,"
"Sixth DATETIME)";
executor().bareboneODBCTest(dbConnString(), tableCreateString,
SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, true, "CONVERT(VARBINARY(30),?)");
executor().bareboneODBCTest(dbConnString(), tableCreateString,
SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, true, "CONVERT(VARBINARY(30),?)");
executor().bareboneODBCTest(dbConnString(), tableCreateString,
SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, true, "CONVERT(VARBINARY(30),?)");
executor().bareboneODBCTest(dbConnString(), tableCreateString,
SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, true, "CONVERT(VARBINARY(30),?)");
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second INTEGER,"
"Third FLOAT)";
executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
}
void ODBCSQLServerTest::testBLOB()
{
const std::size_t maxFldSize = 250000;
session().setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
recreatePersonBLOBTable();
try
{
executor().blob(maxFldSize, "CONVERT(VARBINARY(MAX),?)");
fail ("must fail");
}
catch (DataException&)
{
session().setProperty("maxFieldSize", Poco::Any(maxFldSize));
}
for (int i = 0; i < 8;)
{
recreatePersonBLOBTable();
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().blob(maxFldSize, "CONVERT(VARBINARY(MAX),?)");
i += 2;
}
recreatePersonBLOBTable();
try
{
executor().blob(maxFldSize+1, "CONVERT(VARBINARY(MAX),?)");
fail ("must fail");
}
catch (DataException&) { }
}
void ODBCSQLServerTest::testNull()
{
// test for NOT NULL violation exception
for (int i = 0; i < 8;)
{
recreateNullsTable("NOT NULL");
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().notNulls("23000");
i += 2;
}
// test for null insertion
for (int i = 0; i < 8;)
{
recreateNullsTable();
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
executor().nulls();
i += 2;
}
}
void ODBCSQLServerTest::testBulk()
{
if (!_pSession) fail ("Test not available.");
_pSession->setFeature("autoBind", true);
_pSession->setFeature("autoExtract", true);
recreateMiscTable();
_pExecutor->doBulkWithBool<std::vector<int>,
std::vector<std::string>,
std::vector<CLOB>,
std::vector<double>,
std::vector<DateTime>,
std::vector<bool> >(100, "CONVERT(VARBINARY(30),?)");
recreateMiscTable();
_pExecutor->doBulkWithBool<std::deque<int>,
std::deque<std::string>,
std::deque<CLOB>,
std::deque<double>,
std::deque<DateTime>,
std::deque<bool> >(100, "CONVERT(VARBINARY(30),?)");
recreateMiscTable();
_pExecutor->doBulkWithBool<std::list<int>,
std::list<std::string>,
std::list<CLOB>,
std::list<double>,
std::list<DateTime>,
std::list<bool> >(100, "CONVERT(VARBINARY(30),?)");
}
void ODBCSQLServerTest::testStoredProcedure()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
dropObject("PROCEDURE", "storedProcedure");
session() << "CREATE PROCEDURE storedProcedure(@outParam int OUTPUT) AS "
"BEGIN "
"SET @outParam = -1; "
"END;"
, now;
int i = 0;
session() << "{call storedProcedure(?)}", out(i), now;
assertTrue (-1 == i);
dropObject("PROCEDURE", "storedProcedure");
session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
"BEGIN "
"SET @outParam = @inParam*@inParam; "
"END;"
, now;
i = 2;
int j = 0;
session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
dropObject("PROCEDURE", "storedProcedure");
session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
"BEGIN "
"SET @ioParam = @ioParam*@ioParam; "
"END;"
, now;
i = 2;
session() << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
session() << "CREATE PROCEDURE storedProcedure(@ioParam DATETIME OUTPUT) AS "
"BEGIN "
" SET @ioParam = @ioParam + 1; "
"END;" , now;
DateTime dt(1965, 6, 18, 5, 35, 1);
session() << "{call storedProcedure(?)}", io(dt), now;
assertTrue (19 == dt.day());
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
/*TODO - currently fails with following error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid parameter
2 (''): Data type 0x23 is a deprecated large object, or LOB, but is marked as output parameter.
Deprecated types are not supported as output parameters. Use current large object types instead.
session().setFeature("autoBind", true);
session() << "CREATE PROCEDURE storedProcedure(@inParam VARCHAR(MAX), @outParam VARCHAR(MAX) OUTPUT) AS "
"BEGIN "
"SET @outParam = @inParam; "
"END;"
, now;
std::string inParam = "123";
std::string outParam;
try{
session() << "{call storedProcedure(?, ?)}", in(inParam), out(outParam), now;
}catch(StatementException& ex){std::cout << ex.toString();}
assertTrue (outParam == inParam);
dropObject("PROCEDURE", "storedProcedure");
*/
}
void ODBCSQLServerTest::testCursorStoredProcedure()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
recreatePersonTable();
typedef Tuple<std::string, std::string, std::string, int> Person;
std::vector<Person> people;
people.push_back(Person("Simpson", "Homer", "Springfield", 42));
people.push_back(Person("Simpson", "Bart", "Springfield", 12));
people.push_back(Person("Simpson", "Lisa", "Springfield", 10));
session() << "INSERT INTO Person VALUES (?, ?, ?, ?)", use(people), now;
dropObject("PROCEDURE", "storedCursorProcedure");
session() << "CREATE PROCEDURE storedCursorProcedure(@ageLimit int) AS "
"BEGIN "
" SELECT * "
" FROM Person "
" WHERE Age < @ageLimit "
" ORDER BY Age DESC; "
"END;"
, now;
people.clear();
int age = 13;
session() << "{call storedCursorProcedure(?)}", in(age), into(people), now;
assertTrue (2 == people.size());
assertTrue (Person("Simpson", "Bart", "Springfield", 12) == people[0]);
assertTrue (Person("Simpson", "Lisa", "Springfield", 10) == people[1]);
Statement stmt = ((session() << "{call storedCursorProcedure(?)}", in(age), now));
RecordSet rs(stmt);
assertTrue (rs["LastName"] == "Simpson");
assertTrue (rs["FirstName"] == "Bart");
assertTrue (rs["Address"] == "Springfield");
assertTrue (rs["Age"] == 12);
dropObject("TABLE", "Person");
dropObject("PROCEDURE", "storedCursorProcedure");
k += 2;
}
}
void ODBCSQLServerTest::testStoredProcedureAny()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
Any i = 2;
Any j = 0;
session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
"BEGIN "
"SET @outParam = @inParam*@inParam; "
"END;"
, now;
session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == AnyCast<int>(j));
session() << "DROP PROCEDURE storedProcedure;", now;
session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
"BEGIN "
"SET @ioParam = @ioParam*@ioParam; "
"END;"
, now;
i = 2;
session() << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == AnyCast<int>(i));
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCSQLServerTest::testStoredProcedureDynamicAny()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
DynamicAny i = 2;
DynamicAny j = 0;
session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
"BEGIN "
"SET @outParam = @inParam*@inParam; "
"END;"
, now;
session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
assertTrue (4 == j);
session() << "DROP PROCEDURE storedProcedure;", now;
session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
"BEGIN "
"SET @ioParam = @ioParam*@ioParam; "
"END;"
, now;
i = 2;
session() << "{call storedProcedure(?)}", io(i), now;
assertTrue (4 == i);
dropObject("PROCEDURE", "storedProcedure");
k += 2;
}
}
void ODBCSQLServerTest::testStoredFunction()
{
for (int k = 0; k < 8;)
{
session().setFeature("autoBind", bindValue(k));
session().setFeature("autoExtract", bindValue(k+1));
dropObject("PROCEDURE", "storedFunction");
session() << "CREATE PROCEDURE storedFunction AS "
"BEGIN "
"DECLARE @retVal int;"
"SET @retVal = -1;"
"RETURN @retVal;"
"END;"
, now;
int i = 0;
session() << "{? = call storedFunction}", out(i), now;
assertTrue (-1 == i);
dropObject("PROCEDURE", "storedFunction");
session() << "CREATE PROCEDURE storedFunction(@inParam int) AS "
"BEGIN "
"RETURN @inParam*@inParam;"
"END;"
, now;
i = 2;
int result = 0;
session() << "{? = call storedFunction(?)}", out(result), in(i), now;
assertTrue (4 == result);
dropObject("PROCEDURE", "storedFunction");
session() << "CREATE PROCEDURE storedFunction(@inParam int, @outParam int OUTPUT) AS "
"BEGIN "
"SET @outParam = @inParam*@inParam;"
"RETURN @outParam;"
"END"
, now;
i = 2;
int j = 0;
result = 0;
session() << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
assertTrue (4 == j);
assertTrue (j == result);
dropObject("PROCEDURE", "storedFunction");
session() << "CREATE PROCEDURE storedFunction(@param1 int OUTPUT,@param2 int OUTPUT) AS "
"BEGIN "
"DECLARE @temp int; "
"SET @temp = @param1;"
"SET @param1 = @param2;"
"SET @param2 = @temp;"
"RETURN @param1 + @param2; "
"END"
, now;
i = 1;
j = 2;
result = 0;
session() << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
assertTrue (1 == j);
assertTrue (2 == i);
assertTrue (3 == result);
Tuple<int, int> params(1, 2);
assertTrue (1 == params.get<0>());
assertTrue (2 == params.get<1>());
result = 0;
session() << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
assertTrue (1 == params.get<1>());
assertTrue (2 == params.get<0>());
assertTrue (3 == result);
dropObject("PROCEDURE", "storedFunction");
k += 2;
}
}
void ODBCSQLServerTest::dropObject(const std::string& type, const std::string& name)
{
try
{
session() << format("DROP %s %s", type, name), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (3701 == it->_nativeError)//(table does not exist)
{
ignoreError = true;
break;
}
}
if (!ignoreError) throw;
}
}
void ODBCSQLServerTest::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat FLOAT NULL , EmptyDateTime DATETIME NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCSQLServerTest::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCSQLServerTest::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image VARBINARY(MAX))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCSQLServerTest::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born DATETIME)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCSQLServerTest::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCSQLServerTest::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCSQLServerTest::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str FLOAT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCSQLServerTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { session() << "CREATE TABLE Tuples "
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCSQLServerTest::recreateVectorTable()
{
dropObject("TABLE", "Vector");
try { session() << "CREATE TABLE Vector (i0 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorTable()"); }
}
void ODBCSQLServerTest::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { session() << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCSQLServerTest::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { session() << "CREATE TABLE Anys (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCSQLServerTest::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCSQLServerTest::recreateBoolTable()
{
dropObject("TABLE", "BoolTest");
try { session() << "CREATE TABLE BoolTest (b BIT)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateBoolTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateBoolTable()"); }
}
void ODBCSQLServerTest::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try
{
session() << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
"Second VARBINARY(30),"
"Third INTEGER,"
"Fourth FLOAT,"
"Fifth DATETIME,"
"Sixth BIT)", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
}
void ODBCSQLServerTest::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR(max),"
"Name VARCHAR(max),"
"ProcessId INTEGER,"
"Thread VARCHAR(max), "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR(max),"
"DateTime DATETIME)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
void ODBCSQLServerTest::recreateUnicodeTable()
{
#if defined (POCO_ODBC_UNICODE)
dropObject("TABLE", "UnicodeTable");
try { session() << "CREATE TABLE UnicodeTable (str NVARCHAR(30))", now; }
catch (ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail("recreateUnicodeTable()"); }
catch (StatementException& se){ std::cout << se.toString() << std::endl; fail("recreateUnicodeTable()"); }
#endif
}
CppUnit::Test* ODBCSQLServerTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString, _db)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testZeroRows);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexType);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertList);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertDeque);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testAffectedRows);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimit);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testPrepare);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBulk);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBulkPerformance);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testRange);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOB);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDateTime);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testFloat);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDouble);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTuple);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedure);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testCursorStoredProcedure);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedureAny);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedureDynamicAny);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredFunction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testFilter);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalBulkExtraction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testNull);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testRowIterator);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testStdVectorBool);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testAsync);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testAny);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDynamicAny);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultipleResults);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLChannel);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testNullable);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testUnicode);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,88 @@
//
// ODBCSQLServerTest.h
//
// Definition of the ODBCSQLServerTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCSQLServerTest_INCLUDED
#define ODBCSQLServerTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
// uncomment to use native SQL Server ODBC driver
// #define POCO_ODBC_USE_SQL_NATIVE
class ODBCSQLServerTest: public ODBCTest
/// SQLServer ODBC test class
/// Tested:
///
/// Driver | DB | OS
/// --------------------+-----------------------------------+------------------------------------------
/// 2000.86.1830.00 | SQL Server Express 9.0.2047 | MS Windows XP Professional x64 v.2003/SP1
/// 2005.90.2047.00 | SQL Server Express 9.0.2047 | MS Windows XP Professional x64 v.2003/SP1
/// 2009.100.1600.01 | SQL Server Express 10.50.1600.1 | MS Windows XP Professional x64 v.2003/SP1
///
{
public:
ODBCSQLServerTest(const std::string& name);
~ODBCSQLServerTest();
void testBareboneODBC();
void testBLOB();
void testNull();
void testBulk();
void testStoredProcedure();
void testCursorStoredProcedure();
void testStoredProcedureAny();
void testStoredProcedureDynamicAny();
void testStoredFunction();
static CppUnit::Test* suite();
private:
void dropObject(const std::string& type, const std::string& name);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTimeTable();
void recreatePersonDateTable() { /* no-op */ };
void recreatePersonTimeTable() { /* no-op */ };
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateBoolTable();
void recreateMiscTable();
void recreateLogTable();
void recreateUnicodeTable();
static SessionPtr _pSession;
static ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _db;
static std::string _connectString;
};
#endif // ODBCSQLServerTest_INCLUDED

View File

@ -0,0 +1,397 @@
//
// ODBCSQLiteTest.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCSQLiteTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Exception.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include <sqltypes.h>
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ConnectionException;
using Poco::Data::ODBC::StatementException;
using Poco::Data::ODBC::StatementDiagnostics;
using Poco::format;
using Poco::NotFoundException;
#define SQLITE_ODBC_DRIVER "SQLite3 ODBC Driver"
#define SQLITE_DSN "PocoDataSQLiteTest"
#define SQLITE_DB "dummy.db"
ODBCTest::SessionPtr ODBCSQLiteTest::_pSession;
ODBCTest::ExecPtr ODBCSQLiteTest::_pExecutor;
std::string ODBCSQLiteTest::_driver = SQLITE_ODBC_DRIVER;
std::string ODBCSQLiteTest::_dsn = SQLITE_DSN;
std::string ODBCSQLiteTest::_uid = "";
std::string ODBCSQLiteTest::_pwd = "";
std::string ODBCSQLiteTest::_connectString = "Driver=" SQLITE_ODBC_DRIVER
";Database=" SQLITE_DB ";";
ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
{
}
ODBCSQLiteTest::~ODBCSQLiteTest()
{
}
void ODBCSQLiteTest::testBareboneODBC()
{
std::string tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BLOB,"
"Fourth INTEGER,"
"Fifth REAL,"
"Sixth TIMESTAMP)";
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BLOB,"
"Fourth INTEGER,"
"Fifth REAL,"
"Sixth DATETIME)";
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
tableCreateString = "CREATE TABLE Test "
"(First VARCHAR(30),"
"Second VARCHAR(30),"
"Third BLOB,"
"Fourth INTEGER,"
"Fifth REAL,"
"Sixth DATE)";
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
}
void ODBCSQLiteTest::testAffectedRows()
{
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreateStringsTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
// see SQLiteStatementImpl::affectedRows() documentation for explanation
// why "WHERE 1" is necessary here
_pExecutor->affectedRows("WHERE 1");
i += 2;
}
}
void ODBCSQLiteTest::testNull()
{
if (!_pSession) fail ("Test not available.");
// test for NOT NULL violation exception
for (int i = 0; i < 8;)
{
recreateNullsTable("NOT NULL");
session().setFeature("autoBind", bindValue(i));
session().setFeature("autoExtract", bindValue(i+1));
_pExecutor->notNulls("HY000");
i += 2;
}
}
void ODBCSQLiteTest::dropObject(const std::string& type, const std::string& name)
{
try
{
session() << format("DROP %s %s", type, name), now;
}
catch (StatementException& ex)
{
bool ignoreError = false;
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
StatementDiagnostics::Iterator it = flds.begin();
for (; it != flds.end(); ++it)
{
if (1 == it->_nativeError)//(no such table)
{
ignoreError = true;
break;
}
}
if (!ignoreError)
{
std::cout << ex.toString() << std::endl;
throw;
}
}
}
void ODBCSQLiteTest::recreateNullableTable()
{
dropObject("TABLE", "NullableTest");
try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat REAL NULL , EmptyDateTime TIMESTAMP NULL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCSQLiteTest::recreatePersonTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
}
void ODBCSQLiteTest::recreatePersonBLOBTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
}
void ODBCSQLiteTest::recreatePersonDateTimeTable()
{
dropObject("TABLE", "Person");
try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
}
void ODBCSQLiteTest::recreateIntsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
}
void ODBCSQLiteTest::recreateStringsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str VARCHAR(30))", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
}
void ODBCSQLiteTest::recreateFloatsTable()
{
dropObject("TABLE", "Strings");
try { session() << "CREATE TABLE Strings (str REAL)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
}
void ODBCSQLiteTest::recreateTuplesTable()
{
dropObject("TABLE", "Tuples");
try { session() << "CREATE TABLE Tuples "
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
}
void ODBCSQLiteTest::recreateVectorsTable()
{
dropObject("TABLE", "Vectors");
try { session() << "CREATE TABLE Vectors (int0 INTEGER, flt0 REAL, str0 VARCHAR)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
}
void ODBCSQLiteTest::recreateAnysTable()
{
dropObject("TABLE", "Anys");
try { session() << "CREATE TABLE Anys (int0 INTEGER, flt0 REAL, str0 VARCHAR)", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
}
void ODBCSQLiteTest::recreateNullsTable(const std::string& notNull)
{
dropObject("TABLE", "NullTest");
try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r REAL %s, v VARCHAR(30) %s)",
notNull,
notNull,
notNull), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
void ODBCSQLiteTest::recreateMiscTable()
{
dropObject("TABLE", "MiscTest");
try
{
// SQLite fails with BLOB bulk operations
session() << "CREATE TABLE MiscTest "
"(First VARCHAR(30),"
//"Second BLOB,"
"Third INTEGER,"
"Fourth REAL,"
"Fifth DATETIME)", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
}
void ODBCSQLiteTest::recreateLogTable()
{
dropObject("TABLE", "T_POCO_LOG");
dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
try
{
std::string sql = "CREATE TABLE %s "
"(Source VARCHAR,"
"Name VARCHAR,"
"ProcessId INTEGER,"
"Thread VARCHAR, "
"ThreadId INTEGER,"
"Priority INTEGER,"
"Text VARCHAR,"
"DateTime DATETIME)";
session() << sql, "T_POCO_LOG", now;
session() << sql, "T_POCO_LOG_ARCHIVE", now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
}
CppUnit::Test* ODBCSQLiteTest::suite()
{
if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
{
std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBareboneODBC);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testZeroRows);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccess);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexType);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSharedPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testAutoPtrComplexTypeVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessList);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeList);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertList);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyList);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessDeque);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeDeque);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertDeque);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyDeque);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testAffectedRows);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulk);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulkVec);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimit);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitOnce);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitPrepare);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitZero);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testPrepare);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetSimple);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplex);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplexUnique);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetSimple);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetComplex);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplex);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplexUnique);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiMapComplex);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingle);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleStep);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleFail);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitOk);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitFail);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedLimits);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedIllegalLimits);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testRange);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testIllegalRange);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSingleSelect);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testEmptyDB);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOB);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOBContainer);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOBStmt);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testDateTime);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testFloat);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testDouble);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTuple);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTupleVector);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInternalExtraction);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testFilter);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInternalStorageType);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testNull);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testRowIterator);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testAsync);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testAny);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testDynamicAny);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSQLChannel);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testReconnect);
return pSuite;
}
return 0;
}

View File

@ -0,0 +1,65 @@
//
// ODBCSQLiteTest.h
//
// Definition of the ODBCSQLiteTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCSQLiteTest_INCLUDED
#define ODBCSQLiteTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "ODBCTest.h"
class ODBCSQLiteTest: public ODBCTest
/// SQLite3 ODBC test class
/// Tested:
///
/// Driver | DB | OS
/// ------------+---------------+------------------------------------------
/// 00.70.00.00 | SQLite 3.* | MS Windows XP Professional x64 v.2003/SP1
{
public:
ODBCSQLiteTest(const std::string& name);
~ODBCSQLiteTest();
void testBareboneODBC();
void testAffectedRows();
void testNull();
static CppUnit::Test* suite();
private:
void dropObject(const std::string& type, const std::string& name);
void recreateNullableTable();
void recreatePersonTable();
void recreatePersonBLOBTable();
void recreatePersonDateTimeTable();
void recreateStringsTable();
void recreateIntsTable();
void recreateFloatsTable();
void recreateTuplesTable();
void recreateVectorsTable();
void recreateAnysTable();
void recreateNullsTable(const std::string& notNull = "");
void recreateMiscTable();
void recreateLogTable();
static ODBCTest::SessionPtr _pSession;
static ODBCTest::ExecPtr _pExecutor;
static std::string _driver;
static std::string _dsn;
static std::string _uid;
static std::string _pwd;
static std::string _connectString;
};
#endif // ODBCSQLiteTest_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,413 @@
//
// ODBCTest.h
//
// Definition of the ODBCTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCTest_INCLUDED
#define ODBCTest_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "CppUnit/TestCase.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/SharedPtr.h"
#include "Poco/Exception.h"
#include "SQLExecutor.h"
#define POCO_ODBC_TEST_DATABASE_SERVER "localhost"
class ODBCTest: public CppUnit::TestCase
{
public:
typedef Poco::SharedPtr<Poco::Data::Session> SessionPtr;
typedef Poco::SharedPtr<SQLExecutor> ExecPtr;
ODBCTest(const std::string& name,
SessionPtr pSession,
ExecPtr pExecutor,
std::string& rDSN,
std::string& rUID,
std::string& rPwd,
std::string& rConnectString);
~ODBCTest();
virtual void setUp();
virtual void tearDown();
virtual void testBareboneODBC() = 0;
virtual void testZeroRows();
virtual void testSimpleAccess();
virtual void testComplexType();
virtual void testComplexTypeTuple();
virtual void testSimpleAccessVector();
virtual void testComplexTypeVector();
virtual void testSharedPtrComplexTypeVector();
virtual void testAutoPtrComplexTypeVector();
virtual void testInsertVector();
virtual void testInsertEmptyVector();
virtual void testSimpleAccessList();
virtual void testComplexTypeList();
virtual void testInsertList();
virtual void testInsertEmptyList();
virtual void testSimpleAccessDeque();
virtual void testComplexTypeDeque();
virtual void testInsertDeque();
virtual void testInsertEmptyDeque();
virtual void testAffectedRows();
virtual void testInsertSingleBulk();
virtual void testInsertSingleBulkVec();
virtual void testLimit();
virtual void testLimitOnce();
virtual void testLimitPrepare();
virtual void testLimitZero();
virtual void testPrepare();
virtual void testBulk();
virtual void testBulkPerformance();
virtual void testSetSimple();
virtual void testSetComplex();
virtual void testSetComplexUnique();
virtual void testMultiSetSimple();
virtual void testMultiSetComplex();
virtual void testMapComplex();
virtual void testMapComplexUnique();
virtual void testMultiMapComplex();
virtual void testSelectIntoSingle();
virtual void testSelectIntoSingleStep();
virtual void testSelectIntoSingleFail();
virtual void testLowerLimitOk();
virtual void testLowerLimitFail();
virtual void testCombinedLimits();
virtual void testCombinedIllegalLimits();
virtual void testRange();
virtual void testIllegalRange();
virtual void testSingleSelect();
virtual void testEmptyDB();
virtual void testBLOB();
virtual void testBLOBContainer();
virtual void testBLOBStmt();
virtual void testDateTime();
virtual void testDate();
virtual void testTime();
virtual void testFloat();
virtual void testDouble();
virtual void testTuple();
virtual void testTupleVector();
virtual void testInternalExtraction();
virtual void testFilter();
virtual void testInternalBulkExtraction();
virtual void testInternalStorageType();
virtual void testStoredProcedure();
virtual void testStoredProcedureAny();
virtual void testStoredProcedureDynamicAny();
virtual void testStoredFunction();
virtual void testStoredFunctionAny();
virtual void testStoredFunctionDynamicAny();
virtual void testNull();
virtual void testRowIterator();
virtual void testStdVectorBool();
virtual void testAsync();
virtual void testAny();
virtual void testDynamicAny();
virtual void testMultipleResults();
virtual void testSQLChannel();
virtual void testSQLLogger();
virtual void testSessionTransaction();
virtual void testTransaction();
virtual void testTransactor();
virtual void testNullable();
virtual void testUnicode();
virtual void testReconnect();
protected:
typedef Poco::Data::ODBC::Utility::DriverMap Drivers;
virtual void dropObject(const std::string& type, const std::string& name);
virtual void recreateNullableTable();
virtual void recreatePersonTable();
virtual void recreatePersonTupleTable();
virtual void recreatePersonBLOBTable();
virtual void recreatePersonDateTimeTable();
virtual void recreatePersonDateTable();
virtual void recreatePersonTimeTable();
virtual void recreateStringsTable();
virtual void recreateIntsTable();
virtual void recreateFloatsTable();
virtual void recreateTuplesTable();
virtual void recreateVectorsTable();
virtual void recreateAnysTable();
virtual void recreateNullsTable(const std::string& notNull="");
virtual void recreateBoolTable();
virtual void recreateMiscTable();
virtual void recreateLogTable();
virtual void recreateUnicodeTable();
static SessionPtr init(const std::string& driver,
std::string& dsn,
std::string& uid,
std::string& pwd,
std::string& dbConnString,
const std::string& db = "");
static bool canConnect(const std::string& driver,
std::string& dsn,
std::string& uid,
std::string& pwd,
std::string& dbConnString,
const std::string& db = "");
bool bindValue(int i);
Poco::Data::Session& session();
SQLExecutor& executor();
const std::string& dsn();
const std::string& uid();
const std::string& pwd();
const std::string& dbConnString();
private:
static Drivers _drivers;
static const bool _bindValues[8];
SessionPtr _pSession;
ExecPtr _pExecutor;
std::string& _rDSN;
std::string& _rUID;
std::string& _rPwd;
std::string& _rConnectString;
};
//
// inlines
//
inline void ODBCTest::testStoredProcedure()
{
throw Poco::NotImplementedException("ODBCTest::testStoredProcedure()");
}
inline void ODBCTest::testStoredProcedureAny()
{
throw Poco::NotImplementedException("ODBCTest::testStoredProcedureAny()");
}
inline void ODBCTest::testStoredProcedureDynamicAny()
{
throw Poco::NotImplementedException("ODBCTest::testStoredProcedureDynamicAny()");
}
inline void ODBCTest::testStoredFunction()
{
throw Poco::NotImplementedException("ODBCTest::testStoredFunction()");
}
inline void ODBCTest::testStoredFunctionAny()
{
throw Poco::NotImplementedException("ODBCTest::testStoredFunctionAny()");
}
inline void ODBCTest::testStoredFunctionDynamicAny()
{
throw Poco::NotImplementedException("ODBCTest::testStoredFunctionDynamicAny()");
}
inline void ODBCTest::dropObject(const std::string& type, const std::string& name)
{
throw Poco::NotImplementedException("ODBCTest::dropObject()");
}
inline void ODBCTest::recreateNullableTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateNullableTable()");
}
inline void ODBCTest::recreatePersonTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonTable()");
}
inline void ODBCTest::recreatePersonTupleTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonTupleTable()");
}
inline void ODBCTest::recreatePersonBLOBTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonBLOBTable()");
}
inline void ODBCTest::recreatePersonDateTimeTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonDateTimeTable()");
}
inline void ODBCTest::recreatePersonDateTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonDateTable()");
}
inline void ODBCTest::recreatePersonTimeTable()
{
throw Poco::NotImplementedException("ODBCTest::recreatePersonTimeTable()");
}
inline void ODBCTest::recreateStringsTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateStringsTable()");
}
inline void ODBCTest::recreateIntsTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateIntsTable()");
}
inline void ODBCTest::recreateFloatsTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateFloatsTable()");
}
inline void ODBCTest::recreateTuplesTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateTuplesTable()");
}
inline void ODBCTest::recreateVectorsTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateVectorsTable()");
}
inline void ODBCTest::recreateAnysTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateAnysTable()");
}
inline void ODBCTest::recreateNullsTable(const std::string&)
{
throw Poco::NotImplementedException("ODBCTest::recreateNullsTable()");
}
inline void ODBCTest::recreateBoolTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateBoolTable()");
}
inline void ODBCTest::recreateMiscTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateMiscTable()");
}
inline void ODBCTest::recreateLogTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateLogTable()");
}
inline void ODBCTest::recreateUnicodeTable()
{
throw Poco::NotImplementedException("ODBCTest::recreateUnicodeTable()");
}
inline bool ODBCTest::bindValue(int i)
{
poco_assert (i < 8);
return _bindValues[i];
}
inline Poco::Data::Session& ODBCTest::session()
{
poco_check_ptr (_pSession);
return *_pSession;
}
inline SQLExecutor& ODBCTest::executor()
{
poco_check_ptr (_pExecutor);
return *_pExecutor;
}
inline const std::string& ODBCTest::dsn()
{
return _rDSN;
}
inline const std::string& ODBCTest::uid()
{
return _rUID;
}
inline const std::string& ODBCTest::pwd()
{
return _rPwd;
}
inline const std::string& ODBCTest::dbConnString()
{
return _rConnectString;
}
#endif // ODBCTest_INCLUDED

View File

@ -0,0 +1,59 @@
//
// ODBCTestSuite.cpp
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "ODBCTestSuite.h"
#include "ODBCDB2Test.h"
#include "ODBCMySQLTest.h"
#include "ODBCOracleTest.h"
#include "ODBCPostgreSQLTest.h"
#include "ODBCSQLiteTest.h"
#if defined(POCO_OS_FAMILY_WINDOWS)
#include "ODBCAccessTest.h"
#endif
#include "ODBCSQLServerTest.h"
CppUnit::Test* ODBCTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCTestSuite");
// WARNING!
// On Win XP Pro, the PostgreSQL connection fails if attempted after DB2 w/ following error:
//
// sqlState="IM003"
// message="Specified driver could not be loaded due to system error 127 (PostgreSQL ANSI)."
// nativeError=160
// System error 127 is "The specified procedure could not be found."
// This problem does not manifest with Mammoth ODBCng PostgreSQL driver.
//
// Oracle tests do not exit cleanly if Oracle driver is loaded after DB2.
//
// For the time being, the workaround is to connect to DB2 after connecting to PostgreSQL and Oracle.
addTest(pSuite, ODBCMySQLTest::suite());
addTest(pSuite, ODBCOracleTest::suite());
addTest(pSuite, ODBCPostgreSQLTest::suite());
addTest(pSuite, ODBCSQLiteTest::suite());
addTest(pSuite, ODBCSQLServerTest::suite());
addTest(pSuite, ODBCDB2Test::suite());
// MS Access driver does not support connection status detection
// disabled for the time being
#if 0 //defined(POCO_OS_FAMILY_WINDOWS)
addTest(pSuite, ODBCAccessTest::suite());
#endif
return pSuite;
}
void ODBCTestSuite::addTest(CppUnit::TestSuite* pSuite, CppUnit::Test* pT)
{
if (pSuite && pT) pSuite->addTest(pT);
}

View File

@ -0,0 +1,30 @@
//
// ODBCTestSuite.h
//
// Definition of the ODBCTestSuite class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ODBCTestSuite_INCLUDED
#define ODBCTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class ODBCTestSuite
{
public:
static CppUnit::Test* suite();
private:
static void addTest(CppUnit::TestSuite* pSuite, CppUnit::Test* pT);
};
#endif // ODBCTestSuite_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,528 @@
//
// SQLExecutor.h
//
// Definition of the SQLExecutor class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef SQLExecutor_INCLUDED
#define SQLExecutor_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/BulkExtraction.h"
#include "Poco/Data/BulkBinding.h"
#include "Poco/NumberFormatter.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
#include <iostream>
#define poco_odbc_check_env(r, h) \
if (!SQL_SUCCEEDED(r)) \
{ \
Poco::Data::ODBC::EnvironmentException ee(h); \
std::cout << ee.toString() << std::endl; \
} \
assert (SQL_SUCCEEDED(r))
#define poco_odbc_check_dbc(r, h) \
if (!SQL_SUCCEEDED(r)) \
{ \
Poco::Data::ODBC::ConnectionException ce(h); \
std::cout << ce.toString() << std::endl; \
} \
assert (SQL_SUCCEEDED(r))
#define poco_odbc_check_stmt(r, h) \
if (!SQL_SUCCEEDED(r)) \
{ \
Poco::Data::ODBC::StatementException se(h); \
std::cout << se.toString() << std::endl; \
} \
assert (SQL_SUCCEEDED(r))
#define poco_odbc_check_desc(r, h) \
if (!SQL_SUCCEEDED(r)) \
{ \
Poco::Data::ODBC::DescriptorException de(h); \
std::cout << de.toString() << std::endl; \
} \
assert (SQL_SUCCEEDED(r))
#define poco_data_using_statements using Poco::Data::Keywords::now; \
using Poco::Data::Keywords::into; \
using Poco::Data::Keywords::use; \
using Poco::Data::Keywords::bulk; \
using Poco::Data::Keywords::limit; \
using Poco::Data::CLOB; \
using Poco::Data::ODBC::ConnectionException; \
using Poco::Data::ODBC::StatementException
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 execute(const std::string& sql);
/// Execute a query.
void bareboneODBCTest(const std::string& dbConnString,
const std::string& tableCreateString,
DataBinding bindMode,
DataExtraction extractMode,
bool doTime=true,
const std::string& blobPlaceholder="?");
void bareboneODBCMultiResultTest(const std::string& dbConnString,
const std::string& tableCreateString,
SQLExecutor::DataBinding bindMode,
SQLExecutor::DataExtraction extractMode,
const std::string& insert = MULTI_INSERT,
const std::string& select = MULTI_SELECT);
/// The above two functions use "bare bone" ODBC API calls
/// (i.e. calls are not "wrapped" in PocoData framework structures).
/// The purpose of the functions is to verify that a driver behaves
/// correctly as well as to determine its capabilities
/// (e.g. SQLGetData() restrictions relaxation policy, if any).
/// If these test pass, subsequent tests failures are likely ours.
void zeroRows();
void simpleAccess();
void complexType();
void complexTypeTuple();
void simpleAccessVector();
void complexTypeVector();
void sharedPtrComplexTypeVector();
void autoPtrComplexTypeVector();
void insertVector();
void insertEmptyVector();
void simpleAccessList();
void complexTypeList();
void insertList();
void insertEmptyList();
void simpleAccessDeque();
void complexTypeDeque();
void insertDeque();
void insertEmptyDeque();
void affectedRows(const std::string& whereClause = "");
void insertSingleBulk();
void insertSingleBulkVec();
void limits();
void limitOnce();
void limitPrepare();
void limitZero();
void prepare();
template <typename C1, typename C2, typename C3, typename C4, typename C5, typename C6>
void doBulkWithBool(Poco::UInt32 size, const std::string& blobPlaceholder="?")
{
poco_data_using_statements;
std::string funct = "doBulkWithBool()";
C1 ints;
C2 strings;
C3 blobs;
C4 floats;
C5 dateTimes(size);
C6 bools;
for (int i = 0; i < size; ++i)
{
ints.push_back(i);
strings.push_back(std::string("xyz" + Poco::NumberFormatter::format(i)));
blobs.push_back(std::string("abc") + Poco::NumberFormatter::format(i));
floats.push_back(i + .5);
bools.push_back(0 == i % 2);
}
try
{
session() <<
Poco::format("INSERT INTO MiscTest VALUES (?,%s,?,?,?,?)", blobPlaceholder),
use(strings),
use(blobs),
use(ints),
use(floats),
use(dateTimes),
use(bools), now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
try { session() << "DELETE FROM MiscTest", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
try
{
session() <<
Poco::format("INSERT INTO MiscTest VALUES (?,%s,?,?,?,?)", blobPlaceholder),
use(strings, bulk),
use(blobs, bulk),
use(ints, bulk),
use(floats, bulk),
use(dateTimes, bulk),
use(bools, bulk), now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
ints.clear();
strings.clear();
blobs.clear();
floats.clear();
dateTimes.clear();
bools.clear();
try
{
session() << "SELECT * FROM MiscTest ORDER BY Third",
into(strings),
into(blobs),
into(ints),
into(floats),
into(dateTimes),
into(bools),
now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
std::string number = Poco::NumberFormatter::format(size - 1);
assert (size == ints.size());
assert (0 == ints.front());
assert (size - 1 == ints.back());
assert (std::string("xyz0") == strings.front());
assert (std::string("xyz") + number == strings.back());
assert (CLOB("abc0") == blobs.front());
CLOB blob("abc");
blob.appendRaw(number.c_str(), number.size());
assert (blob == blobs.back());
assert (.5 == floats.front());
assert (floats.size() - 1 + .5 == floats.back());
assert (bools.front());
assert (((0 == ((bools.size() - 1) % 2)) == bools.back()));
ints.clear();
try
{
session() << "SELECT First FROM MiscTest", into(ints, bulk(size)), limit(size+1), now;
fail ("must fail");
}
catch(Poco::InvalidArgumentException&){ }
try
{
session() << "SELECT First FROM MiscTest", into(ints), bulk(size), now;
fail ("must fail");
}
catch(Poco::InvalidAccessException&){ }
ints.clear();
strings.clear();
strings.resize(size);
blobs.clear();
floats.clear();
floats.resize(size);
dateTimes.clear();
bools.clear();
bools.resize(size);
try
{
session() << "SELECT First, Second, Third, Fourth, Fifth, Sixth FROM MiscTest ORDER BY Third",
into(strings, bulk),
into(blobs, bulk(size)),
into(ints, bulk(size)),
into(floats, bulk),
into(dateTimes, bulk(size)),
into(bools, bulk),
now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (size == ints.size());
assert (0 == ints.front());
assert (size - 1 == ints.back());
assert (std::string("xyz0") == strings.front());
assert (std::string("xyz") + number == strings.back());
assert (CLOB("abc0") == blobs.front());
blob.assignRaw("abc", 3);
blob.appendRaw(number.c_str(), number.size());
assert (blob == blobs.back());
assert (.5 == floats.front());
assert (floats.size() - 1 + .5 == floats.back());
assert (bools.front());
assert (((0 == ((bools.size() - 1) % 2)) == bools.back()));
}
void doBulkPerformance(Poco::UInt32 size);
template <typename C1, typename C2, typename C3, typename C4, typename C5>
void doBulk(Poco::UInt32 size)
{
poco_data_using_statements;
std::string funct = "doBulk()";
C1 ints;
C2 strings;
C3 blobs;
C4 floats;
C5 dateTimes(size);
for (int i = 0; i < size; ++i)
{
ints.push_back(i);
strings.push_back(std::string("xyz" + Poco::NumberFormatter::format(i)));
blobs.push_back(std::string("abc") + Poco::NumberFormatter::format(i));
floats.push_back(i + .5);
}
try
{
session() << "INSERT INTO MiscTest VALUES (?,?,?,?,?)",
use(strings),
use(blobs),
use(ints),
use(floats),
use(dateTimes), now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
try { session() << "DELETE FROM MiscTest", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
try
{
session() << "INSERT INTO MiscTest VALUES (?,?,?,?,?)",
use(strings, bulk),
use(blobs, bulk),
use(ints, bulk),
use(floats, bulk),
use(dateTimes, bulk), now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
ints.clear();
strings.clear();
blobs.clear();
floats.clear();
dateTimes.clear();
try
{
session() << "SELECT * FROM MiscTest ORDER BY First",
into(strings),
into(blobs),
into(ints),
into(floats),
into(dateTimes),
now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
std::string number = Poco::NumberFormatter::format(size - 1);
assert (size == ints.size());
assert (0 == ints.front());
assert (size - 1 == ints.back());
assert (std::string("xyz0") == strings.front());
assert (std::string("xyz") + number == strings.back());
assert (CLOB("abc0") == blobs.front());
CLOB blob("abc");
blob.appendRaw(number.c_str(), number.size());
assert (blob == blobs.back());
assert (.5 == floats.front());
assert (floats.size() - 1 + .5 == floats.back());
ints.clear();
try
{
session() << "SELECT First FROM MiscTest", into(ints, bulk(size)), limit(size+1), now;
fail ("must fail");
}
catch(Poco::InvalidArgumentException&){ }
try
{
session() << "SELECT First FROM MiscTest", into(ints), bulk(size), now;
fail ("must fail");
}
catch(Poco::InvalidAccessException&){ }
ints.clear();
strings.clear();
blobs.clear();
floats.clear();
dateTimes.clear();
try
{
session() << "SELECT * FROM MiscTest ORDER BY First",
into(strings, bulk(size)),
into(blobs, bulk(size)),
into(ints, bulk(size)),
into(floats, bulk(size)),
into(dateTimes, bulk(size)),
now;
} catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (size == ints.size());
assert (0 == ints.front());
assert (size - 1 == ints.back());
assert (std::string("xyz0") == strings.front());
assert (std::string("xyz") + number == strings.back());
assert (CLOB("abc0") == blobs.front());
blob.assignRaw("abc", 3);
blob.appendRaw(number.c_str(), number.size());
assert (blob == blobs.back());
assert (.5 == floats.front());
assert (floats.size() - 1 + .5 == floats.back());
}
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, const std::string& blobPlaceholder = "?");
template <typename C1, typename C2>
void blobContainer(int size)
{
poco_data_using_statements;
std::string funct = "blobContainer()";
C1 lastName(size, "lastname");
C1 firstName(size, "firstname");
C1 address(size, "Address");
C2 img(size, CLOB("0123456789", 10));
int count = 0;
try { session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(img), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
try { session() << "SELECT COUNT(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (count == size);
C2 res;
try { session() << "SELECT Image FROM Person", into(res), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (res.size() == img.size());
assert (res == img);
}
void blobStmt();
void dateTime();
void date();
void time();
void floats();
void doubles();
void tuples();
void tupleVector();
void internalExtraction();
void filter(const std::string& query =
"SELECT * FROM Vectors ORDER BY int0 ASC",
const std::string& intFldName = "int0");
void internalBulkExtraction();
void internalBulkExtractionUTF16();
void internalStorageType();
void nulls();
void notNulls(const std::string& sqlState = "23502");
void rowIterator();
void stdVectorBool();
void asynchronous(int rowCount = 500);
void any();
void dynamicAny();
void multipleResults(const std::string& sql =
"SELECT * FROM Person WHERE Age = ?; "
"SELECT Age FROM Person WHERE FirstName = 'Bart'; "
"SELECT * FROM Person WHERE Age = ? OR Age = ? ORDER BY Age;");
void sqlChannel(const std::string& connect);
void sqlLogger(const std::string& connect);
void sessionTransaction(const std::string& connect);
void transaction(const std::string& connect);
void transactor();
void nullable();
void unicode(const std::string& dbConnString);
void reconnect();
private:
static const std::string MULTI_INSERT;
static const std::string MULTI_SELECT;
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
Poco::Data::Session& session();
Poco::Data::Session* _pSession;
};
inline Poco::Data::Session& SQLExecutor::session()
{
poco_check_ptr (_pSession);
return *_pSession;
}
#endif // SQLExecutor_INCLUDED

View File

@ -0,0 +1,31 @@
//
// WinDriver.cpp
//
// Windows test driver for Poco ODBC.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "WinTestRunner/WinTestRunner.h"
#include "ODBCTestSuite.h"
#include "Poco/Data/ODBC/Connector.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
Poco::Data::ODBC::Connector::registerConnector();
CppUnit::WinTestRunner runner;
runner.addTest(ODBCTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;