enh(Data): move SQLExecutor to a library in Poco::Data testsuite #4230

This commit is contained in:
Alex Fabijanic 2023-11-02 22:27:17 +01:00
parent 46728024f7
commit 596bd0ef23
13 changed files with 5204 additions and 3746 deletions

View File

@ -12,8 +12,9 @@ objects = Binder ConnectionHandle Connector EnvironmentHandle \
Extractor ODBCException ODBCMetaColumn ODBCStatementImpl \
Parameter Preparator SessionImpl TypeInfo Unicode Utility
target_includes = $(POCO_BASE)/Data/testsuite/include
ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
target_includes += $(POCO_BASE)/Data/src
endif
target = PocoDataODBC

View File

@ -138,10 +138,10 @@ private:
};
typedef HandleException<SQLHENV, SQL_HANDLE_ENV> EnvironmentException;
typedef HandleException<SQLHDBC, SQL_HANDLE_DBC> ConnectionException;
typedef HandleException<SQLHSTMT, SQL_HANDLE_STMT> StatementException;
typedef HandleException<SQLHDESC, SQL_HANDLE_DESC> DescriptorException;
using EnvironmentException = HandleException<SQLHENV, SQL_HANDLE_ENV>;
using ConnectionException = HandleException<SQLHDBC, SQL_HANDLE_DBC>;
using StatementException = HandleException<SQLHSTMT, SQL_HANDLE_STMT>;
using DescriptorException = HandleException<SQLHDESC, SQL_HANDLE_DESC>;
} } } // namespace Poco::Data::ODBC

View File

@ -33,12 +33,13 @@ ifeq ($(POCO_CONFIG),MinGW)
objects += ODBCAccessTest
endif
target_includes = $(POCO_BASE)/Data/testsuite/include
ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
target_includes += $(POCO_BASE)/Data/src
endif
target = testrunner
target_version = 1
target_libs = PocoDataODBC PocoData PocoFoundation CppUnit
target_libs = PocoDataODBC PocoDataTest PocoData PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec

View File

@ -189,7 +189,7 @@ void ODBCSQLServerTest::testBLOB()
try
{
executor().blob(maxFldSize, "CONVERT(VARBINARY(MAX),?)");
fail ("must fail");
fail (__func__, __LINE__, __FILE__);
}
catch (DataException&)
{
@ -209,7 +209,7 @@ void ODBCSQLServerTest::testBLOB()
try
{
executor().blob(maxFldSize+1, "CONVERT(VARBINARY(MAX),?)");
fail ("must fail");
fail (__func__, __LINE__, __FILE__);
}
catch (DataException&) { }
}

View File

@ -55,7 +55,7 @@ const bool ODBCTest::_bindValues[8] =
ODBCTest::ODBCTest(const std::string& name,
SessionPtr pSession,
ExecPtr pExecutor,
ExecPtr pExecutor,
std::string& rDSN,
std::string& rUID,
std::string& rPwd,

View File

@ -23,14 +23,14 @@
#include "SQLExecutor.h"
#define POCO_ODBC_TEST_DATABASE_SERVER "localhost"
#define POCO_ODBC_TEST_DATABASE_SERVER "10.211.55.5"//"localhost"
class ODBCTest: public CppUnit::TestCase
{
public:
typedef Poco::SharedPtr<Poco::Data::Session> SessionPtr;
typedef Poco::SharedPtr<SQLExecutor> ExecPtr;
using SessionPtr = Poco::SharedPtr<Poco::Data::Session>;
using ExecPtr = Poco::SharedPtr<SQLExecutor>;
ODBCTest(const std::string& name,
SessionPtr pSession,

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@
#include "Poco/Data/Session.h"
#include "Poco/Data/BulkExtraction.h"
#include "Poco/Data/BulkBinding.h"
#include "Poco/Data/Test/SQLExecutor.h"
#include "Poco/NumberFormatter.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
@ -534,21 +535,498 @@ private:
Poco::Data::Session& session(bool enc = false);
Poco::Data::Session* _pSession;
Poco::Data::Session* _pEncSession;
Poco::Data::Test::SQLExecutor _dataExecutor;
};
inline Poco::Data::Session& SQLExecutor::session(bool enc)
inline void SQLExecutor::sessionPool(const std::string& connectString, int minSessions, int maxSessions, int idleTime, int timeout)
{
if (!enc)
{
poco_check_ptr(_pSession);
return *_pSession;
}
else
{
poco_check_ptr(_pEncSession);
return *_pEncSession;
}
_dataExecutor.sessionPool("ODBC", connectString, minSessions, maxSessions, idleTime, timeout);
}
inline void SQLExecutor::zeroRows()
{
_dataExecutor.zeroRows();
}
inline void SQLExecutor::simpleAccess()
{
_dataExecutor.simpleAccess();
}
inline void SQLExecutor::complexType()
{
_dataExecutor.complexType();
}
inline void SQLExecutor::complexTypeTuple()
{
_dataExecutor.complexTypeTuple();
}
inline void SQLExecutor::simpleAccessVector()
{
_dataExecutor.simpleAccessVector();
}
inline void SQLExecutor::complexTypeVector()
{
_dataExecutor.complexTypeVector();
}
inline void SQLExecutor::sharedPtrComplexTypeVector()
{
_dataExecutor.sharedPtrComplexTypeVector();
}
inline void SQLExecutor::autoPtrComplexTypeVector()
{
_dataExecutor.autoPtrComplexTypeVector();
}
inline void SQLExecutor::insertVector()
{
_dataExecutor.insertVector();
}
inline void SQLExecutor::insertEmptyVector()
{
_dataExecutor.insertEmptyVector();
}
inline void SQLExecutor::simpleAccessList()
{
_dataExecutor.simpleAccessList();
}
inline void SQLExecutor::complexTypeList()
{
_dataExecutor.complexTypeList();
}
inline void SQLExecutor::insertList()
{
_dataExecutor.insertList();
}
inline void SQLExecutor::insertEmptyList()
{
_dataExecutor.insertEmptyList();
}
inline void SQLExecutor::simpleAccessDeque()
{
_dataExecutor.simpleAccessDeque();
}
inline void SQLExecutor::complexTypeDeque()
{
_dataExecutor.complexTypeDeque();
}
inline void SQLExecutor::insertDeque()
{
_dataExecutor.insertDeque();
}
inline void SQLExecutor::insertEmptyDeque()
{
_dataExecutor.insertEmptyDeque();
}
inline void SQLExecutor::affectedRows(const std::string& whereClause)
{
_dataExecutor.affectedRows();
}
inline void SQLExecutor::insertSingleBulk()
{
_dataExecutor.insertSingleBulk();
}
inline void SQLExecutor::floats()
{
_dataExecutor.floats();
}
inline void SQLExecutor::doubles()
{
_dataExecutor.doubles();
}
inline void SQLExecutor::uuids()
{
_dataExecutor.uuids();
}
inline void SQLExecutor::insertSingleBulkVec()
{
_dataExecutor.insertSingleBulkVec();
}
inline void SQLExecutor::limits()
{
_dataExecutor.limits();
}
inline void SQLExecutor::limitZero()
{
_dataExecutor.limitZero();
}
inline void SQLExecutor::limitOnce()
{
_dataExecutor.limitOnce();
}
inline void SQLExecutor::limitPrepare()
{
_dataExecutor.limitPrepare();
}
inline void SQLExecutor::prepare()
{
_dataExecutor.prepare();
}
inline void SQLExecutor::doBulkPerformance(Poco::UInt32 size)
{
_dataExecutor.doBulkPerformance(size);
}
inline void SQLExecutor::setSimple()
{
_dataExecutor.setSimple();
}
inline void SQLExecutor::setComplex()
{
_dataExecutor.setComplex();
}
inline void SQLExecutor::setComplexUnique()
{
_dataExecutor.setComplexUnique();
}
inline void SQLExecutor::multiSetSimple()
{
_dataExecutor.multiSetSimple();
}
inline void SQLExecutor::multiSetComplex()
{
_dataExecutor.multiSetComplex();
}
inline void SQLExecutor::mapComplex()
{
_dataExecutor.mapComplex();
}
inline void SQLExecutor::mapComplexUnique()
{
_dataExecutor.mapComplexUnique();
}
inline void SQLExecutor::multiMapComplex()
{
_dataExecutor.multiMapComplex();
}
inline void SQLExecutor::selectIntoSingle()
{
_dataExecutor.selectIntoSingle();
}
inline void SQLExecutor::selectIntoSingleStep()
{
_dataExecutor.selectIntoSingleStep();
}
inline void SQLExecutor::selectIntoSingleFail()
{
_dataExecutor.selectIntoSingleFail();
}
inline void SQLExecutor::lowerLimitOk()
{
_dataExecutor.lowerLimitOk();
}
inline void SQLExecutor::singleSelect()
{
_dataExecutor.singleSelect();
}
inline void SQLExecutor::lowerLimitFail()
{
_dataExecutor.lowerLimitFail();
}
inline void SQLExecutor::combinedLimits()
{
_dataExecutor.combinedLimits();
}
inline void SQLExecutor::ranges()
{
_dataExecutor.ranges();
}
inline void SQLExecutor::combinedIllegalLimits()
{
_dataExecutor.combinedIllegalLimits();
}
inline void SQLExecutor::illegalRange()
{
_dataExecutor.illegalRange();
}
inline void SQLExecutor::emptyDB()
{
_dataExecutor.emptyDB();
}
inline void SQLExecutor::blob(int bigSize, const std::string& blobPlaceholder)
{
_dataExecutor.blob(bigSize, blobPlaceholder);
}
inline void SQLExecutor::blobStmt()
{
_dataExecutor.blobStmt();
}
inline void SQLExecutor::recordSet()
{
_dataExecutor.recordSet();
}
inline void SQLExecutor::dateTime()
{
_dataExecutor.dateTime();
}
inline void SQLExecutor::date()
{
_dataExecutor.date();
}
inline void SQLExecutor::time()
{
_dataExecutor.time();
}
inline void SQLExecutor::tuples()
{
_dataExecutor.tuples();
}
inline void SQLExecutor::tupleVector()
{
_dataExecutor.tupleVector();
}
inline void SQLExecutor::internalExtraction()
{
_dataExecutor.internalExtraction();
}
inline void SQLExecutor::filter(const std::string& query, const std::string& intFldName)
{
_dataExecutor.filter();
}
inline void SQLExecutor::internalBulkExtraction()
{
_dataExecutor.internalBulkExtraction();
}
inline void SQLExecutor::internalBulkExtractionUTF16()
{
_dataExecutor.internalBulkExtractionUTF16();
}
inline void SQLExecutor::internalStorageType()
{
_dataExecutor.internalStorageType();
}
inline void SQLExecutor::nulls()
{
_dataExecutor.nulls();
}
inline void SQLExecutor::rowIterator()
{
_dataExecutor.rowIterator();
}
inline void SQLExecutor::stdVectorBool()
{
_dataExecutor.stdVectorBool();
}
inline void SQLExecutor::asynchronous(int rowCount)
{
_dataExecutor.asynchronous();
}
inline void SQLExecutor::dynamicAny()
{
_dataExecutor.dynamicAny();
}
inline void SQLExecutor::multipleResults(const std::string& sql)
{
_dataExecutor.multipleResults();
}
inline void SQLExecutor::sqlChannel(const std::string& connect)
{
_dataExecutor.sqlChannel("odbc", connect);
}
inline void SQLExecutor::sqlLogger(const std::string& connect)
{
_dataExecutor.sqlLogger("odbc", connect);
}
inline void SQLExecutor::setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti)
{
_dataExecutor.setTransactionIsolation(session, ti);
}
inline void SQLExecutor::autoCommit(const std::string&)
{
_dataExecutor.autoCommit();
}
inline void SQLExecutor::transactionIsolation()
{
_dataExecutor.transactionIsolation();
}
inline void SQLExecutor::sessionTransaction(const std::string& connect)
{
_dataExecutor.sessionTransaction("odbc", connect);
}
inline void SQLExecutor::sessionTransactionNoAutoCommit(const std::string& connect)
{
_dataExecutor.sessionTransactionNoAutoCommit("odbc", connect);
}
inline void SQLExecutor::transaction(const std::string& connect)
{
_dataExecutor.transaction("odbc", connect);
}
inline void SQLExecutor::transactor()
{
_dataExecutor.transactor();
}
inline void SQLExecutor::nullable()
{
_dataExecutor.nullable();
}
inline void SQLExecutor::reconnect()
{
_dataExecutor.reconnect();
}
inline void SQLExecutor::unicode(const std::string& dbConnString)
{
_dataExecutor.unicode(dbConnString);
}
inline void SQLExecutor::encoding(const std::string& dbConnString)
{
_dataExecutor.encoding(dbConnString);
}

View File

@ -1,30 +1,11 @@
#
# Makefile
#
# Makefile for Poco Data testsuite
# Makefile for Poco Data Tests
#
include $(POCO_BASE)/build/rules/global
ifeq ($(findstring SunOS,$(POCO_HOST_OSNAME)),SunOS)
POCO_SUN_FORTE = $(findstring SunOS-SunForte, $(POCO_CONFIG))
POCO_SUN_STUDIO = $(findstring SunOS-SunStudio, $(POCO_CONFIG))
ifneq (,$or ($(POCO_SUN_FORTE), $(POCO_SUN_STUDIO)))
CXXFLAGS += -erroff=hidevf
endif
endif
objects = DataTestSuite Driver \
DataTest SessionPoolTest \
Binder Extractor Preparator SessionImpl Connector TestStatementImpl
ifndef POCO_DATA_NO_SQL_PARSER
objects += SQLParserTest
target_includes = $(POCO_BASE)/Data/src
endif
target = testrunner
target_version = 1
target_libs = PocoData PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec
.PHONY: projects
clean distclean all: projects
projects:
$(MAKE) -f Makefile-testrunner $(MAKECMDGOALS)
$(MAKE) -f Makefile-library $(MAKECMDGOALS)

View File

@ -0,0 +1,21 @@
#
# Makefile
#
# Makefile for Poco Data testsuite library
#
include $(POCO_BASE)/build/rules/global
objects = SQLExecutor
target_includes = $(POCO_BASE)/Data/testsuite/include
ifndef POCO_DATA_NO_SQL_PARSER
objects += SQLParserTest
target_includes += $(POCO_BASE)/Data/src
endif
target = PocoDataTest
target_version = 1
target_libs = PocoData PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/lib

View File

@ -0,0 +1,31 @@
#
# Makefile
#
# Makefile for Poco Data testsuite
#
include $(POCO_BASE)/build/rules/global
ifeq ($(findstring SunOS,$(POCO_HOST_OSNAME)),SunOS)
POCO_SUN_FORTE = $(findstring SunOS-SunForte, $(POCO_CONFIG))
POCO_SUN_STUDIO = $(findstring SunOS-SunStudio, $(POCO_CONFIG))
ifneq (,$or ($(POCO_SUN_FORTE), $(POCO_SUN_STUDIO)))
CXXFLAGS += -erroff=hidevf
endif
endif
objects = DataTestSuite Driver \
DataTest SessionPoolTest Binder Extractor Preparator \
SessionImpl Connector TestStatementImpl
target_includes = $(POCO_BASE)/Data/testsuite/include
ifndef POCO_DATA_NO_SQL_PARSER
objects += SQLParserTest
target_includes += $(POCO_BASE)/Data/src
endif
target = testrunner
target_version = 1
target_libs = PocoData PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec

View File

@ -0,0 +1,241 @@
//
// SQLExecutor.h
//
// Definition of the SQLExecutor class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Data_SQLExecutor_INCLUDED
#define Data_SQLExecutor_INCLUDED
#include "Poco/Data/Data.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_data_using_keywords 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::DataException; \
using Poco::Data::CLOB;
namespace Poco {
namespace Data {
namespace Test {
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, Poco::Data::Session* pEncSession = 0);
~SQLExecutor();
template <typename C>
void connection(C& c, const std::string& connectString)
{
assertFalse (c.isConnected());
assertTrue (c.connect(connectString, 5));
assertTrue (c.isConnected());
assertTrue (c.getTimeout() == 5);
c.setTimeout(6);
assertTrue (c.getTimeout() == 6);
assertTrue (c.disconnect());
assertFalse (c.isConnected());
assertTrue (c.connect(connectString));
assertTrue (c.isConnected());
try
{
c.connect();
fail ("Connection attempt must fail when already connected");
}
catch(const Poco::InvalidAccessException&){}
assertTrue (c.disconnect());
assertFalse (c.isConnected());
try
{
c.connect();
fail ("Connection attempt with empty string must fail");
}
catch(const Poco::InvalidArgumentException&){}
}
void session(const std::string& connector, const std::string& connectString, int timeout);
void sessionPool(const std::string& connector, const std::string& connectString, int minSessions, int maxSessions, int idleTime, int timeout);
void execute(const std::string& sql);
/// Execute a query.
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();
void doBulkPerformance(Poco::UInt32 size);
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_keywords;
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(DataException& ce){ std::cout << ce.displayText() << std::endl; fail (funct, __LINE__, __FILE__); }
try { session() << "SELECT COUNT(*) FROM Person", into(count), now; }
catch(DataException& ce){ std::cout << ce.displayText() << std::endl; fail (funct, __LINE__, __FILE__); }
assert (count == size);
C2 res;
try { session() << "SELECT Image FROM Person", into(res), now; }
catch(DataException& ce){ std::cout << ce.displayText() << std::endl; fail (funct, __LINE__, __FILE__); }
assert (res.size() == img.size());
assert (res == img);
}
void blobStmt();
void recordSet();
void dateTime();
void date();
void time();
void floats();
void doubles();
void uuids();
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 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& connector, const std::string& connect);
void sqlLogger(const std::string& connector, const std::string& connect);
void autoCommit();
void transactionIsolation();
void sessionTransaction(const std::string& connector, const std::string& connect);
void sessionTransactionNoAutoCommit(const std::string& connector, const std::string& connect);
void transaction(const std::string& connector, const std::string& connect);
void transactor();
void nullable();
void unicode(const std::string& dbConnString);
void encoding(const std::string& dbConnString);
void reconnect();
Poco::Data::Session& session(bool enc = false);
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
private:
static const std::string MULTI_INSERT;
static const std::string MULTI_SELECT;
Poco::Data::Session* _pSession;
Poco::Data::Session* _pEncSession;
};
} } } // Poco::Data::Test
#endif // Data_SQLExecutor_INCLUDED

File diff suppressed because it is too large Load Diff