From a50823c5a89d58ea91c9da18a7a19773c0b2a2e1 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sun, 28 Apr 2013 12:34:07 -0500 Subject: [PATCH] data housekeeping - removed naked pointers from Data interfaces - fixed GH #82: name conflict in Data::Keywords::bind - fixed GH #157: MySQL: cannot bind to 'long' data type on Windows/Visual C++ - fixed GH #158: MySQL: MYSQL_BIND 'is_unsigned' member is not set --- CHANGELOG | 4 + Data/MySQL/MySQL_vs110.vcxproj | 164 ++++----- Data/MySQL/include/Poco/Data/MySQL/Binder.h | 49 ++- .../MySQL/include/Poco/Data/MySQL/Extractor.h | 2 + .../Poco/Data/MySQL/MySQLStatementImpl.h | 11 +- Data/MySQL/src/Binder.cpp | 35 +- Data/MySQL/src/MySQLStatementImpl.cpp | 13 +- Data/MySQL/testsuite/TestSuite_vs110.vcxproj | 148 ++++---- Data/ODBC/include/Poco/Data/ODBC/Extractor.h | 40 ++- .../Poco/Data/ODBC/ODBCStatementImpl.h | 14 +- Data/ODBC/include/Poco/Data/ODBC/Preparator.h | 16 +- Data/ODBC/src/Extractor.cpp | 58 +-- Data/ODBC/src/ODBCStatementImpl.cpp | 6 +- .../Poco/Data/SQLite/SQLiteStatementImpl.h | 12 +- Data/include/Poco/Data/AbstractBinder.h | 2 + Data/include/Poco/Data/AbstractBinding.h | 26 +- Data/include/Poco/Data/AbstractExtraction.h | 44 +-- Data/include/Poco/Data/AbstractExtractor.h | 2 + Data/include/Poco/Data/AbstractPreparation.h | 16 +- Data/include/Poco/Data/AbstractPreparator.h | 2 + Data/include/Poco/Data/Binding.h | 330 ++++++++++-------- Data/include/Poco/Data/BulkBinding.h | 14 +- Data/include/Poco/Data/BulkExtraction.h | 14 +- Data/include/Poco/Data/Extraction.h | 24 +- Data/include/Poco/Data/Preparation.h | 2 +- Data/include/Poco/Data/Statement.h | 77 ++-- Data/include/Poco/Data/StatementImpl.h | 55 +-- Data/src/AbstractBinding.cpp | 2 +- Data/src/AbstractPreparation.cpp | 2 +- Data/src/RecordSet.cpp | 2 +- Data/src/Statement.cpp | 8 +- Data/src/StatementImpl.cpp | 8 +- Data/testsuite/src/DataTest.cpp | 52 ++- Data/testsuite/src/TestStatementImpl.h | 12 +- 34 files changed, 669 insertions(+), 597 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f0bbc3f6b..6c77234eb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -39,6 +39,10 @@ Release 1.5.2 (2013-04-29) - fixed GH #141: Application::run() documentation/implementation discrepancy - changed RowFormatter to SharedPtr in Data::RecordSet interface (breaking change!) - fixed GH #144: Poco::Dynamic emits invalid JSON +- removed naked pointers from Data interfaces +- fixed GH #82: name conflict in Data::Keywords::bind +- fixed GH #157: MySQL: cannot bind to 'long' data type on Windows/Visual C++ +- fixed GH #158: MySQL: MYSQL_BIND 'is_unsigned' member is not set Release 1.5.1 (2013-01-11) ========================== diff --git a/Data/MySQL/MySQL_vs110.vcxproj b/Data/MySQL/MySQL_vs110.vcxproj index 59afdd928..83928a96f 100644 --- a/Data/MySQL/MySQL_vs110.vcxproj +++ b/Data/MySQL/MySQL_vs110.vcxproj @@ -1,4 +1,4 @@ - + @@ -32,82 +32,86 @@ MySQL Win32Proj - - + + StaticLibrary MultiByte v110 - + StaticLibrary MultiByte v110 - + StaticLibrary MultiByte v110 - + StaticLibrary MultiByte v110 - + DynamicLibrary MultiByte v110 - + DynamicLibrary MultiByte v110 - - - - + + + + - - + + - - + + - - + + - - + + - - + + - + <_ProjectFileVersion>10.0.40219.1 - ..\..\bin\ - obj\$(Configuration)\ - true - ..\..\bin\ - obj\$(Configuration)\ - false - ..\..\lib\ - obj\$(Configuration)\ - ..\..\lib\ - obj\$(Configuration)\ - ..\..\lib\ - obj\$(Configuration)\ - ..\..\lib\ - obj\$(Configuration)\ - PocoDataMySQLd - PocoDataMySQLmdd - PocoDataMySQLmtd - PocoDataMySQL - PocoDataMySQLmd - PocoDataMySQLmt + ..\..\bin\ + obj\$(Configuration)\ + true + ..\..\bin\ + obj\$(Configuration)\ + false + ..\..\lib\ + obj\$(Configuration)\ + ..\..\lib\ + obj\$(Configuration)\ + ..\..\lib\ + obj\$(Configuration)\ + ..\..\lib\ + obj\$(Configuration)\ + PocoDataMySQLd + PocoDataMySQLmdd + PocoDataMySQLmtd + PocoDataMySQL + PocoDataMySQLmd + PocoDataMySQLmt - + + C:\Program Files (x86)\MySQL\Connector C 6.0.2\include;$(IncludePath) + C:\Program Files (x86)\MySQL\Connector C 6.0.2\lib\debug;$(LibraryPath) + + Disabled .\include;..\..\Foundation\include;..\..\Data\include;%(AdditionalIncludeDirectories) @@ -120,7 +124,7 @@ true true true - + Level3 EditAndContinue Default @@ -138,7 +142,7 @@ MachineX86 - + Disabled OnlyExplicitInline @@ -153,9 +157,9 @@ true true true - + Level3 - + Default %(DisableSpecificWarnings) @@ -172,7 +176,7 @@ MachineX86 - + Disabled .\include;..\..\Foundation\include;..\..\Data\include;%(AdditionalIncludeDirectories) @@ -185,7 +189,7 @@ true true true - + ..\..\lib\PocoDataMySQLmtd.pdb Level3 EditAndContinue @@ -196,7 +200,7 @@ ..\..\lib\PocoDataMySQLmtd.lib - + Disabled OnlyExplicitInline @@ -211,9 +215,9 @@ true true true - + Level3 - + Default %(DisableSpecificWarnings) @@ -221,7 +225,7 @@ ..\..\lib\PocoDataMySQLmt.lib - + Disabled .\include;..\..\Foundation\include;..\..\Data\include;%(AdditionalIncludeDirectories) @@ -234,7 +238,7 @@ true true true - + ..\..\lib\PocoDataMySQLmdd.pdb Level3 EditAndContinue @@ -245,7 +249,7 @@ ..\..\lib\PocoDataMySQLmdd.lib - + Disabled OnlyExplicitInline @@ -260,10 +264,10 @@ true true true - + ..\..\lib\PocoDataMySQLmd.pdb Level3 - + Default %(DisableSpecificWarnings) @@ -273,28 +277,28 @@ - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - + + + \ No newline at end of file diff --git a/Data/MySQL/include/Poco/Data/MySQL/Binder.h b/Data/MySQL/include/Poco/Data/MySQL/Binder.h index c13da8459..731a8437d 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Binder.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Binder.h @@ -54,54 +54,53 @@ class MySQL_API Binder: public Poco::Data::AbstractBinder /// Binds placeholders in the sql query to the provided values. Performs data types mapping. { public: + typedef SharedPtr Ptr; Binder(); /// Creates the Binder. virtual ~Binder(); /// Destroys the Binder. - + virtual void bind(std::size_t pos, const Poco::Int8& val, Direction dir); /// Binds an Int8. virtual void bind(std::size_t pos, const Poco::UInt8& val, Direction dir); /// Binds an UInt8. - + virtual void bind(std::size_t pos, const Poco::Int16& val, Direction dir); /// Binds an Int16. - + virtual void bind(std::size_t pos, const Poco::UInt16& val, Direction dir); /// Binds an UInt16. - + virtual void bind(std::size_t pos, const Poco::Int32& val, Direction dir); /// Binds an Int32. - + virtual void bind(std::size_t pos, const Poco::UInt32& val, Direction dir); /// Binds an UInt32. - + virtual void bind(std::size_t pos, const Poco::Int64& val, Direction dir); /// Binds an Int64. - + virtual void bind(std::size_t pos, const Poco::UInt64& val, Direction dir); /// Binds an UInt64. -#ifndef POCO_LONG_IS_64_BIT virtual void bind(std::size_t pos, const long& val, Direction dir = PD_IN); /// Binds a long. virtual void bind(std::size_t pos, const unsigned long& val, Direction dir = PD_IN); /// Binds an unsigned long. -#endif - + virtual void bind(std::size_t pos, const bool& val, Direction dir); /// Binds a boolean. - + virtual void bind(std::size_t pos, const float& val, Direction dir); /// Binds a float. - + virtual void bind(std::size_t pos, const double& val, Direction dir); /// Binds a double. - + virtual void bind(std::size_t pos, const char& val, Direction dir); /// Binds a single character. @@ -154,27 +153,27 @@ public: virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); - + virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); @@ -261,7 +260,7 @@ private: { } - void realBind(std::size_t pos, enum_field_types type, const void* buffer, int length); + void realBind(std::size_t pos, enum_field_types type, const void* buffer, int length, bool isUnsigned = false); /// Common bind implementation private: diff --git a/Data/MySQL/include/Poco/Data/MySQL/Extractor.h b/Data/MySQL/include/Poco/Data/MySQL/Extractor.h index fcc072148..ea0644b01 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Extractor.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Extractor.h @@ -62,6 +62,8 @@ class MySQL_API Extractor: public Poco::Data::AbstractExtractor /// If NULL is received, the incoming val value is not changed and false is returned { public: + typedef SharedPtr Ptr; + Extractor(StatementExecutor& st, ResultMetadata& md); /// Creates the Extractor. diff --git a/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h b/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h index aeba37eaa..5e4e8747d 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h +++ b/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h @@ -59,7 +59,6 @@ class MySQL_API MySQLStatementImpl: public Poco::Data::StatementImpl /// Implements statement functionality needed for MySQL { public: - MySQLStatementImpl(SessionImpl& s); /// Creates the MySQLStatementImpl. @@ -69,7 +68,7 @@ public: protected: virtual std::size_t columnsReturned() const; - /// Returns number of columns returned by query. + /// Returns number of columns returned by query. virtual std::size_t affectedRowCount() const; /// Returns the number of affected rows. @@ -97,10 +96,10 @@ protected: virtual void bindImpl(); /// Binds parameters - virtual AbstractExtractor& extractor(); + virtual Poco::Data::AbstractExtractor::Ptr extractor(); /// Returns the concrete extractor used by the statement. - virtual AbstractBinder& binder(); + virtual Poco::Data::AbstractBinder::Ptr binder(); /// Returns the concrete binder used by the statement. private: @@ -113,8 +112,8 @@ private: StatementExecutor _stmt; ResultMetadata _metadata; - Binder _binder; - Extractor _extractor; + Binder::Ptr _pBinder; + Extractor::Ptr _pExtractor; int _hasNext; }; diff --git a/Data/MySQL/src/Binder.cpp b/Data/MySQL/src/Binder.cpp index 00106708d..40262e109 100644 --- a/Data/MySQL/src/Binder.cpp +++ b/Data/MySQL/src/Binder.cpp @@ -49,11 +49,11 @@ Binder::Binder() Binder::~Binder() { - for (std::vector::iterator it = _dates.begin(); it != _dates.end(); ++it) - { - delete *it; - *it = 0; - } + for (std::vector::iterator it = _dates.begin(); it != _dates.end(); ++it) + { + delete *it; + *it = 0; + } } @@ -67,7 +67,7 @@ void Binder::bind(std::size_t pos, const Poco::Int8& val, Direction dir) void Binder::bind(std::size_t pos, const Poco::UInt8& val, Direction dir) { poco_assert(dir == PD_IN); - realBind(pos, MYSQL_TYPE_TINY, &val, 0); + realBind(pos, MYSQL_TYPE_TINY, &val, 0, true); } @@ -81,7 +81,7 @@ void Binder::bind(std::size_t pos, const Poco::Int16& val, Direction dir) void Binder::bind(std::size_t pos, const Poco::UInt16& val, Direction dir) { poco_assert(dir == PD_IN); - realBind(pos, MYSQL_TYPE_SHORT, &val, 0); + realBind(pos, MYSQL_TYPE_SHORT, &val, 0, true); } @@ -95,7 +95,7 @@ void Binder::bind(std::size_t pos, const Poco::Int32& val, Direction dir) void Binder::bind(std::size_t pos, const Poco::UInt32& val, Direction dir) { poco_assert(dir == PD_IN); - realBind(pos, MYSQL_TYPE_LONG, &val, 0); + realBind(pos, MYSQL_TYPE_LONG, &val, 0, true); } @@ -109,24 +109,30 @@ void Binder::bind(std::size_t pos, const Poco::Int64& val, Direction dir) void Binder::bind(std::size_t pos, const Poco::UInt64& val, Direction dir) { poco_assert(dir == PD_IN); - realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0); + realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0, true); } -#ifndef POCO_LONG_IS_64_BIT void Binder::bind(std::size_t pos, const long& val, Direction dir) { poco_assert(dir == PD_IN); +#ifdef POCO_LONG_IS_64_BIT realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0); +#else + realBind(pos, MYSQL_TYPE_LONG, &val, 0); +#endif } void Binder::bind(std::size_t pos, const unsigned long& val, Direction dir) { poco_assert(dir == PD_IN); - realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0); -} +#ifdef POCO_LONG_IS_64_BIT + realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0, true); +#else + realBind(pos, MYSQL_TYPE_LONG, &val, 0, true); #endif +} void Binder::bind(std::size_t pos, const bool& val, Direction dir) @@ -290,7 +296,7 @@ MYSQL_BIND* Binder::getBindArray() const // //////////////////// -void Binder::realBind(std::size_t pos, enum_field_types type, const void* buffer, int length) +void Binder::realBind(std::size_t pos, enum_field_types type, const void* buffer, int length, bool isUnsigned) { if (pos >= _bindArray.size()) { @@ -303,8 +309,9 @@ void Binder::realBind(std::size_t pos, enum_field_types type, const void* buffer MYSQL_BIND b = {0}; b.buffer_type = type; - b.buffer = const_cast(buffer); + b.buffer = const_cast(buffer); b.buffer_length = length; + b.is_unsigned = isUnsigned; _bindArray[pos] = b; } diff --git a/Data/MySQL/src/MySQLStatementImpl.cpp b/Data/MySQL/src/MySQLStatementImpl.cpp index 1630bd7fa..9c692109c 100644 --- a/Data/MySQL/src/MySQLStatementImpl.cpp +++ b/Data/MySQL/src/MySQLStatementImpl.cpp @@ -44,7 +44,8 @@ namespace MySQL { MySQLStatementImpl::MySQLStatementImpl(SessionImpl& h) : Poco::Data::StatementImpl(h), _stmt(h.handle()), - _extractor(_stmt, _metadata), + _pBinder(new Binder), + _pExtractor(new Extractor(_stmt, _metadata)), _hasNext(NEXT_DONTKNOW) { } @@ -160,21 +161,21 @@ void MySQLStatementImpl::bindImpl() pos += (*it)->numOfColumnsHandled(); } - _stmt.bindParams(_binder.getBindArray(), _binder.size()); + _stmt.bindParams(_pBinder->getBindArray(), _pBinder->size()); _stmt.execute(); _hasNext = NEXT_DONTKNOW; } -AbstractExtractor& MySQLStatementImpl::extractor() +Poco::Data::AbstractExtractor::Ptr MySQLStatementImpl::extractor() { - return _extractor; + return _pExtractor; } -AbstractBinder& MySQLStatementImpl::binder() +Poco::Data::AbstractBinder::Ptr MySQLStatementImpl::binder() { - return _binder; + return _pBinder; } diff --git a/Data/MySQL/testsuite/TestSuite_vs110.vcxproj b/Data/MySQL/testsuite/TestSuite_vs110.vcxproj index 0f9d7d9c5..0e163de71 100644 --- a/Data/MySQL/testsuite/TestSuite_vs110.vcxproj +++ b/Data/MySQL/testsuite/TestSuite_vs110.vcxproj @@ -1,4 +1,4 @@ - + @@ -32,92 +32,96 @@ TestSuite Win32Proj - - + + Application Dynamic MultiByte v110 - + Application Dynamic MultiByte v110 - + Application Static MultiByte v110 - + Application Static MultiByte v110 - + Application Dynamic MultiByte v110 - + Application Dynamic MultiByte v110 - - - - + + + + - - + + - - + + - - + + - - + + - - + + - + <_ProjectFileVersion>10.0.40219.1 - bin\ - obj\$(Configuration)\ - true - bin\ - obj\$(Configuration)\ - false - bin\static_mt\ - obj\$(Configuration)\ - true - bin\static_mt\ - obj\$(Configuration)\ - false - bin\static_md\ - obj\$(Configuration)\ - true - bin\static_md\ - obj\$(Configuration)\ - false - TestSuited - TestSuited - TestSuited - TestSuite - TestSuite - TestSuite + bin\ + obj\$(Configuration)\ + true + bin\ + obj\$(Configuration)\ + false + bin\static_mt\ + obj\$(Configuration)\ + true + bin\static_mt\ + obj\$(Configuration)\ + false + bin\static_md\ + obj\$(Configuration)\ + true + bin\static_md\ + obj\$(Configuration)\ + false + TestSuited + TestSuited + TestSuited + TestSuite + TestSuite + TestSuite - + + C:\Program Files (x86)\MySQL\Connector C 6.0.2\include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + C:\Program Files (x86)\MySQL\Connector C 6.0.2\lib\debug;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSDK_LibraryPath_x86); + + Disabled ..\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Foundation\include;..\..\..\Data\include;%(AdditionalIncludeDirectories) @@ -130,7 +134,7 @@ true true true - + Level3 EditAndContinue Default @@ -147,7 +151,7 @@ MachineX86 - + Disabled OnlyExplicitInline @@ -162,9 +166,9 @@ true true true - + Level3 - + Default %(DisableSpecificWarnings) @@ -179,7 +183,7 @@ MachineX86 - + Disabled ..\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Foundation\include;..\..\..\Data\include;%(AdditionalIncludeDirectories) @@ -192,7 +196,7 @@ true true true - + Level3 EditAndContinue Default @@ -210,7 +214,7 @@ MachineX86 - + Disabled OnlyExplicitInline @@ -225,9 +229,9 @@ true true true - + Level3 - + Default %(DisableSpecificWarnings) @@ -243,7 +247,7 @@ MachineX86 - + Disabled ..\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Foundation\include;..\..\..\Data\include;%(AdditionalIncludeDirectories) @@ -256,7 +260,7 @@ true true true - + Level3 EditAndContinue Default @@ -273,7 +277,7 @@ MachineX86 - + Disabled OnlyExplicitInline @@ -288,9 +292,9 @@ true true true - + Level3 - + Default %(DisableSpecificWarnings) @@ -306,16 +310,16 @@ - - - + + + - - - - + + + + - - - + + + \ No newline at end of file diff --git a/Data/ODBC/include/Poco/Data/ODBC/Extractor.h b/Data/ODBC/include/Poco/Data/ODBC/Extractor.h index 4ecc7dd82..07c5795c5 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Extractor.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Extractor.h @@ -71,8 +71,10 @@ class ODBC_API Extractor: public Poco::Data::AbstractExtractor /// If NULL is received, the incoming val value is not changed and false is returned { public: + typedef Preparator::Ptr PreparatorPtr; + Extractor(const StatementHandle& rStmt, - Preparator& rPreparator); + Preparator::Ptr pPreparator); /// Creates the Extractor. ~Extractor(); @@ -370,8 +372,8 @@ private: bool extractBoundImpl(std::size_t pos, T& val) { if (isNull(pos)) return false; - poco_assert_dbg (typeid(T) == _rPreparator[pos].type()); - val = *AnyCast(&_rPreparator[pos]); + poco_assert_dbg (typeid(T) == _pPreparator->at(pos).type()); + val = *AnyCast(&_pPreparator->at(pos)); return true; } @@ -382,8 +384,8 @@ private: bool extractBoundImplContainer(std::size_t pos, C& val) { typedef typename C::value_type Type; - poco_assert_dbg (typeid(std::vector) == _rPreparator[pos].type()); - std::vector& v = RefAnyCast >(_rPreparator[pos]); + poco_assert_dbg (typeid(std::vector) == _pPreparator->at(pos).type()); + std::vector& v = RefAnyCast >(_pPreparator->at(pos)); val.assign(v.begin(), v.end()); return true; } @@ -405,14 +407,14 @@ private: typedef typename C::iterator ItType; typedef typename StringType::value_type CharType; - CharType** pc = AnyCast(&_rPreparator[pos]); + CharType** pc = AnyCast(&(_pPreparator->at(pos))); poco_assert_dbg (pc); - poco_assert_dbg (_rPreparator.bulkSize() == values.size()); + poco_assert_dbg (_pPreparator->bulkSize() == values.size()); std::size_t colWidth = columnSize(pos); ItType it = values.begin(); ItType end = values.end(); for (int row = 0; it != end; ++it, ++row) - it->assign(*pc + row * colWidth, _rPreparator.actualDataSize(pos, row)); + it->assign(*pc + row * colWidth, _pPreparator->actualDataSize(pos, row)); return true; } @@ -424,14 +426,14 @@ private: typedef typename LOBType::ValueType CharType; typedef typename C::iterator ItType; - CharType** pc = AnyCast(&_rPreparator[pos]); + CharType** pc = AnyCast(&(_pPreparator->at(pos))); poco_assert_dbg (pc); - poco_assert_dbg (_rPreparator.bulkSize() == values.size()); - std::size_t colWidth = _rPreparator.maxDataSize(pos); + poco_assert_dbg (_pPreparator->bulkSize() == values.size()); + std::size_t colWidth = _pPreparator->maxDataSize(pos); ItType it = values.begin(); ItType end = values.end(); for (int row = 0; it != end; ++it, ++row) - it->assignRaw(*pc + row * colWidth, _rPreparator.actualDataSize(pos, row)); + it->assignRaw(*pc + row * colWidth, _pPreparator->actualDataSize(pos, row)); return true; } @@ -441,9 +443,9 @@ private: { if (isNull(pos)) return false; - std::size_t dataSize = _rPreparator.actualDataSize(pos); + std::size_t dataSize = _pPreparator->actualDataSize(pos); checkDataSize(dataSize); - T* sp = AnyCast(_rPreparator[pos]); + T* sp = AnyCast(_pPreparator->at(pos)); val.assignRaw(sp, dataSize); return true; @@ -569,10 +571,10 @@ private: SQLINTEGER columnSize(std::size_t pos) const; - const StatementHandle& _rStmt; - Preparator& _rPreparator; + const StatementHandle& _rStmt; + PreparatorPtr _pPreparator; Preparator::DataExtraction _dataExtraction; - std::vector _lengths; + std::vector _lengths; }; @@ -654,7 +656,7 @@ inline bool Extractor::extractBoundImplContainer(std::size_t pos, inline void Extractor::setDataExtraction(Preparator::DataExtraction ext) { - _rPreparator.setDataExtraction(_dataExtraction = ext); + _pPreparator->setDataExtraction(_dataExtraction = ext); } @@ -686,7 +688,7 @@ inline bool Extractor::isNullLengthIndicator(SQLLEN val) const inline SQLINTEGER Extractor::columnSize(std::size_t pos) const { std::size_t size = ODBCMetaColumn(_rStmt, pos).length(); - std::size_t maxSize = _rPreparator.maxDataSize(pos); + std::size_t maxSize = _pPreparator->maxDataSize(pos); if (size > maxSize) size = maxSize; return (SQLINTEGER) size; } diff --git a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h index cd75b87c9..98126ac14 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h @@ -104,10 +104,10 @@ protected: void bindImpl(); /// Binds all parameters and executes the statement. - AbstractExtractor& extractor(); + AbstractExtraction::ExtractorPtr extractor(); /// Returns the concrete extractor used by the statement. - AbstractBinder& binder(); + AbstractBinding::BinderPtr binder(); /// Returns the concrete binder used by the statement. std::string nativeSQL(); @@ -181,18 +181,18 @@ private: // // inlines // -inline AbstractExtractor& ODBCStatementImpl::extractor() +inline AbstractExtraction::ExtractorPtr ODBCStatementImpl::extractor() { poco_assert_dbg (currentDataSet() < _extractors.size()); poco_assert_dbg (_extractors[currentDataSet()]); - return *_extractors[currentDataSet()]; + return _extractors[currentDataSet()]; } -inline AbstractBinder& ODBCStatementImpl::binder() +inline AbstractBinding::BinderPtr ODBCStatementImpl::binder() { - poco_assert_dbg (_pBinder); - return *_pBinder; + poco_assert_dbg (!_pBinder.isNull()); + return _pBinder; } diff --git a/Data/ODBC/include/Poco/Data/ODBC/Preparator.h b/Data/ODBC/include/Poco/Data/ODBC/Preparator.h index 1813133a5..9b87f5839 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Preparator.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Preparator.h @@ -81,9 +81,9 @@ class ODBC_API Preparator : public AbstractPreparator /// /// Preparator object is used to : /// - /// 1) Prepare SQL statement. - /// 2) Provide and contain the memory locations where retrieved values are placed during recordset iteration. - /// 3) Keep count of returned number of columns with their respective datatypes and sizes. + /// 1) Prepare SQL statement. + /// 2) Provide and contain the memory locations where retrieved values are placed during recordset iteration. + /// 3) Keep count of returned number of columns with their respective datatypes and sizes. /// /// Notes: /// @@ -94,6 +94,7 @@ class ODBC_API Preparator : public AbstractPreparator { public: typedef std::vector CharArray; + typedef SharedPtr Ptr; enum DataExtraction { @@ -390,6 +391,9 @@ public: Poco::Any& operator [] (std::size_t pos); /// Returns reference to column data. + Poco::Any& at(std::size_t pos); + /// Returns reference to column data. + void setMaxFieldSize(std::size_t size); /// Sets maximum supported field size. @@ -1224,6 +1228,12 @@ inline Preparator::DataExtraction Preparator::getDataExtraction() const inline Poco::Any& Preparator::operator [] (std::size_t pos) +{ + return at(pos); +} + + +inline Poco::Any& Preparator::at(std::size_t pos) { return _values.at(pos); } diff --git a/Data/ODBC/src/Extractor.cpp b/Data/ODBC/src/Extractor.cpp index c1d5afe9b..44c789770 100644 --- a/Data/ODBC/src/Extractor.cpp +++ b/Data/ODBC/src/Extractor.cpp @@ -55,10 +55,10 @@ const std::string Extractor::FLD_SIZE_EXCEEDED_FMT = "Specified data size (%z by Extractor::Extractor(const StatementHandle& rStmt, - Preparator& rPreparator): + Preparator::Ptr pPreparator): _rStmt(rStmt), - _rPreparator(rPreparator), - _dataExtraction(rPreparator.getDataExtraction()) + _pPreparator(pPreparator), + _dataExtraction(pPreparator->getDataExtraction()) { } @@ -73,8 +73,8 @@ bool Extractor::extractBoundImpl(std::size_t pos, std::string& val) { if (isNull(pos)) return false; - std::size_t dataSize = _rPreparator.actualDataSize(pos); - char* sp = AnyCast(_rPreparator[pos]); + std::size_t dataSize = _pPreparator->actualDataSize(pos); + char* sp = AnyCast(_pPreparator->at(pos)); std::size_t len = std::strlen(sp); if (len < dataSize) dataSize = len; checkDataSize(dataSize); @@ -88,7 +88,7 @@ template<> bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data::Date& val) { if (isNull(pos)) return false; - SQL_DATE_STRUCT& ds = *AnyCast(&_rPreparator[pos]); + SQL_DATE_STRUCT& ds = *AnyCast(&(_pPreparator->at(pos))); Utility::dateSync(val, ds); return true; } @@ -98,7 +98,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::vector& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateSync(val, ds); return true; } @@ -108,7 +108,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::deque& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateSync(val, ds); return true; } @@ -118,7 +118,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::list& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateSync(val, ds); return true; } @@ -129,9 +129,9 @@ bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data:: { if (isNull(pos)) return false; - std::size_t dataSize = _rPreparator.actualDataSize(pos); + std::size_t dataSize = _pPreparator->actualDataSize(pos); checkDataSize(dataSize); - SQL_TIME_STRUCT& ts = *AnyCast(&_rPreparator[pos]); + SQL_TIME_STRUCT& ts = *AnyCast(&_pPreparator->at(pos)); Utility::timeSync(val, ts); return true; @@ -142,7 +142,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::vector& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::timeSync(val, ds); return true; } @@ -152,7 +152,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::deque& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::timeSync(val, ds); return true; } @@ -162,7 +162,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::list& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::timeSync(val, ds); return true; } @@ -173,9 +173,9 @@ bool Extractor::extractBoundImpl(std::size_t pos, Poco::DateTime { if (isNull(pos)) return false; - std::size_t dataSize = _rPreparator.actualDataSize(pos); + std::size_t dataSize = _pPreparator->actualDataSize(pos); checkDataSize(dataSize); - SQL_TIMESTAMP_STRUCT& tss = *AnyCast(&_rPreparator[pos]); + SQL_TIMESTAMP_STRUCT& tss = *AnyCast(&_pPreparator->at(pos)); Utility::dateTimeSync(val, tss); return true; @@ -186,7 +186,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::vector& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateTimeSync(val, ds); return true; } @@ -196,7 +196,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::deque& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateTimeSync(val, ds); return true; } @@ -206,7 +206,7 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::list& val) { - std::vector& ds = RefAnyCast >(_rPreparator[pos]); + std::vector& ds = RefAnyCast >(_pPreparator->at(pos)); Utility::dateTimeSync(val, ds); return true; } @@ -216,8 +216,8 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::vector& val) { - std::size_t length = _rPreparator.getLength(); - bool** p = AnyCast(&_rPreparator[pos]); + std::size_t length = _pPreparator->getLength(); + bool** p = AnyCast(&_pPreparator->at(pos)); val.assign(*p, *p + length); return true; } @@ -227,8 +227,8 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::deque& val) { - std::size_t length = _rPreparator.getLength(); - bool** p = AnyCast(&_rPreparator[pos]); + std::size_t length = _pPreparator->getLength(); + bool** p = AnyCast(&_pPreparator->at(pos)); val.assign(*p, *p + length); return true; } @@ -238,8 +238,8 @@ template<> bool Extractor::extractBoundImplContainer >(std::size_t pos, std::list& val) { - std::size_t length = _rPreparator.getLength(); - bool** p = AnyCast(&_rPreparator[pos]); + std::size_t length = _pPreparator->getLength(); + bool** p = AnyCast(&_pPreparator->at(pos)); val.assign(*p, *p + length); return true; } @@ -248,7 +248,7 @@ bool Extractor::extractBoundImplContainer >(std::size_t pos, template<> bool Extractor::extractManualImpl(std::size_t pos, std::string& val, SQLSMALLINT cType) { - std::size_t maxSize = _rPreparator.getMaxFieldSize(); + std::size_t maxSize = _pPreparator->getMaxFieldSize(); std::size_t fetchedSize = 0; std::size_t totalSize = 0; @@ -304,7 +304,7 @@ bool Extractor::extractManualImpl(std::size_t pos, Poco::Data::CLOB& val, SQLSMALLINT cType) { - std::size_t maxSize = _rPreparator.getMaxFieldSize(); + std::size_t maxSize = _pPreparator->getMaxFieldSize(); std::size_t fetchedSize = 0; std::size_t totalSize = 0; @@ -1209,13 +1209,13 @@ bool Extractor::isNull(std::size_t col, std::size_t row) } } else - return SQL_NULL_DATA == _rPreparator.actualDataSize(col, row); + return SQL_NULL_DATA == _pPreparator->actualDataSize(col, row); } void Extractor::checkDataSize(std::size_t size) { - std::size_t maxSize = _rPreparator.getMaxFieldSize(); + std::size_t maxSize = _pPreparator->getMaxFieldSize(); if (size > maxSize) throw DataException(format(FLD_SIZE_EXCEEDED_FMT, size, maxSize)); } diff --git a/Data/ODBC/src/ODBCStatementImpl.cpp b/Data/ODBC/src/ODBCStatementImpl.cpp index 6ce0963a5..dfe704167 100644 --- a/Data/ODBC/src/ODBCStatementImpl.cpp +++ b/Data/ODBC/src/ODBCStatementImpl.cpp @@ -163,7 +163,7 @@ void ODBCStatementImpl::addPreparator() else _preparations.push_back(new Preparator(*_preparations[0])); - _extractors.push_back(new Extractor(_stmt, *_preparations.back())); + _extractors.push_back(new Extractor(_stmt, _preparations.back())); } @@ -189,10 +189,10 @@ void ODBCStatementImpl::doPrepare() for (std::size_t pos = 0; it != itEnd; ++it) { - AbstractPreparation* pAP = (*it)->createPreparation(_preparations[curDataSet], pos); + Poco::Data::AbstractPreparator::Ptr pP = _preparations[curDataSet]; + std::auto_ptr pAP((*it)->createPreparation(pP, pos)); pAP->prepare(); pos += (*it)->numOfColumnsHandled(); - delete pAP; } _prepared = true; diff --git a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h index 41b53e039..40864e0e7 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h +++ b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h @@ -104,10 +104,10 @@ protected: void bindImpl(); /// Binds parameters - AbstractExtractor& extractor(); + AbstractExtraction::ExtractorPtr extractor(); /// Returns the concrete extractor used by the statement. - AbstractBinder& binder(); + AbstractBinding::BinderPtr binder(); /// Returns the concrete binder used by the statement. private: @@ -144,15 +144,15 @@ private: // // inlines // -inline AbstractExtractor& SQLiteStatementImpl::extractor() +inline AbstractExtraction::ExtractorPtr SQLiteStatementImpl::extractor() { - return *_pExtractor; + return _pExtractor; } -inline AbstractBinder& SQLiteStatementImpl::binder() +inline AbstractBinding::BinderPtr SQLiteStatementImpl::binder() { - return *_pBinder; + return _pBinder; } diff --git a/Data/include/Poco/Data/AbstractBinder.h b/Data/include/Poco/Data/AbstractBinder.h index 7076b50ce..b6387d62f 100644 --- a/Data/include/Poco/Data/AbstractBinder.h +++ b/Data/include/Poco/Data/AbstractBinder.h @@ -74,6 +74,8 @@ class Data_API AbstractBinder /// Interface for Binding data types to placeholders. { public: + typedef SharedPtr Ptr; + enum Direction /// Binding direction for a parameter. { diff --git a/Data/include/Poco/Data/AbstractBinding.h b/Data/include/Poco/Data/AbstractBinding.h index c09c9435a..0a200afd2 100644 --- a/Data/include/Poco/Data/AbstractBinding.h +++ b/Data/include/Poco/Data/AbstractBinding.h @@ -55,10 +55,13 @@ namespace Poco { namespace Data { -class Data_API AbstractBinding: public Poco::RefCountedObject +class Data_API AbstractBinding /// AbstractBinding connects a value with a placeholder via an AbstractBinder interface. { public: + typedef SharedPtr Ptr; + typedef AbstractBinder::Ptr BinderPtr; + enum Direction { PD_IN = AbstractBinder::PD_IN, @@ -72,10 +75,10 @@ public: virtual ~AbstractBinding(); /// Destroys the AbstractBinding. - void setBinder(AbstractBinder* pBinder); + void setBinder(BinderPtr pBinder); /// Sets the object used for binding; object does NOT take ownership of the pointer. - AbstractBinder* getBinder() const; + BinderPtr getBinder() const; /// Returns the AbstractBinder used for binding data. virtual std::size_t numOfColumnsHandled() const = 0; @@ -112,23 +115,22 @@ public: /// Returns the size of the bulk binding. private: - AbstractBinder* _pBinder; - std::string _name; - Direction _direction; - Poco::UInt32 _bulkSize; + BinderPtr _pBinder; + std::string _name; + Direction _direction; + Poco::UInt32 _bulkSize; }; -typedef Poco::AutoPtr AbstractBindingPtr; -typedef std::vector AbstractBindingVec; -typedef std::deque AbstractBindingDeq; -typedef std::list AbstractBindingLst; +typedef std::vector AbstractBindingVec; +typedef std::deque AbstractBindingDeq; +typedef std::list AbstractBindingLst; // // inlines // -inline AbstractBinder* AbstractBinding::getBinder() const +inline AbstractBinder::Ptr AbstractBinding::getBinder() const { return _pBinder; } diff --git a/Data/include/Poco/Data/AbstractExtraction.h b/Data/include/Poco/Data/AbstractExtraction.h index 7e7173531..68b436d19 100644 --- a/Data/include/Poco/Data/AbstractExtraction.h +++ b/Data/include/Poco/Data/AbstractExtraction.h @@ -59,11 +59,15 @@ class AbstractPreparation; class AbstractPreparator; -class Data_API AbstractExtraction: public Poco::RefCountedObject +class Data_API AbstractExtraction /// AbstractExtraction is the interface class that connects output positions to concrete values /// retrieved via an AbstractExtractor. { public: + typedef SharedPtr Ptr; + typedef SharedPtr ExtractorPtr; + typedef SharedPtr PreparatorPtr; + AbstractExtraction(Poco::UInt32 limit = Limit::LIMIT_UNLIMITED, Poco::UInt32 position = 0, bool bulk = false); /// Creates the AbstractExtraction. A limit value equal to EXTRACT_UNLIMITED (0xffffffffu) @@ -73,10 +77,10 @@ public: virtual ~AbstractExtraction(); /// Destroys the AbstractExtraction. - void setExtractor(AbstractExtractor* pExtractor); + void setExtractor(ExtractorPtr pExtractor); /// Sets the class used for extracting the data. Does not take ownership of the pointer. - AbstractExtractor* getExtractor() const; + ExtractorPtr getExtractor() const; /// Retrieves the extractor object Poco::UInt32 position() const; @@ -109,8 +113,9 @@ public: virtual bool canExtract() const; /// Returns true. Implementations should override it for different behavior. - virtual AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) = 0; - /// Creates a Preparation object for the extracting object + virtual AbstractPreparation* createPreparation(PreparatorPtr& pPrep, std::size_t pos) = 0; + /// Creates a Preparation object for the extracting object. The returned pointer points to + /// a preparation object allocated on the heap; caller must take ownership of it. void setLimit(Poco::UInt32 limit); /// Sets the limit. @@ -161,34 +166,33 @@ public: /// - getEmptyStringIsNull() returns true private: - AbstractExtractor* _pExtractor; - Poco::UInt32 _limit; - Poco::UInt32 _position; - bool _bulk; - bool _emptyStringIsNull; - bool _forceEmptyString; + ExtractorPtr _pExtractor; + Poco::UInt32 _limit; + Poco::UInt32 _position; + bool _bulk; + bool _emptyStringIsNull; + bool _forceEmptyString; }; -typedef Poco::AutoPtr AbstractExtractionPtr; -typedef std::vector AbstractExtractionVec; -typedef std::vector AbstractExtractionVecVec; -typedef std::deque AbstractExtractionDeq; -typedef std::vector AbstractExtractionDeqVec; -typedef std::list AbstractExtractionLst; -typedef std::vector AbstractExtractionLstVec; +typedef std::vector AbstractExtractionVec; +typedef std::vector AbstractExtractionVecVec; +typedef std::deque AbstractExtractionDeq; +typedef std::vector AbstractExtractionDeqVec; +typedef std::list AbstractExtractionLst; +typedef std::vector AbstractExtractionLstVec; // // inlines // -inline void AbstractExtraction::setExtractor(AbstractExtractor* pExtractor) +inline void AbstractExtraction::setExtractor(ExtractorPtr pExtractor) { _pExtractor = pExtractor; } -inline AbstractExtractor* AbstractExtraction::getExtractor() const +inline AbstractExtraction::ExtractorPtr AbstractExtraction::getExtractor() const { return _pExtractor; } diff --git a/Data/include/Poco/Data/AbstractExtractor.h b/Data/include/Poco/Data/AbstractExtractor.h index b76cec584..d898948ee 100644 --- a/Data/include/Poco/Data/AbstractExtractor.h +++ b/Data/include/Poco/Data/AbstractExtractor.h @@ -72,6 +72,8 @@ class Data_API AbstractExtractor /// If an extractor receives null it is not allowed to change val! { public: + typedef SharedPtr Ptr; + AbstractExtractor(); /// Creates the AbstractExtractor. diff --git a/Data/include/Poco/Data/AbstractPreparation.h b/Data/include/Poco/Data/AbstractPreparation.h index bd6583545..ac296183c 100644 --- a/Data/include/Poco/Data/AbstractPreparation.h +++ b/Data/include/Poco/Data/AbstractPreparation.h @@ -41,6 +41,8 @@ #include "Poco/Data/Data.h" +#include "Poco/Data/AbstractPreparator.h" +#include "Poco/SharedPtr.h" #include @@ -48,14 +50,14 @@ namespace Poco { namespace Data { -class AbstractPreparator; - - class Data_API AbstractPreparation /// Interface for calling the appropriate AbstractPreparator method { public: - AbstractPreparation(AbstractPreparator* pPreparator); + typedef SharedPtr Ptr; + typedef AbstractPreparator::Ptr PreparatorPtr; + + AbstractPreparation(PreparatorPtr pPreparator); /// Creates the AbstractPreparation. virtual ~AbstractPreparation(); @@ -65,17 +67,17 @@ public: /// Preparations data. protected: - AbstractPreparator* preparation(); + PreparatorPtr preparation(); /// Returns the preparation object - AbstractPreparator* _pPreparator; + PreparatorPtr _pPreparator; }; // // inlines // -inline AbstractPreparator* AbstractPreparation::preparation() +inline AbstractPreparation::PreparatorPtr AbstractPreparation::preparation() { return _pPreparator; } diff --git a/Data/include/Poco/Data/AbstractPreparator.h b/Data/include/Poco/Data/AbstractPreparator.h index be1fa16bd..e4e323bb8 100644 --- a/Data/include/Poco/Data/AbstractPreparator.h +++ b/Data/include/Poco/Data/AbstractPreparator.h @@ -78,6 +78,8 @@ class Data_API AbstractPreparator: public Poco::RefCountedObject /// after SQL execution (e.g. SQLite) do not need this functionality at all. { public: + typedef SharedPtr Ptr; + AbstractPreparator(Poco::UInt32 length = 1u); /// Creates the AbstractPreparator. diff --git a/Data/include/Poco/Data/Binding.h b/Data/include/Poco/Data/Binding.h index 27944c16d..08e54bbf2 100644 --- a/Data/include/Poco/Data/Binding.h +++ b/Data/include/Poco/Data/Binding.h @@ -73,6 +73,10 @@ class Binding: public AbstractBinding /// function. An attempt to pass a constant by reference shall result in compile-time error. { public: + typedef typename T ValType; + typedef Binding Type; + typedef SharedPtr Ptr; + explicit Binding(T& val, const std::string& name = "", Direction direction = PD_IN): @@ -106,7 +110,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); TypeHandler::bind(pos, _val, getBinder(), getDirection()); _bound = true; } @@ -114,8 +118,8 @@ public: void reset () { _bound = false; - AbstractBinder* pBinder = getBinder(); - poco_check_ptr (pBinder); + AbstractBinder::Ptr pBinder = getBinder(); + poco_assert_dbg (!pBinder.isNull()); pBinder->reset(); } @@ -136,10 +140,13 @@ class CopyBinding: public AbstractBinding /// is passed to binding, the storage it refers to must be valid at the statement execution time. /// To pass a copy of a variable, constant or string literal, use utility function bind(). /// Variables can be passed as either copies or references (i.e. using either use() or bind()). - /// Constants, however, can only be passed as copies. this is best achieved using bind() utility - /// function. An attempt to pass a constant by reference shall result in compile-time error. { public: + typedef typename T ValType; + typedef SharedPtr ValPtr; + typedef CopyBinding Type; + typedef SharedPtr Ptr; + explicit CopyBinding(T& val, const std::string& name = "", Direction direction = PD_IN): @@ -173,7 +180,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); TypeHandler::bind(pos, *_pVal, getBinder(), getDirection()); _bound = true; } @@ -181,15 +188,15 @@ public: void reset () { _bound = false; - AbstractBinder* pBinder = getBinder(); - poco_check_ptr (pBinder); + AbstractBinder::Ptr pBinder = getBinder(); + poco_assert_dbg (!pBinder.isNull()); pBinder->reset(); } private: - typedef typename TypeWrapper::TYPE ValueType; - SharedPtr _pVal; - bool _bound; + //typedef typename TypeWrapper::TYPE ValueType; + ValPtr _pVal; + bool _bound; }; @@ -198,6 +205,11 @@ class Binding: public AbstractBinding /// Binding const char* specialization wraps char pointer into string. { public: + typedef const char* ValType; + typedef SharedPtr ValPtr; + typedef Binding Type; + typedef SharedPtr Ptr; + explicit Binding(const char* pVal, const std::string& name = "", Direction direction = PD_IN): @@ -230,7 +242,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); TypeHandler::bind(pos, _val, getBinder(), getDirection()); _bound = true; } @@ -238,8 +250,8 @@ public: void reset () { _bound = false; - AbstractBinder* pBinder = getBinder(); - poco_check_ptr (pBinder); + AbstractBinder::Ptr pBinder = getBinder(); + poco_assert_dbg (!pBinder.isNull()); pBinder->reset(); } @@ -255,6 +267,11 @@ class CopyBinding: public AbstractBinding /// Binding const char* specialization wraps char pointer into string. { public: + typedef const char* ValType; + typedef SharedPtr ValPtr; + typedef CopyBinding Type; + typedef SharedPtr Ptr; + explicit CopyBinding(const char* pVal, const std::string& name = "", Direction direction = PD_IN): @@ -287,7 +304,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); TypeHandler::bind(pos, _val, getBinder(), getDirection()); _bound = true; } @@ -295,8 +312,8 @@ public: void reset () { _bound = false; - AbstractBinder* pBinder = getBinder(); - poco_check_ptr (pBinder); + AbstractBinder::Ptr pBinder = getBinder(); + poco_assert_dbg (!pBinder.isNull()); pBinder->reset(); } @@ -311,6 +328,11 @@ class Binding >: public AbstractBinding /// Specialization for std::vector. { public: + typedef std::vector ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::vector& val, const std::string& name = "", Direction direction = PD_IN): @@ -347,7 +369,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); @@ -361,12 +383,9 @@ public: } private: - typedef std::vector Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -375,6 +394,12 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::vector. { public: + + typedef std::vector ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::vector& val, const std::string& name = "", Direction direction = PD_IN): @@ -411,7 +436,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); @@ -425,13 +450,9 @@ public: } private: - typedef std::vector Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -451,6 +472,11 @@ class Binding >: public AbstractBinding /// Only IN binding is supported. { public: + typedef std::vector ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef ValType::const_iterator Iterator; + explicit Binding(const std::vector& val, const std::string& name = "", Direction direction = PD_IN): @@ -491,7 +517,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -528,6 +554,11 @@ class CopyBinding >: public AbstractBinding /// Only IN binding is supported. { public: + typedef std::vector ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef ValType::const_iterator Iterator; + explicit CopyBinding(const std::vector& val, const std::string& name = "", Direction direction = PD_IN): @@ -568,11 +599,10 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; - } void reset() @@ -593,6 +623,11 @@ class Binding >: public AbstractBinding /// Specialization for std::list. { public: + typedef std::list ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::list& val, const std::string& name = "", Direction direction = PD_IN): @@ -629,7 +664,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -642,12 +677,9 @@ public: } private: - typedef std::list Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -656,7 +688,12 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::list. { public: - explicit CopyBinding(std::list& val, + typedef typename std::list ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + + explicit CopyBinding(ValType& val, const std::string& name = "", Direction direction = PD_IN): AbstractBinding(name, direction), @@ -692,7 +729,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -705,13 +742,9 @@ public: } private: - typedef std::list Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -720,6 +753,11 @@ class Binding >: public AbstractBinding /// Specialization for std::deque. { public: + typedef std::deque ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::deque& val, const std::string& name = "", Direction direction = PD_IN): @@ -756,7 +794,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -769,12 +807,9 @@ public: } private: - typedef std::deque Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -783,6 +818,11 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::deque. { public: + typedef std::deque ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::deque& val, const std::string& name = "", Direction direction = PD_IN): @@ -819,7 +859,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -832,13 +872,9 @@ public: } private: - typedef std::deque Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -847,6 +883,11 @@ class Binding >: public AbstractBinding /// Specialization for std::set. { public: + typedef std::set ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::set& val, const std::string& name = "", Direction direction = PD_IN): @@ -883,7 +924,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -896,12 +937,9 @@ public: } private: - typedef std::set Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -910,6 +948,11 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::set. { public: + typedef std::set ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::set& val, const std::string& name = "", Direction direction = PD_IN): @@ -946,7 +989,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -959,13 +1002,9 @@ public: } private: - typedef std::set Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -974,6 +1013,11 @@ class Binding >: public AbstractBinding /// Specialization for std::multiset. { public: + typedef std::multiset ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::multiset& val, const std::string& name = "", Direction direction = PD_IN): @@ -1010,7 +1054,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -1023,12 +1067,9 @@ public: } private: - typedef std::multiset Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -1037,6 +1078,11 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::multiset. { public: + typedef std::multiset ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::multiset& val, const std::string& name = "", Direction direction = PD_IN): @@ -1073,7 +1119,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, *_begin, getBinder(), getDirection()); ++_begin; @@ -1086,13 +1132,9 @@ public: } private: - typedef std::multiset Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -1101,6 +1143,11 @@ class Binding >: public AbstractBinding /// Specialization for std::map. { public: + typedef std::map ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::map& val, const std::string& name = "", Direction direction = PD_IN): @@ -1137,7 +1184,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, _begin->second, getBinder(), getDirection()); ++_begin; @@ -1150,12 +1197,9 @@ public: } private: - typedef std::map Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -1164,6 +1208,11 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::map. { public: + typedef std::map ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::map& val, const std::string& name = "", Direction direction = PD_IN): @@ -1200,7 +1249,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, _begin->second, getBinder(), getDirection()); ++_begin; @@ -1213,13 +1262,9 @@ public: } private: - typedef std::map Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -1228,6 +1273,11 @@ class Binding >: public AbstractBinding /// Specialization for std::multimap. { public: + typedef std::multimap ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit Binding(std::multimap& val, const std::string& name = "", Direction direction = PD_IN): @@ -1264,7 +1314,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, _begin->second, getBinder(), getDirection()); ++_begin; @@ -1277,12 +1327,9 @@ public: } private: - typedef std::multimap Type; - typedef typename Type::const_iterator Iterator; - - const Type& _val; - Iterator _begin; - Iterator _end; + const ValType& _val; + Iterator _begin; + Iterator _end; }; @@ -1291,6 +1338,11 @@ class CopyBinding >: public AbstractBinding /// Specialization for std::multimap. { public: + typedef std::multimap ValType; + typedef SharedPtr ValPtr; + typedef SharedPtr > Ptr; + typedef typename ValType::const_iterator Iterator; + explicit CopyBinding(std::multimap& val, const std::string& name = "", Direction direction = PD_IN): @@ -1327,7 +1379,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); poco_assert_dbg(canBind()); TypeHandler::bind(pos, _begin->second, getBinder(), getDirection()); ++_begin; @@ -1340,13 +1392,9 @@ public: } private: - typedef std::multimap Type; - typedef SharedPtr TypePtr; - typedef typename Type::const_iterator Iterator; - - TypePtr _pVal; - Iterator _begin; - Iterator _end; + ValPtr _pVal; + Iterator _begin; + Iterator _end; }; @@ -1354,29 +1402,27 @@ namespace Keywords { template -inline Binding* use(T& t, const std::string& name = "") +inline AbstractBinding::Ptr use(T& t, const std::string& name = "") /// Convenience function for a more compact Binding creation. { - // If this test fails with an error, you tried to pass a const ref value to use(). - // Resolve this either by using bind (which will copy the value) or - // if you are sure that the const ref will still exist when execute is called - // (which can be much later!), then use the "useRef" keyword instead + // If this fails to compile, a const ref was passed to use(). + // This can be resolved by either (a) using bind (which will copy the value), + // or (b) if the const ref is guaranteed to exist when execute is called + // (which can be much later!), by using the "useRef" keyword instead poco_static_assert (!IsConst::VALUE); return new Binding(t, name, AbstractBinding::PD_IN); } - -inline Binding* use(const NullData& t, const std::string& name = "") +inline AbstractBinding::Ptr use(const NullData& t, const std::string& name = "") /// NullData overload. { return new Binding(const_cast(t), name, AbstractBinding::PD_IN); } - template -inline Binding* useRef(T& t, const std::string& name = "") +inline AbstractBinding::Ptr useRef(T& t, const std::string& name = "") /// Convenience function for a more compact Binding creation. { return new Binding(t, name, AbstractBinding::PD_IN); @@ -1384,14 +1430,14 @@ inline Binding* useRef(T& t, const std::string& name = "") template -inline Binding* in(T& t, const std::string& name = "") +inline AbstractBinding::Ptr in(T& t, const std::string& name = "") /// Convenience function for a more compact Binding creation. { return use(t, name); } -inline Binding* in(const NullData& t, const std::string& name = "") +inline AbstractBinding::Ptr in(const NullData& t, const std::string& name = "") /// NullData overload. { return use(t, name); @@ -1399,7 +1445,7 @@ inline Binding* in(const NullData& t, const std::string& name = "") template -inline Binding* out(T& t) +inline AbstractBinding::Ptr out(T& t) /// Convenience function for a more compact Binding creation. { poco_static_assert (!IsConst::VALUE); @@ -1408,7 +1454,7 @@ inline Binding* out(T& t) template -inline Binding* io(T& t) +inline AbstractBinding::Ptr io(T& t) /// Convenience function for a more compact Binding creation. { poco_static_assert (!IsConst::VALUE); @@ -1445,7 +1491,7 @@ inline AbstractBindingVec& io(AbstractBindingVec& bv) template -inline CopyBinding* bind(T t, const std::string& name) +inline AbstractBinding::Ptr bind(T t, const std::string& name) /// Convenience function for a more compact Binding creation. /// This funtion differs from use() in its value copy semantics. { @@ -1454,11 +1500,11 @@ inline CopyBinding* bind(T t, const std::string& name) template -inline CopyBinding* bind(T t) +inline AbstractBinding::Ptr bind(T t) /// Convenience function for a more compact Binding creation. /// This funtion differs from use() in its value copy semantics. { - return bind(t, ""); + return Poco::Data::Keywords::bind(t, ""); } diff --git a/Data/include/Poco/Data/BulkBinding.h b/Data/include/Poco/Data/BulkBinding.h index 9981aa878..82de6eee7 100644 --- a/Data/include/Poco/Data/BulkBinding.h +++ b/Data/include/Poco/Data/BulkBinding.h @@ -93,7 +93,7 @@ public: void bind(std::size_t pos) { - poco_assert_dbg(getBinder() != 0); + poco_assert_dbg(!getBinder().isNull()); TypeHandler::bind(pos, _val, getBinder(), getDirection()); _bound = true; } @@ -114,7 +114,7 @@ namespace Keywords { template -BulkBinding >* use(const std::vector& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr use(const std::vector& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::vector. { return new BulkBinding >(t, static_cast(t.size()), name); @@ -122,7 +122,7 @@ BulkBinding >* use(const std::vector& t, BulkFnType, const std template -BulkBinding >* in(const std::vector& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr in(const std::vector& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::vector. { return new BulkBinding >(t, static_cast(t.size()), name); @@ -130,7 +130,7 @@ BulkBinding >* in(const std::vector& t, BulkFnType, const std: template -BulkBinding >* use(const std::deque& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr use(const std::deque& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::deque. { return new BulkBinding >(t, static_cast(t.size()), name); @@ -138,7 +138,7 @@ BulkBinding >* use(const std::deque& t, BulkFnType, const std:: template -BulkBinding >* in(const std::deque& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr in(const std::deque& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::deque. { return new BulkBinding >(t, static_cast(t.size()), name); @@ -146,7 +146,7 @@ BulkBinding >* in(const std::deque& t, BulkFnType, const std::s template -BulkBinding >* use(const std::list& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr use(const std::list& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::list. { return new BulkBinding >(t, static_cast(t.size()), name); @@ -154,7 +154,7 @@ BulkBinding >* use(const std::list& t, BulkFnType, const std::st template -BulkBinding >* in(const std::list& t, BulkFnType, const std::string& name = "") +AbstractBinding::Ptr in(const std::list& t, BulkFnType, const std::string& name = "") /// Convenience function for a more compact BulkBinding creation for std::list. { return new BulkBinding >(t, static_cast(t.size()), name); diff --git a/Data/include/Poco/Data/BulkExtraction.h b/Data/include/Poco/Data/BulkExtraction.h index 6c816894b..031f02510 100644 --- a/Data/include/Poco/Data/BulkExtraction.h +++ b/Data/include/Poco/Data/BulkExtraction.h @@ -128,7 +128,7 @@ public: { } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t col) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t col) { Poco::UInt32 limit = getLimit(); if (limit != _rResult.size()) _rResult.resize(limit); @@ -221,7 +221,7 @@ namespace Keywords { template -BulkExtraction >* into(std::vector& t, const Bulk& bulk, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::vector& t, const Bulk& bulk, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::vector bulk extraction support. { @@ -230,7 +230,7 @@ BulkExtraction >* into(std::vector& t, const Bulk& bulk, const template -BulkExtraction >* into(std::vector& t, BulkFnType, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::vector& t, BulkFnType, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::vector bulk extraction support. { @@ -241,7 +241,7 @@ BulkExtraction >* into(std::vector& t, BulkFnType, const Posit template -BulkExtraction >* into(std::deque& t, const Bulk& bulk, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::deque& t, const Bulk& bulk, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::deque bulk extraction support. { @@ -250,7 +250,7 @@ BulkExtraction >* into(std::deque& t, const Bulk& bulk, const P template -BulkExtraction >* into(std::deque& t, BulkFnType, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::deque& t, BulkFnType, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::deque bulk extraction support. { @@ -261,7 +261,7 @@ BulkExtraction >* into(std::deque& t, BulkFnType, const Positio template -BulkExtraction >* into(std::list& t, const Bulk& bulk, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::list& t, const Bulk& bulk, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::list bulk extraction support. { @@ -270,7 +270,7 @@ BulkExtraction >* into(std::list& t, const Bulk& bulk, const Pos template -BulkExtraction >* into(std::list& t, BulkFnType, const Position& pos = Position(0)) +AbstractExtraction::Ptr into(std::list& t, BulkFnType, const Position& pos = Position(0)) /// Convenience function to allow for a more compact creation of an extraction object /// with std::list bulk extraction support. { diff --git a/Data/include/Poco/Data/Extraction.h b/Data/include/Poco/Data/Extraction.h index ddc709782..cc8476e77 100644 --- a/Data/include/Poco/Data/Extraction.h +++ b/Data/include/Poco/Data/Extraction.h @@ -130,7 +130,7 @@ public: return !_extracted; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _rResult); } @@ -204,7 +204,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -285,7 +285,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -364,7 +364,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -443,7 +443,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -576,7 +576,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -635,7 +635,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -694,7 +694,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -753,7 +753,7 @@ public: return 1u; } - AbstractPreparation* createPreparation(AbstractPreparator* pPrep, std::size_t pos) + AbstractPreparation* createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t pos) { return new Preparation(pPrep, pos, _default); } @@ -768,7 +768,7 @@ namespace Keywords { template -inline Extraction* into(T& t) +inline AbstractExtraction::Ptr into(T& t) /// Convenience function to allow for a more compact creation of an extraction object. { return new Extraction(t); @@ -776,7 +776,7 @@ inline Extraction* into(T& t) template -inline Extraction* into(T& t, const Position& pos) +inline AbstractExtraction::Ptr into(T& t, const Position& pos) /// Convenience function to allow for a more compact creation of an extraction object /// with multiple recordset support. { @@ -785,7 +785,7 @@ inline Extraction* into(T& t, const Position& pos) template -inline Extraction* into(T& t, const Position& pos, const T& def) +inline AbstractExtraction::Ptr into(T& t, const Position& pos, const T& def) /// Convenience function to allow for a more compact creation of an extraction object /// with multiple recordset support and the given default { diff --git a/Data/include/Poco/Data/Preparation.h b/Data/include/Poco/Data/Preparation.h index 82f3031d3..57a7a7245 100644 --- a/Data/include/Poco/Data/Preparation.h +++ b/Data/include/Poco/Data/Preparation.h @@ -56,7 +56,7 @@ class Preparation: public AbstractPreparation /// Class for calling the appropriate AbstractPreparator method. { public: - Preparation(AbstractPreparator* pPreparator, std::size_t pos, T& val): + Preparation(AbstractPreparator::Ptr& pPreparator, std::size_t pos, T& val): AbstractPreparation(pPreparator), _pos(pos), _val(val) diff --git a/Data/include/Poco/Data/Statement.h b/Data/include/Poco/Data/Statement.h index 3f801d800..cc02e96fd 100644 --- a/Data/include/Poco/Data/Statement.h +++ b/Data/include/Poco/Data/Statement.h @@ -42,6 +42,7 @@ #include "Poco/Data/Data.h" #include "Poco/Data/StatementImpl.h" +#include "Poco/Data/Binding.h" #include "Poco/Data/Range.h" #include "Poco/Data/Bulk.h" #include "Poco/Data/Row.h" @@ -82,8 +83,8 @@ class Data_API Statement /// /// Once asyncronous, a statement can be reverted back to synchronous state in two ways: /// - /// 1) By calling setAsync(false) - /// 2) By means of 'sync' or 'reset' manipulators + /// 1) By calling setAsync(false) + /// 2) By means of 'sync' or 'reset' manipulators /// /// See individual functions documentation for more details. /// @@ -110,7 +111,7 @@ public: STORAGE_UNKNOWN = StatementImpl::STORAGE_UNKNOWN_IMPL }; - Statement(StatementImpl* pImpl); + Statement(StatementImpl::Ptr pImpl); /// Creates the Statement. explicit Statement(Session& session); @@ -153,19 +154,11 @@ public: Statement& operator , (Manipulator manip); /// Handles manipulators, such as now, async, etc. - Statement& operator , (AbstractBinding* bind); + Statement& operator , (AbstractBinding::Ptr pBind); /// Registers the Binding with the Statement by calling addBind(). - /// Statement takes the ownership of the bind in an AutoPtr. - /// To prevent bind destruction upon statement destruction, pass an - /// AutoPtr::duplicate() to this function. - /// This function is primarily intended to be a destination for - /// use() and bind() utility functions return value, so it is - /// recommended to call addBind() directly instead. - Statement& addBind(AbstractBinding* pBind, bool duplicate = true); + Statement& addBind(AbstractBinding::Ptr pBind); /// Registers a single binding with the statement. - /// To allow the binding to outlive the statement destruction, - /// duplicate must be true. void removeBind(const std::string& name); /// Removes the all the bindings with specified name from the statement. @@ -173,20 +166,20 @@ public: Statement& operator , (AbstractBindingVec& bindVec); /// Registers the Binding vector with the Statement. - Statement& operator , (AbstractExtraction* extract); + template + Statement& addBinding(C& bindingCont, bool reset) + /// Registers binding container with the Statement. + { + if (reset) _pImpl->resetBinding(); + typename C::iterator itAB = bindingCont.begin(); + typename C::iterator itABEnd = bindingCont.end(); + for (; itAB != itABEnd; ++itAB) addBind(*itAB); + return *this; + } + + Statement& operator , (AbstractExtraction::Ptr extract); /// Registers objects used for extracting data with the Statement by /// calling addExtract(). - /// Statement takes the ownership of the extract in an AutoPtr. - /// To prevent extract destruction upon statement destruction, pass an - /// AutoPtr::duplicate() to this function. - /// This function is primarily intended to be a destination for - /// into() utility function return value, so it is recommended to call - /// addExtract() directly instead. - - Statement& addExtract(AbstractExtraction* pExtract, bool duplicate = true); - /// Registers a single extraction with the statement. - /// To allow the extraction to outlive the statement destruction, - /// duplicate must be true. Statement& operator , (AbstractExtractionVec& extVec); /// Registers the extraction vector with the Statement. @@ -195,17 +188,6 @@ public: Statement& operator , (AbstractExtractionVecVec& extVecVec); /// Registers the vector of extraction vectors with the Statement. - template - Statement& addBinding(C& bindingCont, bool reset) - /// Registers binding container with the Statement. - { - if (reset) _pImpl->resetBinding(); - typename C::iterator itAB = bindingCont.begin(); - typename C::iterator itABEnd = bindingCont.end(); - for (; itAB != itABEnd; ++itAB) addBind(itAB->duplicate()); - return *this; - } - template Statement& addExtraction(C& val, bool reset) /// Registers extraction container with the Statement. @@ -213,7 +195,7 @@ public: if (reset) _pImpl->resetExtraction(); typename C::iterator itAE = val.begin(); typename C::iterator itAEEnd = val.end(); - for (; itAE != itAEEnd; ++itAE) addExtract(itAE->duplicate()); + for (; itAE != itAEEnd; ++itAE) addExtract(*itAE); return *this; } @@ -228,7 +210,9 @@ public: return *this; } - + Statement& addExtract(AbstractExtraction::Ptr pExtract); + /// Registers a single extraction with the statement. + Statement& operator , (const Bulk& bulk); /// Sets the bulk execution mode (both binding and extraction) for this /// statement.Statement must not have any extractors or binders set at the @@ -406,7 +390,7 @@ public: /// Statement takes the ownership of the formatter. protected: - typedef Poco::AutoPtr StatementImplPtr; + typedef StatementImpl::Ptr ImplPtr; const AbstractExtractionVec& extractions() const; /// Returns the extractions vector. @@ -423,7 +407,7 @@ protected: bool isBulkExtraction() const; /// Returns true if this statement extracts data in bulk. - StatementImplPtr impl() const; + ImplPtr impl() const; /// Returns pointer to statement implementation. const RowFormatterPtr& getRowFormatter(); @@ -433,6 +417,7 @@ protected: /// Returns the underlying session. private: + const Result& doAsyncExec(bool reset = true); /// Asynchronously executes the statement. @@ -443,7 +428,7 @@ private: return *this; } - StatementImplPtr _pImpl; + StatementImpl::Ptr _pImpl; // asynchronous execution related members bool _async; @@ -656,9 +641,9 @@ inline void Statement::removeBind(const std::string& name) } -inline Statement& Statement::operator , (AbstractBinding* pBind) +inline Statement& Statement::operator , (AbstractBinding::Ptr pBind) { - return addBind(pBind, false); + return addBind(pBind); } @@ -668,9 +653,9 @@ inline Statement& Statement::operator , (AbstractBindingVec& bindVec) } -inline Statement& Statement::operator , (AbstractExtraction* pExtract) +inline Statement& Statement::operator , (AbstractExtraction::Ptr pExtract) { - return addExtract(pExtract, false); + return addExtract(pExtract); } @@ -686,7 +671,7 @@ inline Statement& Statement::operator , (AbstractExtractionVecVec& extVecVec) } -inline Statement::StatementImplPtr Statement::impl() const +inline Statement::ImplPtr Statement::impl() const { return _pImpl; } diff --git a/Data/include/Poco/Data/StatementImpl.h b/Data/include/Poco/Data/StatementImpl.h index f3d57f9e0..cc3c23e27 100644 --- a/Data/include/Poco/Data/StatementImpl.h +++ b/Data/include/Poco/Data/StatementImpl.h @@ -50,7 +50,6 @@ #include "Poco/Data/BulkExtraction.h" #include "Poco/Data/SessionImpl.h" #include "Poco/RefCountedObject.h" -#include "Poco/AutoPtr.h" #include "Poco/String.h" #include "Poco/Format.h" #include "Poco/Exception.h" @@ -65,12 +64,14 @@ namespace Poco { namespace Data { -class Data_API StatementImpl: public Poco::RefCountedObject +class Data_API StatementImpl /// StatementImpl interface that subclasses must implement to define database dependent query execution. /// /// StatementImpl's are noncopyable. { public: + typedef Poco::SharedPtr Ptr; + enum State { ST_INITIALIZED, @@ -127,14 +128,14 @@ public: _ostr << t; } - void addBind(AbstractBinding* pBinding); + void addBind(AbstractBinding::Ptr pBinding); /// Registers the Binding with the StatementImpl. void removeBind(const std::string& name); /// Unregisters all the bindings having specified name with the StatementImpl. /// Bindings are released and, if this class was the sole owner, deleted. - void addExtract(AbstractExtraction* pExtraction); + void addExtract(AbstractExtraction::Ptr pExtraction); /// Registers objects used for extracting data with the StatementImpl. void setExtractionLimit(const Limit& extrLimit); @@ -216,14 +217,23 @@ protected: virtual void bindImpl() = 0; /// Binds parameters. - virtual AbstractExtractor& extractor() = 0; + virtual AbstractExtraction::ExtractorPtr extractor() = 0; /// Returns the concrete extractor used by the statement. const AbstractExtractionVec& extractions() const; - /// Returns the extractions vector. + /// Returns the const reference to extractions vector. - virtual AbstractBinder& binder() = 0; - /// Returns the concrete binder used by the statement. + AbstractExtractionVec& extractions(); + /// Returns the reference to extractions vector. + + void fixupExtraction(); + /// Sets the AbstractExtractor at the extractors. + + std::size_t getExtractionLimit(); + /// Returns the extraction limit value. + + const Limit& extractionLimit() const; + /// Returns the extraction limit. std::size_t columnsExtracted(int dataSet = USE_CURRENT_DATA_SET) const; /// Returns the number of columns that the extractors handle. @@ -236,15 +246,6 @@ protected: /// Returns the number of rows extracted so far for the data set. /// Default value indicates current data set (if any). - const AbstractBindingVec& bindings() const; - /// Returns the bindings. - - AbstractBindingVec& bindings(); - /// Returns the bindings. - - AbstractExtractionVec& extractions(); - /// Returns the extractions vector. - void makeExtractors(std::size_t count); /// Determines the type of the internal extraction container and /// calls the extraction creation function (addInternalExtract) @@ -270,6 +271,15 @@ protected: SessionImpl& session(); /// Rteurns session associated with this statement. + virtual AbstractBinding::BinderPtr binder() = 0; + /// Returns the concrete binder used by the statement. + + const AbstractBindingVec& bindings() const; + /// Returns the const reference to bindings vector. + + AbstractBindingVec& bindings(); + /// Returns the reference to bindings. + void fixupBinding(); /// Sets the AbstractBinder at the bindings. @@ -290,9 +300,6 @@ protected: /// When connector-specific behavior is desired, it should be overriden /// by the statement implementation. - void fixupExtraction(); - /// Sets the AbstractExtractor at the extractors. - std::size_t currentDataSet() const; /// Returns the current data set. @@ -307,12 +314,6 @@ protected: bool hasMoreDataSets() const; /// Returns true if there are data sets not activated yet. - std::size_t getExtractionLimit(); - /// Returns the extraction limit value. - - const Limit& extractionLimit() const; - /// Returns the extraction limit. - private: void compile(); /// Compiles the statement. @@ -472,7 +473,7 @@ private: // -inline void StatementImpl::addBind(AbstractBinding* pBinding) +inline void StatementImpl::addBind(AbstractBinding::Ptr pBinding) { poco_check_ptr (pBinding); _bindings.push_back(pBinding); diff --git a/Data/src/AbstractBinding.cpp b/Data/src/AbstractBinding.cpp index 17a8a042f..44bea3f06 100644 --- a/Data/src/AbstractBinding.cpp +++ b/Data/src/AbstractBinding.cpp @@ -57,7 +57,7 @@ AbstractBinding::~AbstractBinding() } -void AbstractBinding::setBinder(AbstractBinder* pBinder) +void AbstractBinding::setBinder(BinderPtr pBinder) { poco_check_ptr (pBinder); _pBinder = pBinder; diff --git a/Data/src/AbstractPreparation.cpp b/Data/src/AbstractPreparation.cpp index 914e7b826..c407681aa 100644 --- a/Data/src/AbstractPreparation.cpp +++ b/Data/src/AbstractPreparation.cpp @@ -41,7 +41,7 @@ namespace Poco { namespace Data { -AbstractPreparation::AbstractPreparation(AbstractPreparator* pPreparator): +AbstractPreparation::AbstractPreparation(PreparatorPtr pPreparator): _pPreparator(pPreparator) { poco_assert_dbg (_pPreparator); diff --git a/Data/src/RecordSet.cpp b/Data/src/RecordSet.cpp index f11aae925..4ae213518 100644 --- a/Data/src/RecordSet.cpp +++ b/Data/src/RecordSet.cpp @@ -81,7 +81,7 @@ RecordSet::RecordSet(Session& rSession, RecordSet::RecordSet(const RecordSet& other): - Statement(other.impl().duplicate()), + Statement(other.impl()), _currentRow(other._currentRow), _pBegin(new RowIterator(this, 0 == rowsExtracted())), _pEnd(new RowIterator(this, true)), diff --git a/Data/src/Statement.cpp b/Data/src/Statement.cpp index b0e0c736c..df31345de 100644 --- a/Data/src/Statement.cpp +++ b/Data/src/Statement.cpp @@ -49,7 +49,7 @@ namespace Poco { namespace Data { -Statement::Statement(StatementImpl* pImpl): +Statement::Statement(StatementImpl::Ptr pImpl): _pImpl(pImpl), _async(false) { @@ -207,7 +207,7 @@ Statement& Statement::operator , (Manipulator manip) } -Statement& Statement::addBind(AbstractBinding* pBind, bool duplicate) +Statement& Statement::addBind(AbstractBinding::Ptr pBind) { if (pBind->isBulk()) { @@ -221,13 +221,12 @@ Statement& Statement::addBind(AbstractBinding* pBind, bool duplicate) } else _pImpl->forbidBulk(); - if (duplicate) pBind->duplicate(); _pImpl->addBind(pBind); return *this; } -Statement& Statement::addExtract(AbstractExtraction* pExtract, bool duplicate) +Statement& Statement::addExtract(AbstractExtraction::Ptr pExtract) { if (pExtract->isBulk()) { @@ -244,7 +243,6 @@ Statement& Statement::addExtract(AbstractExtraction* pExtract, bool duplicate) } else _pImpl->forbidBulk(); - if (duplicate) pExtract->duplicate(); _pImpl->addExtract(pExtract); return *this; } diff --git a/Data/src/StatementImpl.cpp b/Data/src/StatementImpl.cpp index 0c8ba0995..154e5777f 100644 --- a/Data/src/StatementImpl.cpp +++ b/Data/src/StatementImpl.cpp @@ -264,10 +264,9 @@ void StatementImpl::fixupExtraction() Poco::Data::AbstractExtractionVec::iterator it = extractions().begin(); Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end(); - AbstractExtractor& ex = extractor(); for (; it != itEnd; ++it) { - (*it)->setExtractor(&ex); + (*it)->setExtractor(extractor()); (*it)->setLimit(_extrLimit.value()), _columnsExtracted[_curDataSet] += (int)(*it)->numOfColumnsHandled(); } @@ -279,8 +278,7 @@ void StatementImpl::fixupBinding() // no need to call binder().reset(); here will be called before each bind anyway AbstractBindingVec::iterator it = bindings().begin(); AbstractBindingVec::iterator itEnd = bindings().end(); - AbstractBinder& bin = binder(); - for (; it != itEnd; ++it) (*it)->setBinder(&bin); + for (; it != itEnd; ++it) (*it)->setBinder(binder()); } @@ -395,7 +393,7 @@ std::size_t StatementImpl::activatePreviousDataSet() } -void StatementImpl::addExtract(AbstractExtraction* pExtraction) +void StatementImpl::addExtract(AbstractExtraction::Ptr pExtraction) { poco_check_ptr (pExtraction); std::size_t pos = pExtraction->position(); diff --git a/Data/testsuite/src/DataTest.cpp b/Data/testsuite/src/DataTest.cpp index f06fe416c..31fcb0543 100644 --- a/Data/testsuite/src/DataTest.cpp +++ b/Data/testsuite/src/DataTest.cpp @@ -1346,43 +1346,41 @@ void DataTest::testExternalBindingAndExtraction() Session tmp (Poco::Data::Test::Connector::KEY, "dummy.db"); int i; - AbstractExtraction* pExt1 = into(i); - AbstractExtraction* pExt2 = into(i); - assert (1 == pExt1->referenceCount()); - assert (1 == pExt2->referenceCount()); + AbstractExtraction::Ptr pExt1 = into(i); + AbstractExtraction::Ptr pExt2 = into(i); + assert (1 == pExt1.referenceCount()); + assert (1 == pExt2.referenceCount()); { Statement stmt(tmp); - stmt.addExtract(pExt1); // retain external ownership in addition to giving it to statement - assert (2 == pExt1->referenceCount()); - stmt.addExtract(pExt2, false); // give ownership to statement - assert (1 == pExt2->referenceCount()); + stmt.addExtract(pExt1); + assert (2 == pExt1.referenceCount()); } - assert (1 == pExt1->referenceCount()); delete pExt1; - // pExt2 does not exist any more + assert (1 == pExt1.referenceCount()); + assert (1 == pExt2.referenceCount()); - AbstractBinding* pBind1 = use(i, "mybind1"); - AbstractBinding* pBind2 = use(i, "mybind2"); - AbstractBinding* pBind3 = use(i, "mybind3"); - assert (1 == pBind1->referenceCount()); - assert (1 == pBind2->referenceCount()); - assert (1 == pBind3->referenceCount()); + AbstractBinding::Ptr pBind1 = use(i, "mybind1"); + AbstractBinding::Ptr pBind2 = use(i, "mybind2"); + AbstractBinding::Ptr pBind3 = use(i, "mybind3"); + assert (1 == pBind1.referenceCount()); + assert (1 == pBind2.referenceCount()); + assert (1 == pBind3.referenceCount()); { Statement stmt(tmp); - stmt.addBind(pBind1); // retain external ownership in addition to giving it to statement - assert (2 == pBind1->referenceCount()); - stmt.addBind(pBind2, false);// give ownership to statement - assert (1 == pBind2->referenceCount()); - stmt.addBind(pBind3);// give ownership to statement - assert (2 == pBind3->referenceCount()); - stmt.removeBind(pBind3->name());// take ownership from statement - assert (1 == pBind3->referenceCount()); + stmt.addBind(pBind1); + assert (2 == pBind1.referenceCount()); + stmt.removeBind(pBind1->name()); + assert (1 == pBind1.referenceCount()); + stmt.addBind(pBind2); + assert (2 == pBind2.referenceCount()); + stmt.addBind(pBind3); + assert (2 == pBind3.referenceCount()); try { stmt.removeBind("a bad name"); fail("must fail"); } catch (NotFoundException&) { } } - assert (1 == pBind1->referenceCount()); delete pBind1; - // pBind2 does not exist any more - assert (1 == pBind3->referenceCount()); delete pBind3; + assert (1 == pBind1.referenceCount()); + assert (1 == pBind2.referenceCount()); + assert (1 == pBind3.referenceCount()); } diff --git a/Data/testsuite/src/TestStatementImpl.h b/Data/testsuite/src/TestStatementImpl.h index f8650286a..1374d879b 100644 --- a/Data/testsuite/src/TestStatementImpl.h +++ b/Data/testsuite/src/TestStatementImpl.h @@ -92,10 +92,10 @@ protected: void bindImpl(); /// Binds parameters - AbstractExtractor& extractor(); + AbstractExtraction::ExtractorPtr extractor(); /// Returns the concrete extractor used by the statement. - AbstractBinder& binder(); + AbstractBinding::BinderPtr binder(); /// Returns the concrete binder used by the statement. private: @@ -109,15 +109,15 @@ private: // // inlines // -inline AbstractExtractor& TestStatementImpl::extractor() +inline AbstractExtraction::ExtractorPtr TestStatementImpl::extractor() { - return *_ptrExtractor; + return _ptrExtractor; } -inline AbstractBinder& TestStatementImpl::binder() +inline AbstractBinding::BinderPtr TestStatementImpl::binder() { - return *_ptrBinder; + return _ptrBinder; }