- fixed bug in SQLite Extractor (DateTime extraction not returning false when value is NullPointerException, see http://pocoproject.org/forum/viewtopic.php?f=12&t=5141#p9363 )

- fixed code indentation (spaces to tabs)
This commit is contained in:
Aleksandar Fabijanic 2012-08-23 02:34:35 +00:00
parent 0ca3bbc848
commit dbda035719
18 changed files with 866 additions and 771 deletions

View File

@ -681,6 +681,7 @@ CppUnit::Test* ODBCDB2Test::suite()
CppUnit_addTest(pSuite, ODBCDB2Test, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransactor);
CppUnit_addTest(pSuite, ODBCDB2Test, testNullable);
CppUnit_addTest(pSuite, ODBCDB2Test, testReconnect);
return pSuite;

View File

@ -497,6 +497,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCMySQLTest, testNullable);
CppUnit_addTest(pSuite, ODBCMySQLTest, testReconnect);
return pSuite;

View File

@ -933,6 +933,7 @@ CppUnit::Test* ODBCOracleTest::suite()
CppUnit_addTest(pSuite, ODBCOracleTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransactor);
CppUnit_addTest(pSuite, ODBCOracleTest, testNullable);
CppUnit_addTest(pSuite, ODBCOracleTest, testReconnect);
return pSuite;

View File

@ -659,6 +659,7 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNullable);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
return pSuite;

View File

@ -809,6 +809,7 @@ CppUnit::Test* ODBCSQLServerTest::suite()
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testNullable);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect);
return pSuite;

View File

@ -1204,6 +1204,21 @@ void ODBCTest::testTransactor()
}
void ODBCTest::testNullable()
{
if (!_pSession) fail ("Test not available.");
for (int i = 0; i < 8;)
{
recreatePersonTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->nullable();
i += 2;
}
}
void ODBCTest::testReconnect()
{
if (!_pSession) fail ("Test not available.");

View File

@ -167,6 +167,7 @@ public:
virtual void testSessionTransaction();
virtual void testTransaction();
virtual void testTransactor();
virtual void testNullable();
virtual void testReconnect();

View File

@ -107,6 +107,7 @@ using Poco::Message;
using Poco::NotFoundException;
using Poco::InvalidAccessException;
using Poco::InvalidArgumentException;
using Poco::NotImplementedException;
using Poco::BadCastException;
using Poco::RangeException;
@ -3786,6 +3787,12 @@ void SQLExecutor::transactor()
}
void SQLExecutor::nullable()
{
throw NotImplementedException("TODO - see SQLite test for nullable");
}
void SQLExecutor::reconnect()
{
std::string funct = "reconnect()";

View File

@ -518,6 +518,7 @@ public:
void sessionTransaction(const std::string& connect);
void transaction(const std::string& connect);
void transactor();
void nullable();
void reconnect();

View File

@ -1,262 +1,252 @@
//
// Extractor.cpp
//
//
// Extractor.cpp
//
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
//
//
// Library: SQLite
// Package: SQLite
// Module: Extractor
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SQLite/Extractor.h"
#include "Poco/Data/SQLite/Utility.h"
// Package: SQLite
// Module: Extractor
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SQLite/Extractor.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/DataException.h"
#include "Poco/DateTimeParser.h"
#include "Poco/Exception.h"
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
#include <cstdlib>
#include "Poco/Exception.h"
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
#include <cstdlib>
using Poco::DateTimeParser;
namespace Poco {
namespace Data {
namespace SQLite {
Extractor::Extractor(sqlite3_stmt* pStmt):
_pStmt(pStmt)
{
}
Extractor::~Extractor()
{
}
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int64(_pStmt, (int) pos);
return true;
}
namespace Poco {
namespace Data {
namespace SQLite {
Extractor::Extractor(sqlite3_stmt* pStmt):
_pStmt(pStmt)
{
}
Extractor::~Extractor()
{
}
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int64(_pStmt, (int) pos);
return true;
}
#ifndef POCO_LONG_IS_64_BIT
bool Extractor::extract(std::size_t pos, long& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
#endif
bool Extractor::extract(std::size_t pos, double& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_double(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, std::string& val)
{
if (isNull(pos))
return false;
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
if (!pBuf)
val.clear();
else
val = std::string(pBuf);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
{
if (isNull(pos))
return false;
val = sqlite3_column_int64(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, bool& val)
{
if (isNull(pos))
return false;
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
return true;
}
bool Extractor::extract(std::size_t pos, float& val)
{
if (isNull(pos))
return false;
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
return true;
}
bool Extractor::extract(std::size_t pos, char& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Date& val)
{
std::string str;
extract(pos, str);
int tzd;
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
val = dt;
return true;
bool Extractor::extract(std::size_t pos, double& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_double(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, std::string& val)
{
if (isNull(pos)) return false;
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
if (!pBuf)
val.clear();
else
val = std::string(pBuf);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int64(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, bool& val)
{
if (isNull(pos)) return false;
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
return true;
}
bool Extractor::extract(std::size_t pos, float& val)
{
if (isNull(pos)) return false;
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
return true;
}
bool Extractor::extract(std::size_t pos, char& val)
{
if (isNull(pos)) return false;
val = sqlite3_column_int(_pStmt, (int) pos);
return true;
}
bool Extractor::extract(std::size_t pos, Date& val)
{
if (isNull(pos)) return false;
std::string str;
extract(pos, str);
int tzd;
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
val = dt;
return true;
}
bool Extractor::extract(std::size_t pos, Time& val)
{
std::string str;
extract(pos, str);
int tzd;
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
val = dt;
return true;
}
{
if (isNull(pos)) return false;
std::string str;
extract(pos, str);
int tzd;
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
val = dt;
return true;
}
bool Extractor::extract(std::size_t pos, DateTime& val)
{
std::string dt;
extract(pos, dt);
int tzd;
DateTimeParser::parse(dt, val, tzd);
return true;
}
{
if (isNull(pos)) return false;
std::string dt;
extract(pos, dt);
int tzd;
DateTimeParser::parse(dt, val, tzd);
return true;
}
bool Extractor::extract(std::size_t pos, Poco::Any& val)
{
return extractImpl(pos, val);
}
{
return extractImpl(pos, val);
}
bool Extractor::extract(std::size_t pos, Poco::DynamicAny& val)
{
return extractImpl(pos, val);
}
{
return extractImpl(pos, val);
}
bool Extractor::isNull(std::size_t pos, std::size_t)
{
if (pos >= _nulls.size())
_nulls.resize(pos + 1);
if (!_nulls[pos].first)
{
_nulls[pos].first = true;
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
}
return _nulls[pos].second;
}
} } } // namespace Poco::Data::SQLite
if (pos >= _nulls.size())
_nulls.resize(pos + 1);
if (!_nulls[pos].first)
{
_nulls[pos].first = true;
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
}
return _nulls[pos].second;
}
} } } // namespace Poco::Data::SQLite

View File

@ -1,311 +1,311 @@
//
// SQLiteStatementImpl.cpp
//
//
// SQLiteStatementImpl.cpp
//
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
//
//
// Library: SQLite
// Package: SQLite
// Module: SQLiteStatementImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/String.h"
#include <cstdlib>
#include <cstring>
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
namespace Poco {
namespace Data {
namespace SQLite {
// Package: SQLite
// Module: SQLiteStatementImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/String.h"
#include <cstdlib>
#include <cstring>
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
namespace Poco {
namespace Data {
namespace SQLite {
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
StatementImpl(rSession),
_pDB(pDB),
_pStmt(0),
_stepCalled(false),
_nextResponse(0),
_affectedRowCount(0),
_canBind(false),
_isExtracted(false),
_canCompile(true)
{
_columns.resize(1);
}
SQLiteStatementImpl::~SQLiteStatementImpl()
{
clear();
}
void SQLiteStatementImpl::compileImpl()
{
if (!_pLeftover) _bindBegin = bindings().begin();
std::string statement(toString());
sqlite3_stmt* pStmt = 0;
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
StatementImpl(rSession),
_pDB(pDB),
_pStmt(0),
_stepCalled(false),
_nextResponse(0),
_affectedRowCount(0),
_canBind(false),
_isExtracted(false),
_canCompile(true)
{
_columns.resize(1);
}
if (0 == std::strlen(pSql))
throw InvalidSQLStatementException("Empty statements are illegal");
int rc = SQLITE_OK;
const char* pLeftover = 0;
bool queryFound = false;
do
{
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
if (rc != SQLITE_OK)
{
if (pStmt) sqlite3_finalize(pStmt);
pStmt = 0;
std::string errMsg = sqlite3_errmsg(_pDB);
Utility::throwException(rc, errMsg);
}
else if (rc == SQLITE_OK && pStmt)
{
queryFound = true;
}
else if (rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
{
pSql = pLeftover;
if (std::strlen(pSql) == 0)
{
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
// this is valid
queryFound = true;
}
}
} while (rc == SQLITE_OK && !pStmt && !queryFound);
//Finalization call in clear() invalidates the pointer, so the value is remembered here.
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
// to compileImpl() shall return false immediately when there are no more statements left.
std::string leftOver(pLeftover);
trimInPlace(leftOver);
clear();
_pStmt = pStmt;
if (!leftOver.empty())
{
_pLeftover = new std::string(leftOver);
_canCompile = true;
}
else _canCompile = false;
_pBinder = new Binder(_pStmt);
_pExtractor = new Extractor(_pStmt);
if (SQLITE_DONE == _nextResponse && _isExtracted)
{
//if this is not the first compile and there has already been extraction
//during previous step, switch to the next set if there is one provided
if (hasMoreDataSets())
{
activateNextDataSet();
_isExtracted = false;
}
}
SQLiteStatementImpl::~SQLiteStatementImpl()
{
clear();
}
int colCount = sqlite3_column_count(_pStmt);
if (colCount)
{
std::size_t curDataSet = currentDataSet();
if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
for (int i = 0; i < colCount; ++i)
{
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
_columns[curDataSet].push_back(mc);
}
}
}
void SQLiteStatementImpl::bindImpl()
{
_stepCalled = false;
_nextResponse = 0;
if (_pStmt == 0) return;
sqlite3_reset(_pStmt);
int paramCount = sqlite3_bind_parameter_count(_pStmt);
BindIt bindEnd = bindings().end();
if (0 == paramCount || bindEnd == _bindBegin)
{
_canBind = false;
return;
}
int availableCount = 0;
Bindings::difference_type bindCount = 0;
Bindings::iterator it = _bindBegin;
for (; it != bindEnd; ++it)
{
availableCount += (*it)->numOfColumnsHandled();
if (availableCount <= paramCount) ++bindCount;
else break;
}
Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
if (bindCount < remainingBindCount)
{
bindEnd = _bindBegin + bindCount;
_canBind = true;
}
else if (bindCount > remainingBindCount)
throw ParameterCountMismatchException();
if (_bindBegin != bindings().end())
{
_affectedRowCount = (*_bindBegin)->numOfRowsHandled();
void SQLiteStatementImpl::compileImpl()
{
if (!_pLeftover) _bindBegin = bindings().begin();
Bindings::iterator oldBegin = _bindBegin;
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
{
if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
std::string statement(toString());
sqlite3_stmt* pStmt = 0;
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
(*_bindBegin)->bind(pos);
pos += (*_bindBegin)->numOfColumnsHandled();
}
if (0 == std::strlen(pSql))
throw InvalidSQLStatementException("Empty statements are illegal");
int rc = SQLITE_OK;
const char* pLeftover = 0;
bool queryFound = false;
do
{
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
if (rc != SQLITE_OK)
{
if (pStmt) sqlite3_finalize(pStmt);
pStmt = 0;
std::string errMsg = sqlite3_errmsg(_pDB);
Utility::throwException(rc, errMsg);
}
else if (rc == SQLITE_OK && pStmt)
{
queryFound = true;
}
else if (rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
{
pSql = pLeftover;
if (std::strlen(pSql) == 0)
{
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
// this is valid
queryFound = true;
}
}
} while (rc == SQLITE_OK && !pStmt && !queryFound);
//Finalization call in clear() invalidates the pointer, so the value is remembered here.
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
// to compileImpl() shall return false immediately when there are no more statements left.
std::string leftOver(pLeftover);
trimInPlace(leftOver);
clear();
_pStmt = pStmt;
if (!leftOver.empty())
{
_pLeftover = new std::string(leftOver);
_canCompile = true;
}
else _canCompile = false;
_pBinder = new Binder(_pStmt);
_pExtractor = new Extractor(_pStmt);
if (SQLITE_DONE == _nextResponse && _isExtracted)
{
//if this is not the first compile and there has already been extraction
//during previous step, switch to the next set if there is one provided
if (hasMoreDataSets())
{
activateNextDataSet();
_isExtracted = false;
}
}
int colCount = sqlite3_column_count(_pStmt);
if (colCount)
{
std::size_t curDataSet = currentDataSet();
if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
for (int i = 0; i < colCount; ++i)
{
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
_columns[curDataSet].push_back(mc);
}
}
}
void SQLiteStatementImpl::bindImpl()
{
_stepCalled = false;
_nextResponse = 0;
if (_pStmt == 0) return;
sqlite3_reset(_pStmt);
int paramCount = sqlite3_bind_parameter_count(_pStmt);
BindIt bindEnd = bindings().end();
if (0 == paramCount || bindEnd == _bindBegin)
{
_canBind = false;
return;
}
int availableCount = 0;
Bindings::difference_type bindCount = 0;
Bindings::iterator it = _bindBegin;
for (; it != bindEnd; ++it)
{
availableCount += (*it)->numOfColumnsHandled();
if (availableCount <= paramCount) ++bindCount;
else break;
}
Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
if (bindCount < remainingBindCount)
{
bindEnd = _bindBegin + bindCount;
_canBind = true;
}
else if (bindCount > remainingBindCount)
throw ParameterCountMismatchException();
if (_bindBegin != bindings().end())
{
_affectedRowCount = (*_bindBegin)->numOfRowsHandled();
Bindings::iterator oldBegin = _bindBegin;
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
{
if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
(*_bindBegin)->bind(pos);
pos += (*_bindBegin)->numOfColumnsHandled();
}
if ((*oldBegin)->canBind())
{
//container binding will come back for more, so we must rewind
_bindBegin = oldBegin;
_canBind = true;
}
else _canBind = false;
}
}
void SQLiteStatementImpl::clear()
{
_columns[currentDataSet()].clear();
_affectedRowCount = 0;
if (_pStmt)
{
sqlite3_finalize(_pStmt);
_pStmt=0;
}
_pLeftover = 0;
}
bool SQLiteStatementImpl::hasNext()
{
if (_stepCalled)
return (_nextResponse == SQLITE_ROW);
// _pStmt is allowed to be null for conditional SQL statements
if (_pStmt == 0)
{
_stepCalled = true;
_nextResponse = SQLITE_DONE;
return false;
}
_stepCalled = true;
_nextResponse = sqlite3_step(_pStmt);
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
Utility::throwException(_nextResponse);
_pExtractor->reset();//clear the cached null indicators
return (_nextResponse == SQLITE_ROW);
}
if ((*oldBegin)->canBind())
{
//container binding will come back for more, so we must rewind
_bindBegin = oldBegin;
_canBind = true;
}
else _canBind = false;
}
}
void SQLiteStatementImpl::clear()
{
_columns[currentDataSet()].clear();
_affectedRowCount = 0;
if (_pStmt)
{
sqlite3_finalize(_pStmt);
_pStmt=0;
}
_pLeftover = 0;
}
bool SQLiteStatementImpl::hasNext()
{
if (_stepCalled)
return (_nextResponse == SQLITE_ROW);
// _pStmt is allowed to be null for conditional SQL statements
if (_pStmt == 0)
{
_stepCalled = true;
_nextResponse = SQLITE_DONE;
return false;
}
_stepCalled = true;
_nextResponse = sqlite3_step(_pStmt);
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
Utility::throwException(_nextResponse);
_pExtractor->reset();//clear the cached null indicators
return (_nextResponse == SQLITE_ROW);
}
std::size_t SQLiteStatementImpl::next()
{
if (SQLITE_ROW == _nextResponse)
{
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
Extractions& extracts = extractions();
Extractions::iterator it = extracts.begin();
Extractions::iterator itEnd = extracts.end();
std::size_t pos = 0; // sqlite starts with pos 0 for results!
for (; it != itEnd; ++it)
{
(*it)->extract(pos);
pos += (*it)->numOfColumnsHandled();
_isExtracted = true;
}
_stepCalled = false;
}
else if (SQLITE_DONE == _nextResponse)
{
throw Poco::Data::DataException("No data received");
}
else
{
int rc = _nextResponse;
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
}
return 1u;
}
{
if (SQLITE_ROW == _nextResponse)
{
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
Extractions& extracts = extractions();
Extractions::iterator it = extracts.begin();
Extractions::iterator itEnd = extracts.end();
std::size_t pos = 0; // sqlite starts with pos 0 for results!
for (; it != itEnd; ++it)
{
(*it)->extract(pos);
pos += (*it)->numOfColumnsHandled();
_isExtracted = true;
}
_stepCalled = false;
}
else if (SQLITE_DONE == _nextResponse)
{
throw Poco::Data::DataException("No data received");
}
else
{
int rc = _nextResponse;
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
}
return 1u;
}
std::size_t SQLiteStatementImpl::columnsReturned() const
{
return (std::size_t) _columns[currentDataSet()].size();
}
{
return (std::size_t) _columns[currentDataSet()].size();
}
const MetaColumn& SQLiteStatementImpl::metaColumn(std::size_t pos) const
{
std::size_t curDataSet = currentDataSet();
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
return _columns[curDataSet][pos];
}
{
std::size_t curDataSet = currentDataSet();
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
return _columns[curDataSet][pos];
}
std::size_t SQLiteStatementImpl::affectedRowCount() const
{
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
}
} } } // namespace Poco::Data::SQLite
{
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
}
} } } // namespace Poco::Data::SQLite

Binary file not shown.

View File

@ -44,6 +44,7 @@
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/Data/TypeHandler.h"
#include "Poco/Data/Nullable.h"
#include "Poco/Data/DataException.h"
#include "Poco/Tuple.h"
#include "Poco/Any.h"
@ -73,6 +74,7 @@ using Poco::Data::Time;
using Poco::Data::AbstractExtractionVec;
using Poco::Data::AbstractExtractionVecVec;
using Poco::Data::AbstractBindingVec;
using Poco::Data::Nullable;
using Poco::Data::NotConnectedException;
using Poco::Tuple;
using Poco::Any;
@ -1958,6 +1960,42 @@ void SQLiteTest::testPrimaryKeyConstraint()
}
void SQLiteTest::testNullable()
{
Session ses (Poco::Data::SQLite::Connector::KEY, "dummy.db");
ses << "DROP TABLE IF EXISTS NullableTest", now;
ses << "CREATE TABLE NullableTest (i INTEGER, r REAL, s VARCHAR, d DATETIME)", now;
ses << "INSERT INTO NullableTest VALUES(:i, :r, :s, :d)", use(null), use(null), use(null), use(null), now;
Nullable<int> i = 1;
Nullable<double> f = 1.5;
Nullable<std::string> s = "abc";
Nullable<DateTime> d = DateTime();
assert (!i.isNull());
assert (!f.isNull());
assert (!s.isNull());
assert (!d.isNull());
ses << "SELECT i, r, s FROM NullableTest", into(i), into(f), into(s), into(d), now;
assert (i.isNull());
assert (f.isNull());
assert (s.isNull());
assert (d.isNull());
RecordSet rs(ses, "SELECT * FROM NullableTest");
rs.moveFirst();
assert (rs.isNull("i"));
assert (rs.isNull("r"));
assert (rs.isNull("s"));
assert (rs.isNull("d"));
}
void SQLiteTest::testNull()
{
Session ses (Poco::Data::SQLite::Connector::KEY, "dummy.db");
@ -2564,6 +2602,7 @@ CppUnit::Test* SQLiteTest::suite()
CppUnit_addTest(pSuite, SQLiteTest, testDateTime);
CppUnit_addTest(pSuite, SQLiteTest, testInternalExtraction);
CppUnit_addTest(pSuite, SQLiteTest, testPrimaryKeyConstraint);
CppUnit_addTest(pSuite, SQLiteTest, testNullable);
CppUnit_addTest(pSuite, SQLiteTest, testNull);
CppUnit_addTest(pSuite, SQLiteTest, testRowIterator);
CppUnit_addTest(pSuite, SQLiteTest, testAsync);

View File

@ -115,6 +115,7 @@ public:
void testInternalExtraction();
void testPrimaryKeyConstraint();
void testNullable();
void testNull();
void testRowIterator();
void testAsync();

View File

@ -44,130 +44,130 @@
namespace Poco {
namespace Data {
template <typename T>
class Nullable {
/// Nullable class - template for field, that can be null
/// Nullable class - template for field, that can be null
public:
Nullable()
: _value(), _isNull(true)
/// Creates the Nullable.
{
}
Nullable()
: _value(), _isNull(true)
/// Creates the Nullable.
{
}
Nullable(const T& value)
: _value(value), _isNull(false)
/// Creates the Nullable from value
{
}
Nullable(const T& value)
: _value(value), _isNull(false)
/// Creates the Nullable from value
{
}
Nullable(const NullData&)
: _value(), _isNull(true)
/// Creates the Nullable from null
{
}
Nullable(const NullData&)
: _value(), _isNull(true)
/// Creates the Nullable from null
{
}
Nullable& operator=(const T& value)
/// Assigns new value to Nullable
{
_isNull = false;
_value = value;
return *this;
}
Nullable& operator=(const T& value)
/// Assigns new value to Nullable
{
_isNull = false;
_value = value;
return *this;
}
Nullable& operator=(const Nullable<T>& other)
/// Assigns other Nullable to Nullable
{
_isNull = other._isNull;
_value = other._value;
return *this;
}
Nullable& operator=(const Nullable<T>& other)
/// Assigns other Nullable to Nullable
{
_isNull = other._isNull;
_value = other._value;
return *this;
}
Nullable& operator=(const NullData&)
/// Assigns null to Nullable
{
_isNull = true;
return *this;
}
Nullable& operator=(const NullData&)
/// Assigns null to Nullable
{
_isNull = true;
return *this;
}
bool operator==(const Nullable<T>& other) const
/// Compares two Nullable
{
return (_isNull && other._isNull) || (_isNull == other._isNull && _value == other._value);
}
bool operator==(const Nullable<T>& other) const
/// Compares two Nullable
{
return (_isNull && other._isNull) || (_isNull == other._isNull && _value == other._value);
}
bool operator==(const T& value) const
/// Compares Nullable with value
{
return (!_isNull && _value == value);
}
bool operator==(const T& value) const
/// Compares Nullable with value
{
return (!_isNull && _value == value);
}
bool operator==(const NullData&) const
/// Compares Nullable with null
{
return _isNull;
}
bool operator==(const NullData&) const
/// Compares Nullable with null
{
return _isNull;
}
bool operator!=(const NullData&) const
/// Compares Nullable for non null
{
return !_isNull;
}
bool operator!=(const NullData&) const
/// Compares Nullable for non null
{
return !_isNull;
}
bool operator!=(const T& value) const
/// Compares Nullable with value for non equal
{
return (_isNull || _value != value);
}
bool operator!=(const T& value) const
/// Compares Nullable with value for non equal
{
return (_isNull || _value != value);
}
bool operator < (const Nullable<T>& other) const
/// Compares two Nullable objects
{
if (_isNull < other._isNull)
return true;
return (_value < other._value);
}
bool operator < (const Nullable<T>& other) const
/// Compares two Nullable objects
{
if (_isNull < other._isNull)
return true;
return (_value < other._value);
}
operator T& ()
/// Get reference to the value
{
return _value;
}
operator T& ()
/// Get reference to the value
{
return _value;
}
operator const T& () const
/// Get const reference to the value
{
return _value;
}
operator const T& () const
/// Get const reference to the value
{
return _value;
}
bool isNull() const
/// Test Nullable for null
{
return _isNull;
}
bool isNull() const
/// Test Nullable for null
{
return _isNull;
}
void setNull(bool isNull)
/// Change Nullable "isNull" sign
{
_isNull = isNull;
}
void setNull(bool isNull = true)
/// Change Nullable "isNull" sign
{
_isNull = isNull;
}
const T& getValue() const
/// Get value
{
return _value;
}
const T& getValue() const
/// Get value
{
return _value;
}
void setValue(const T& value)
/// Set value
{
_isNull = false; _value = value;
}
void setValue(const T& value)
/// Set value
{
_isNull = false; _value = value;
}
private:
T _value;
bool _isNull;
T _value;
bool _isNull;
};
//
@ -177,39 +177,39 @@ private:
template <typename T>
bool operator == (const T& value, const Nullable<T>& nValue)
{
return (!nValue.isNull() && value == nValue.getValue());
return (!nValue.isNull() && value == nValue.getValue());
}
template <typename T>
bool operator != (const T& value, const Nullable<T>& nValue)
{
return (nValue.isNull() || value != nValue.getValue());
return (nValue.isNull() || value != nValue.getValue());
}
template <typename T>
bool operator == (const NullData&, const Nullable<T>& nValue)
{
return nValue.isNull();
return nValue.isNull();
}
template <typename T>
bool operator != (const NullData&, const Nullable<T>& nValue)
{
return !nValue.isNull();
return !nValue.isNull();
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const Nullable<T>& obj)
{
if (obj.isNull())
{
out << "NULL";
}
else
{
out << obj.getValue();
}
return out;
if (obj.isNull())
{
out << "NULL";
}
else
{
out << obj.getValue();
}
return out;
}
} } // namespace Poco::Data

View File

@ -73,65 +73,65 @@ class TypeHandler: public AbstractTypeHandler
/// Converts Rows to a Type and the other way around. Provide template specializations to support your own complex types.
///
/// Take as example the following (simplified) class:
/// class Person
/// {
/// private:
/// std::string _lastName;
/// std::string _firstName;
/// int _age;
/// public:
/// const std::string& getLastName();
/// [...] // other set/get methods (returning const reference), a default constructor,
/// [...] // optional < operator (for set, multiset) or function operator (for map, multimap)
/// };
/// class Person
/// {
/// private:
/// std::string _lastName;
/// std::string _firstName;
/// int _age;
/// public:
/// const std::string& getLastName();
/// [...] // other set/get methods (returning const reference), a default constructor,
/// [...] // optional < operator (for set, multiset) or function operator (for map, multimap)
/// };
///
/// The TypeHandler must provide a custom bind, size, prepare and extract method:
///
/// template <>
/// class TypeHandler<struct Person>
/// {
/// public:
/// static std::size_t size()
/// {
/// return 3; // lastName + firstname + age occupy three columns
/// }
///
/// static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
/// {
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// // Note that we advance pos by the number of columns the datatype uses! For string/int this is one.
/// poco_assert_dbg (pBinder != 0);
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder);
/// }
///
/// static void prepare(std::size_t pos, Person& obj, AbstractPreparator* pPreparator)
/// {
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// poco_assert_dbg (pPreparator != 0);
/// TypeHandler<std::string>::prepare(pos++, obj.getLastName(), pPreparator);
/// TypeHandler<std::string>::prepare(pos++, obj.getFirstName(), pPreparator);
/// TypeHandler<int>::prepare(pos++, obj.getAge(), pPreparator);
/// }
///
/// static void extract(std::size_t pos, Person& obj, const Person& defVal, AbstractExtractor* pExt)
/// {
/// // defVal is the default person we should use if we encunter NULL entries, so we take the individual fields
/// // as defaults. You can do more complex checking, ie return defVal if only one single entry of the fields is null etc...
/// poco_assert_dbg (pExt != 0);
/// std::string lastName;
/// std::string firstName;
/// int age = 0;
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// TypeHandler<std::string>::extract(pos++, lastName, defVal.getLastName(), pExt);
/// TypeHandler<std::string>::extract(pos++, firstName, defVal.getFirstName(), pExt);
/// TypeHandler<int>::extract(pos++, age, defVal.getAge(), pExt);
/// obj.setLastName(lastName);
/// obj.setFirstName(firstName);
/// obj.setAge(age);
/// }
/// };
///
/// template <>
/// class TypeHandler<struct Person>
/// {
/// public:
/// static std::size_t size()
/// {
/// return 3; // lastName + firstname + age occupy three columns
/// }
///
/// static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
/// {
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// // Note that we advance pos by the number of columns the datatype uses! For string/int this is one.
/// poco_assert_dbg (pBinder != 0);
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder);
/// }
///
/// static void prepare(std::size_t pos, Person& obj, AbstractPreparator* pPreparator)
/// {
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// poco_assert_dbg (pPreparator != 0);
/// TypeHandler<std::string>::prepare(pos++, obj.getLastName(), pPreparator);
/// TypeHandler<std::string>::prepare(pos++, obj.getFirstName(), pPreparator);
/// TypeHandler<int>::prepare(pos++, obj.getAge(), pPreparator);
/// }
///
/// static void extract(std::size_t pos, Person& obj, const Person& defVal, AbstractExtractor* pExt)
/// {
/// // defVal is the default person we should use if we encunter NULL entries, so we take the individual fields
/// // as defaults. You can do more complex checking, ie return defVal if only one single entry of the fields is null etc...
/// poco_assert_dbg (pExt != 0);
/// std::string lastName;
/// std::string firstName;
/// int age = 0;
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
/// TypeHandler<std::string>::extract(pos++, lastName, defVal.getLastName(), pExt);
/// TypeHandler<std::string>::extract(pos++, firstName, defVal.getFirstName(), pExt);
/// TypeHandler<int>::extract(pos++, age, defVal.getAge(), pExt);
/// obj.setLastName(lastName);
/// obj.setFirstName(firstName);
/// obj.setAge(age);
/// }
/// };
///
/// Note that the TypeHandler template specialization must always be declared in the namespace Poco::Data.
/// Apart from that no further work is needed. One can now use Person with into and use clauses.
@ -271,63 +271,63 @@ private:
};
template <typename T>
class TypeHandler< Nullable<T> >
/// Specialization of type handler for Nullable.
class TypeHandler<Nullable<T> >
/// Specialization of type handler for Nullable.
{
public:
static void bind(std::size_t pos, const Nullable<T>& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
poco_assert_dbg (pBinder != 0);
if (obj.isNull())
{
pBinder->bind(pos++, Poco::Data::Keywords::null, dir);
}
else
{
pBinder->bind(pos++, obj.getValue(), dir);
}
}
static void bind(std::size_t pos, const Nullable<T>& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
poco_assert_dbg (pBinder != 0);
if (obj.isNull())
{
pBinder->bind(pos++, Poco::Data::Keywords::null, dir);
}
else
{
pBinder->bind(pos++, obj.getValue(), dir);
}
}
static void prepare(std::size_t pos, Nullable<T>& obj, AbstractPreparator* pPreparator)
{
poco_assert_dbg (pPreparator != 0);
if (obj.isNull())
{
pPreparator->prepare(pos++, (Poco::Any&)Poco::Data::Keywords::null);
}
else
{
pPreparator->prepare(pos++, (T&)obj.getValue());
}
}
static void prepare(std::size_t pos, Nullable<T>& obj, AbstractPreparator* pPreparator)
{
poco_assert_dbg (pPreparator != 0);
if (obj.isNull())
{
pPreparator->prepare(pos++, (Poco::Any&)Poco::Data::Keywords::null);
}
else
{
pPreparator->prepare(pos++, (T&)obj.getValue());
}
}
static std::size_t size()
{
return 1u;
}
static std::size_t size()
{
return 1u;
}
static void extract(std::size_t pos, Nullable<T>& obj, const Nullable<T>& , AbstractExtractor* pExt)
{
poco_assert_dbg (pExt != 0);
T value;
if (pExt->extract(pos++, value))
{
obj.setValue(value);
}
else
{
obj.setNull(true);
}
}
static void extract(std::size_t pos, Nullable<T>& obj, const Nullable<T>& , AbstractExtractor* pExt)
{
poco_assert_dbg (pExt != 0);
T value;
if (pExt->extract(pos++, value))
{
obj.setValue(value);
}
else
{
obj.setNull(true);
}
}
private:
TypeHandler();
~TypeHandler();
TypeHandler(const TypeHandler&);
TypeHandler& operator=(const TypeHandler&);
TypeHandler();
~TypeHandler();
TypeHandler(const TypeHandler&);
TypeHandler& operator=(const TypeHandler&);
};
@ -389,7 +389,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -519,7 +519,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -644,7 +644,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -764,7 +764,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -879,7 +879,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -989,7 +989,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1094,7 +1094,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1194,7 +1194,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1289,7 +1289,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1379,7 +1379,7 @@ class TypeHandler<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1455,7 +1455,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1527,7 +1527,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, NullTypeList>
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1595,7 +1595,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, T7, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1659,7 +1659,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, T6, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1719,7 +1719,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, T5, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, T5, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1775,7 +1775,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, T4, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, T4, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1827,7 +1827,7 @@ class TypeHandler<Poco::Tuple<T0, T1, T2, T3, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, T3, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1871,11 +1871,11 @@ private:
template <class T0, class T1, class T2>
class TypeHandler<Poco::Tuple<T0, T1, T2, NullTypeList> >
class TypeHandler<Poco::Tuple<T0, T1, T2, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1919,7 +1919,7 @@ class TypeHandler<Poco::Tuple<T0, T1, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{
@ -1959,7 +1959,7 @@ class TypeHandler<Poco::Tuple<T0, NullTypeList> >
{
public:
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, NullTypeList> >::CONSTREFTYPE TupleConstRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, NullTypeList> >::REFTYPE TupleRef;
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, NullTypeList> >::REFTYPE TupleRef;
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
{

View File

@ -51,6 +51,7 @@
#include "Poco/Dynamic/Var.h"
#include "Poco/Data/DynamicLOB.h"
#include "Poco/Data/DynamicDateTime.h"
#include "Poco/Data/Nullable.h"
#include "Poco/Exception.h"
#include <cstring>
#include <sstream>
@ -92,6 +93,7 @@ using Poco::Data::AbstractExtractionVec;
using Poco::Data::AbstractExtractionVecVec;
using Poco::Data::AbstractBinding;
using Poco::Data::AbstractBindingVec;
using Poco::Data::Nullable;
using Poco::Data::NotConnectedException;
@ -1385,6 +1387,38 @@ void DataTest::testExternalBindingAndExtraction()
}
void DataTest::testNullable()
{
Nullable<int> i;
Nullable<double> f;
Nullable<std::string> s;
assert (i.isNull());
assert (f.isNull());
assert (s.isNull());
i = 1;
f = 1.5;
s = "abc";
assert (!i.isNull());
assert (!f.isNull());
assert (!s.isNull());
assert (i == 1);
assert (f == 1.5);
assert (s == "abc");
i.setNull();
f.setNull();
s.setNull();
assert (i.isNull());
assert (f.isNull());
assert (s.isNull());
}
void DataTest::setUp()
{
}
@ -1415,6 +1449,7 @@ CppUnit::Test* DataTest::suite()
CppUnit_addTest(pSuite, DataTest, testRowFormat);
CppUnit_addTest(pSuite, DataTest, testDateAndTime);
CppUnit_addTest(pSuite, DataTest, testExternalBindingAndExtraction);
CppUnit_addTest(pSuite, DataTest, testNullable);
return pSuite;
}

View File

@ -65,6 +65,7 @@ public:
void testRowFormat();
void testDateAndTime();
void testExternalBindingAndExtraction();
void testNullable();
void setUp();
void tearDown();