mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 19:13:30 +01:00
- 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:
parent
0ca3bbc848
commit
dbda035719
@ -681,6 +681,7 @@ CppUnit::Test* ODBCDB2Test::suite()
|
|||||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSessionTransaction);
|
CppUnit_addTest(pSuite, ODBCDB2Test, testSessionTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCDB2Test, testTransaction);
|
CppUnit_addTest(pSuite, ODBCDB2Test, testTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCDB2Test, testTransactor);
|
CppUnit_addTest(pSuite, ODBCDB2Test, testTransactor);
|
||||||
|
CppUnit_addTest(pSuite, ODBCDB2Test, testNullable);
|
||||||
CppUnit_addTest(pSuite, ODBCDB2Test, testReconnect);
|
CppUnit_addTest(pSuite, ODBCDB2Test, testReconnect);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -497,6 +497,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
|
|||||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
|
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransaction);
|
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransactor);
|
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransactor);
|
||||||
|
CppUnit_addTest(pSuite, ODBCMySQLTest, testNullable);
|
||||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testReconnect);
|
CppUnit_addTest(pSuite, ODBCMySQLTest, testReconnect);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -933,6 +933,7 @@ CppUnit::Test* ODBCOracleTest::suite()
|
|||||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSessionTransaction);
|
CppUnit_addTest(pSuite, ODBCOracleTest, testSessionTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCOracleTest, testTransaction);
|
CppUnit_addTest(pSuite, ODBCOracleTest, testTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCOracleTest, testTransactor);
|
CppUnit_addTest(pSuite, ODBCOracleTest, testTransactor);
|
||||||
|
CppUnit_addTest(pSuite, ODBCOracleTest, testNullable);
|
||||||
CppUnit_addTest(pSuite, ODBCOracleTest, testReconnect);
|
CppUnit_addTest(pSuite, ODBCOracleTest, testReconnect);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -659,6 +659,7 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
|
|||||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
|
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
|
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
|
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
|
||||||
|
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNullable);
|
||||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
|
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -809,6 +809,7 @@ CppUnit::Test* ODBCSQLServerTest::suite()
|
|||||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
|
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
|
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
|
||||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
|
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
|
||||||
|
CppUnit_addTest(pSuite, ODBCSQLServerTest, testNullable);
|
||||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect);
|
CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
|
@ -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()
|
void ODBCTest::testReconnect()
|
||||||
{
|
{
|
||||||
if (!_pSession) fail ("Test not available.");
|
if (!_pSession) fail ("Test not available.");
|
||||||
|
@ -167,6 +167,7 @@ public:
|
|||||||
virtual void testSessionTransaction();
|
virtual void testSessionTransaction();
|
||||||
virtual void testTransaction();
|
virtual void testTransaction();
|
||||||
virtual void testTransactor();
|
virtual void testTransactor();
|
||||||
|
virtual void testNullable();
|
||||||
|
|
||||||
virtual void testReconnect();
|
virtual void testReconnect();
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ using Poco::Message;
|
|||||||
using Poco::NotFoundException;
|
using Poco::NotFoundException;
|
||||||
using Poco::InvalidAccessException;
|
using Poco::InvalidAccessException;
|
||||||
using Poco::InvalidArgumentException;
|
using Poco::InvalidArgumentException;
|
||||||
|
using Poco::NotImplementedException;
|
||||||
using Poco::BadCastException;
|
using Poco::BadCastException;
|
||||||
using Poco::RangeException;
|
using Poco::RangeException;
|
||||||
|
|
||||||
@ -3786,6 +3787,12 @@ void SQLExecutor::transactor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SQLExecutor::nullable()
|
||||||
|
{
|
||||||
|
throw NotImplementedException("TODO - see SQLite test for nullable");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SQLExecutor::reconnect()
|
void SQLExecutor::reconnect()
|
||||||
{
|
{
|
||||||
std::string funct = "reconnect()";
|
std::string funct = "reconnect()";
|
||||||
|
@ -518,6 +518,7 @@ public:
|
|||||||
void sessionTransaction(const std::string& connect);
|
void sessionTransaction(const std::string& connect);
|
||||||
void transaction(const std::string& connect);
|
void transaction(const std::string& connect);
|
||||||
void transactor();
|
void transactor();
|
||||||
|
void nullable();
|
||||||
|
|
||||||
void reconnect();
|
void reconnect();
|
||||||
|
|
||||||
|
@ -1,262 +1,252 @@
|
|||||||
//
|
//
|
||||||
// Extractor.cpp
|
// Extractor.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
|
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
|
||||||
//
|
//
|
||||||
// Library: SQLite
|
// Library: SQLite
|
||||||
// Package: SQLite
|
// Package: SQLite
|
||||||
// Module: Extractor
|
// Module: Extractor
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Data/SQLite/Extractor.h"
|
#include "Poco/Data/SQLite/Extractor.h"
|
||||||
#include "Poco/Data/SQLite/Utility.h"
|
#include "Poco/Data/SQLite/Utility.h"
|
||||||
#include "Poco/Data/Date.h"
|
#include "Poco/Data/Date.h"
|
||||||
#include "Poco/Data/Time.h"
|
#include "Poco/Data/Time.h"
|
||||||
#include "Poco/Data/LOB.h"
|
#include "Poco/Data/LOB.h"
|
||||||
#include "Poco/Data/DataException.h"
|
#include "Poco/Data/DataException.h"
|
||||||
#include "Poco/DateTimeParser.h"
|
#include "Poco/DateTimeParser.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#if defined(POCO_UNBUNDLED)
|
#if defined(POCO_UNBUNDLED)
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#else
|
#else
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
#endif
|
#endif
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
using Poco::DateTimeParser;
|
using Poco::DateTimeParser;
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Data {
|
namespace Data {
|
||||||
namespace SQLite {
|
namespace SQLite {
|
||||||
|
|
||||||
|
|
||||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||||
_pStmt(pStmt)
|
_pStmt(pStmt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Extractor::~Extractor()
|
Extractor::~Extractor()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||||
{
|
{
|
||||||
if (isNull(pos))
|
if (isNull(pos)) return false;
|
||||||
return false;
|
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
{
|
||||||
{
|
if (isNull(pos)) return false;
|
||||||
if (isNull(pos))
|
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||||
return false;
|
return true;
|
||||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef POCO_LONG_IS_64_BIT
|
#ifndef POCO_LONG_IS_64_BIT
|
||||||
bool Extractor::extract(std::size_t pos, long& val)
|
bool Extractor::extract(std::size_t pos, long& val)
|
||||||
{
|
{
|
||||||
if (isNull(pos))
|
if (isNull(pos)) return false;
|
||||||
return false;
|
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool Extractor::extract(std::size_t pos, double& val)
|
bool Extractor::extract(std::size_t pos, double& val)
|
||||||
{
|
{
|
||||||
if (isNull(pos))
|
if (isNull(pos)) return false;
|
||||||
return false;
|
val = sqlite3_column_double(_pStmt, (int) pos);
|
||||||
val = sqlite3_column_double(_pStmt, (int) pos);
|
return true;
|
||||||
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, 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)
|
bool Extractor::extract(std::size_t pos, Time& val)
|
||||||
{
|
{
|
||||||
std::string str;
|
if (isNull(pos)) return false;
|
||||||
extract(pos, str);
|
std::string str;
|
||||||
int tzd;
|
extract(pos, str);
|
||||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
int tzd;
|
||||||
val = dt;
|
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
||||||
return true;
|
val = dt;
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||||
{
|
{
|
||||||
std::string dt;
|
if (isNull(pos)) return false;
|
||||||
extract(pos, dt);
|
std::string dt;
|
||||||
int tzd;
|
extract(pos, dt);
|
||||||
DateTimeParser::parse(dt, val, tzd);
|
int tzd;
|
||||||
return true;
|
DateTimeParser::parse(dt, val, tzd);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Extractor::extract(std::size_t pos, Poco::Any& val)
|
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)
|
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)
|
bool Extractor::isNull(std::size_t pos, std::size_t)
|
||||||
{
|
{
|
||||||
if (pos >= _nulls.size())
|
if (pos >= _nulls.size())
|
||||||
_nulls.resize(pos + 1);
|
_nulls.resize(pos + 1);
|
||||||
|
|
||||||
if (!_nulls[pos].first)
|
if (!_nulls[pos].first)
|
||||||
{
|
{
|
||||||
_nulls[pos].first = true;
|
_nulls[pos].first = true;
|
||||||
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
|
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _nulls[pos].second;
|
return _nulls[pos].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} } } // namespace Poco::Data::SQLite
|
} } } // namespace Poco::Data::SQLite
|
||||||
|
@ -1,311 +1,311 @@
|
|||||||
//
|
//
|
||||||
// SQLiteStatementImpl.cpp
|
// SQLiteStatementImpl.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
|
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
|
||||||
//
|
//
|
||||||
// Library: SQLite
|
// Library: SQLite
|
||||||
// Package: SQLite
|
// Package: SQLite
|
||||||
// Module: SQLiteStatementImpl
|
// Module: SQLiteStatementImpl
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
||||||
#include "Poco/Data/SQLite/Utility.h"
|
#include "Poco/Data/SQLite/Utility.h"
|
||||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||||
#include "Poco/String.h"
|
#include "Poco/String.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#if defined(POCO_UNBUNDLED)
|
#if defined(POCO_UNBUNDLED)
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#else
|
#else
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Data {
|
namespace Data {
|
||||||
namespace SQLite {
|
namespace SQLite {
|
||||||
|
|
||||||
|
|
||||||
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
|
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
|
||||||
StatementImpl(rSession),
|
StatementImpl(rSession),
|
||||||
_pDB(pDB),
|
_pDB(pDB),
|
||||||
_pStmt(0),
|
_pStmt(0),
|
||||||
_stepCalled(false),
|
_stepCalled(false),
|
||||||
_nextResponse(0),
|
_nextResponse(0),
|
||||||
_affectedRowCount(0),
|
_affectedRowCount(0),
|
||||||
_canBind(false),
|
_canBind(false),
|
||||||
_isExtracted(false),
|
_isExtracted(false),
|
||||||
_canCompile(true)
|
_canCompile(true)
|
||||||
{
|
{
|
||||||
_columns.resize(1);
|
_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();
|
|
||||||
|
|
||||||
if (0 == std::strlen(pSql))
|
SQLiteStatementImpl::~SQLiteStatementImpl()
|
||||||
throw InvalidSQLStatementException("Empty statements are illegal");
|
{
|
||||||
|
clear();
|
||||||
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())
|
void SQLiteStatementImpl::compileImpl()
|
||||||
{
|
{
|
||||||
_affectedRowCount = (*_bindBegin)->numOfRowsHandled();
|
if (!_pLeftover) _bindBegin = bindings().begin();
|
||||||
|
|
||||||
Bindings::iterator oldBegin = _bindBegin;
|
std::string statement(toString());
|
||||||
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
|
sqlite3_stmt* pStmt = 0;
|
||||||
{
|
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
|
||||||
if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
|
|
||||||
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
|
|
||||||
|
|
||||||
(*_bindBegin)->bind(pos);
|
if (0 == std::strlen(pSql))
|
||||||
pos += (*_bindBegin)->numOfColumnsHandled();
|
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()
|
std::size_t SQLiteStatementImpl::next()
|
||||||
{
|
{
|
||||||
if (SQLITE_ROW == _nextResponse)
|
if (SQLITE_ROW == _nextResponse)
|
||||||
{
|
{
|
||||||
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
|
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
|
||||||
|
|
||||||
Extractions& extracts = extractions();
|
Extractions& extracts = extractions();
|
||||||
Extractions::iterator it = extracts.begin();
|
Extractions::iterator it = extracts.begin();
|
||||||
Extractions::iterator itEnd = extracts.end();
|
Extractions::iterator itEnd = extracts.end();
|
||||||
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
{
|
{
|
||||||
(*it)->extract(pos);
|
(*it)->extract(pos);
|
||||||
pos += (*it)->numOfColumnsHandled();
|
pos += (*it)->numOfColumnsHandled();
|
||||||
_isExtracted = true;
|
_isExtracted = true;
|
||||||
}
|
}
|
||||||
_stepCalled = false;
|
_stepCalled = false;
|
||||||
}
|
}
|
||||||
else if (SQLITE_DONE == _nextResponse)
|
else if (SQLITE_DONE == _nextResponse)
|
||||||
{
|
{
|
||||||
throw Poco::Data::DataException("No data received");
|
throw Poco::Data::DataException("No data received");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int rc = _nextResponse;
|
int rc = _nextResponse;
|
||||||
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1u;
|
return 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::size_t SQLiteStatementImpl::columnsReturned() const
|
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
|
const MetaColumn& SQLiteStatementImpl::metaColumn(std::size_t pos) const
|
||||||
{
|
{
|
||||||
std::size_t curDataSet = currentDataSet();
|
std::size_t curDataSet = currentDataSet();
|
||||||
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
|
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
|
||||||
return _columns[curDataSet][pos];
|
return _columns[curDataSet][pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::size_t SQLiteStatementImpl::affectedRowCount() const
|
std::size_t SQLiteStatementImpl::affectedRowCount() const
|
||||||
{
|
{
|
||||||
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
|
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} } } // namespace Poco::Data::SQLite
|
} } } // namespace Poco::Data::SQLite
|
||||||
|
Binary file not shown.
@ -44,6 +44,7 @@
|
|||||||
#include "Poco/Data/SQLite/Utility.h"
|
#include "Poco/Data/SQLite/Utility.h"
|
||||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||||
#include "Poco/Data/TypeHandler.h"
|
#include "Poco/Data/TypeHandler.h"
|
||||||
|
#include "Poco/Data/Nullable.h"
|
||||||
#include "Poco/Data/DataException.h"
|
#include "Poco/Data/DataException.h"
|
||||||
#include "Poco/Tuple.h"
|
#include "Poco/Tuple.h"
|
||||||
#include "Poco/Any.h"
|
#include "Poco/Any.h"
|
||||||
@ -73,6 +74,7 @@ using Poco::Data::Time;
|
|||||||
using Poco::Data::AbstractExtractionVec;
|
using Poco::Data::AbstractExtractionVec;
|
||||||
using Poco::Data::AbstractExtractionVecVec;
|
using Poco::Data::AbstractExtractionVecVec;
|
||||||
using Poco::Data::AbstractBindingVec;
|
using Poco::Data::AbstractBindingVec;
|
||||||
|
using Poco::Data::Nullable;
|
||||||
using Poco::Data::NotConnectedException;
|
using Poco::Data::NotConnectedException;
|
||||||
using Poco::Tuple;
|
using Poco::Tuple;
|
||||||
using Poco::Any;
|
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()
|
void SQLiteTest::testNull()
|
||||||
{
|
{
|
||||||
Session ses (Poco::Data::SQLite::Connector::KEY, "dummy.db");
|
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, testDateTime);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testInternalExtraction);
|
CppUnit_addTest(pSuite, SQLiteTest, testInternalExtraction);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testPrimaryKeyConstraint);
|
CppUnit_addTest(pSuite, SQLiteTest, testPrimaryKeyConstraint);
|
||||||
|
CppUnit_addTest(pSuite, SQLiteTest, testNullable);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testNull);
|
CppUnit_addTest(pSuite, SQLiteTest, testNull);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testRowIterator);
|
CppUnit_addTest(pSuite, SQLiteTest, testRowIterator);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testAsync);
|
CppUnit_addTest(pSuite, SQLiteTest, testAsync);
|
||||||
|
@ -115,6 +115,7 @@ public:
|
|||||||
|
|
||||||
void testInternalExtraction();
|
void testInternalExtraction();
|
||||||
void testPrimaryKeyConstraint();
|
void testPrimaryKeyConstraint();
|
||||||
|
void testNullable();
|
||||||
void testNull();
|
void testNull();
|
||||||
void testRowIterator();
|
void testRowIterator();
|
||||||
void testAsync();
|
void testAsync();
|
||||||
|
@ -44,130 +44,130 @@
|
|||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Nullable {
|
class Nullable {
|
||||||
/// Nullable class - template for field, that can be null
|
/// Nullable class - template for field, that can be null
|
||||||
public:
|
public:
|
||||||
Nullable()
|
Nullable()
|
||||||
: _value(), _isNull(true)
|
: _value(), _isNull(true)
|
||||||
/// Creates the Nullable.
|
/// Creates the Nullable.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable(const T& value)
|
Nullable(const T& value)
|
||||||
: _value(value), _isNull(false)
|
: _value(value), _isNull(false)
|
||||||
/// Creates the Nullable from value
|
/// Creates the Nullable from value
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable(const NullData&)
|
Nullable(const NullData&)
|
||||||
: _value(), _isNull(true)
|
: _value(), _isNull(true)
|
||||||
/// Creates the Nullable from null
|
/// Creates the Nullable from null
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable& operator=(const T& value)
|
Nullable& operator=(const T& value)
|
||||||
/// Assigns new value to Nullable
|
/// Assigns new value to Nullable
|
||||||
{
|
{
|
||||||
_isNull = false;
|
_isNull = false;
|
||||||
_value = value;
|
_value = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable& operator=(const Nullable<T>& other)
|
Nullable& operator=(const Nullable<T>& other)
|
||||||
/// Assigns other Nullable to Nullable
|
/// Assigns other Nullable to Nullable
|
||||||
{
|
{
|
||||||
_isNull = other._isNull;
|
_isNull = other._isNull;
|
||||||
_value = other._value;
|
_value = other._value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nullable& operator=(const NullData&)
|
Nullable& operator=(const NullData&)
|
||||||
/// Assigns null to Nullable
|
/// Assigns null to Nullable
|
||||||
{
|
{
|
||||||
_isNull = true;
|
_isNull = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Nullable<T>& other) const
|
bool operator==(const Nullable<T>& other) const
|
||||||
/// Compares two Nullable
|
/// Compares two Nullable
|
||||||
{
|
{
|
||||||
return (_isNull && other._isNull) || (_isNull == other._isNull && _value == other._value);
|
return (_isNull && other._isNull) || (_isNull == other._isNull && _value == other._value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const T& value) const
|
bool operator==(const T& value) const
|
||||||
/// Compares Nullable with value
|
/// Compares Nullable with value
|
||||||
{
|
{
|
||||||
return (!_isNull && _value == value);
|
return (!_isNull && _value == value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const NullData&) const
|
bool operator==(const NullData&) const
|
||||||
/// Compares Nullable with null
|
/// Compares Nullable with null
|
||||||
{
|
{
|
||||||
return _isNull;
|
return _isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const NullData&) const
|
bool operator!=(const NullData&) const
|
||||||
/// Compares Nullable for non null
|
/// Compares Nullable for non null
|
||||||
{
|
{
|
||||||
return !_isNull;
|
return !_isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const T& value) const
|
bool operator!=(const T& value) const
|
||||||
/// Compares Nullable with value for non equal
|
/// Compares Nullable with value for non equal
|
||||||
{
|
{
|
||||||
return (_isNull || _value != value);
|
return (_isNull || _value != value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const Nullable<T>& other) const
|
bool operator < (const Nullable<T>& other) const
|
||||||
/// Compares two Nullable objects
|
/// Compares two Nullable objects
|
||||||
{
|
{
|
||||||
if (_isNull < other._isNull)
|
if (_isNull < other._isNull)
|
||||||
return true;
|
return true;
|
||||||
return (_value < other._value);
|
return (_value < other._value);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T& ()
|
operator T& ()
|
||||||
/// Get reference to the value
|
/// Get reference to the value
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const T& () const
|
operator const T& () const
|
||||||
/// Get const reference to the value
|
/// Get const reference to the value
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNull() const
|
bool isNull() const
|
||||||
/// Test Nullable for null
|
/// Test Nullable for null
|
||||||
{
|
{
|
||||||
return _isNull;
|
return _isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNull(bool isNull)
|
void setNull(bool isNull = true)
|
||||||
/// Change Nullable "isNull" sign
|
/// Change Nullable "isNull" sign
|
||||||
{
|
{
|
||||||
_isNull = isNull;
|
_isNull = isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& getValue() const
|
const T& getValue() const
|
||||||
/// Get value
|
/// Get value
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const T& value)
|
void setValue(const T& value)
|
||||||
/// Set value
|
/// Set value
|
||||||
{
|
{
|
||||||
_isNull = false; _value = value;
|
_isNull = false; _value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
T _value;
|
T _value;
|
||||||
bool _isNull;
|
bool _isNull;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -177,39 +177,39 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator == (const T& value, const Nullable<T>& nValue)
|
bool operator == (const T& value, const Nullable<T>& nValue)
|
||||||
{
|
{
|
||||||
return (!nValue.isNull() && value == nValue.getValue());
|
return (!nValue.isNull() && value == nValue.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator != (const T& value, const Nullable<T>& nValue)
|
bool operator != (const T& value, const Nullable<T>& nValue)
|
||||||
{
|
{
|
||||||
return (nValue.isNull() || value != nValue.getValue());
|
return (nValue.isNull() || value != nValue.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator == (const NullData&, const Nullable<T>& nValue)
|
bool operator == (const NullData&, const Nullable<T>& nValue)
|
||||||
{
|
{
|
||||||
return nValue.isNull();
|
return nValue.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator != (const NullData&, const Nullable<T>& nValue)
|
bool operator != (const NullData&, const Nullable<T>& nValue)
|
||||||
{
|
{
|
||||||
return !nValue.isNull();
|
return !nValue.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::ostream& operator<<(std::ostream& out, const Nullable<T>& obj)
|
std::ostream& operator<<(std::ostream& out, const Nullable<T>& obj)
|
||||||
{
|
{
|
||||||
if (obj.isNull())
|
if (obj.isNull())
|
||||||
{
|
{
|
||||||
out << "NULL";
|
out << "NULL";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out << obj.getValue();
|
out << obj.getValue();
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // namespace Poco::Data
|
} } // namespace Poco::Data
|
||||||
|
@ -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.
|
/// 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:
|
/// Take as example the following (simplified) class:
|
||||||
/// class Person
|
/// class Person
|
||||||
/// {
|
/// {
|
||||||
/// private:
|
/// private:
|
||||||
/// std::string _lastName;
|
/// std::string _lastName;
|
||||||
/// std::string _firstName;
|
/// std::string _firstName;
|
||||||
/// int _age;
|
/// int _age;
|
||||||
/// public:
|
/// public:
|
||||||
/// const std::string& getLastName();
|
/// const std::string& getLastName();
|
||||||
/// [...] // other set/get methods (returning const reference), a default constructor,
|
/// [...] // other set/get methods (returning const reference), a default constructor,
|
||||||
/// [...] // optional < operator (for set, multiset) or function operator (for map, multimap)
|
/// [...] // optional < operator (for set, multiset) or function operator (for map, multimap)
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// The TypeHandler must provide a custom bind, size, prepare and extract method:
|
/// The TypeHandler must provide a custom bind, size, prepare and extract method:
|
||||||
///
|
///
|
||||||
/// template <>
|
/// template <>
|
||||||
/// class TypeHandler<struct Person>
|
/// class TypeHandler<struct Person>
|
||||||
/// {
|
/// {
|
||||||
/// public:
|
/// public:
|
||||||
/// static std::size_t size()
|
/// static std::size_t size()
|
||||||
/// {
|
/// {
|
||||||
/// return 3; // lastName + firstname + age occupy three columns
|
/// return 3; // lastName + firstname + age occupy three columns
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
|
/// 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))
|
/// // 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.
|
/// // Note that we advance pos by the number of columns the datatype uses! For string/int this is one.
|
||||||
/// poco_assert_dbg (pBinder != 0);
|
/// poco_assert_dbg (pBinder != 0);
|
||||||
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
|
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
|
||||||
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
|
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
|
||||||
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder);
|
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// static void prepare(std::size_t pos, Person& obj, AbstractPreparator* pPreparator)
|
/// 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))
|
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
|
||||||
/// poco_assert_dbg (pPreparator != 0);
|
/// poco_assert_dbg (pPreparator != 0);
|
||||||
/// TypeHandler<std::string>::prepare(pos++, obj.getLastName(), pPreparator);
|
/// TypeHandler<std::string>::prepare(pos++, obj.getLastName(), pPreparator);
|
||||||
/// TypeHandler<std::string>::prepare(pos++, obj.getFirstName(), pPreparator);
|
/// TypeHandler<std::string>::prepare(pos++, obj.getFirstName(), pPreparator);
|
||||||
/// TypeHandler<int>::prepare(pos++, obj.getAge(), pPreparator);
|
/// TypeHandler<int>::prepare(pos++, obj.getAge(), pPreparator);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// static void extract(std::size_t pos, Person& obj, const Person& defVal, AbstractExtractor* pExt)
|
/// 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
|
/// // 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...
|
/// // 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);
|
/// poco_assert_dbg (pExt != 0);
|
||||||
/// std::string lastName;
|
/// std::string lastName;
|
||||||
/// std::string firstName;
|
/// std::string firstName;
|
||||||
/// int age = 0;
|
/// int age = 0;
|
||||||
/// // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3))
|
/// // 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++, lastName, defVal.getLastName(), pExt);
|
||||||
/// TypeHandler<std::string>::extract(pos++, firstName, defVal.getFirstName(), pExt);
|
/// TypeHandler<std::string>::extract(pos++, firstName, defVal.getFirstName(), pExt);
|
||||||
/// TypeHandler<int>::extract(pos++, age, defVal.getAge(), pExt);
|
/// TypeHandler<int>::extract(pos++, age, defVal.getAge(), pExt);
|
||||||
/// obj.setLastName(lastName);
|
/// obj.setLastName(lastName);
|
||||||
/// obj.setFirstName(firstName);
|
/// obj.setFirstName(firstName);
|
||||||
/// obj.setAge(age);
|
/// obj.setAge(age);
|
||||||
/// }
|
/// }
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// Note that the TypeHandler template specialization must always be declared in the namespace Poco::Data.
|
/// 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.
|
/// 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>
|
template <typename T>
|
||||||
class TypeHandler< Nullable<T> >
|
class TypeHandler<Nullable<T> >
|
||||||
/// Specialization of type handler for Nullable.
|
/// Specialization of type handler for Nullable.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void bind(std::size_t pos, const Nullable<T>& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
|
static void bind(std::size_t pos, const Nullable<T>& obj, AbstractBinder* pBinder, AbstractBinder::Direction dir)
|
||||||
{
|
{
|
||||||
poco_assert_dbg (pBinder != 0);
|
poco_assert_dbg (pBinder != 0);
|
||||||
if (obj.isNull())
|
if (obj.isNull())
|
||||||
{
|
{
|
||||||
pBinder->bind(pos++, Poco::Data::Keywords::null, dir);
|
pBinder->bind(pos++, Poco::Data::Keywords::null, dir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pBinder->bind(pos++, obj.getValue(), dir);
|
pBinder->bind(pos++, obj.getValue(), dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare(std::size_t pos, Nullable<T>& obj, AbstractPreparator* pPreparator)
|
static void prepare(std::size_t pos, Nullable<T>& obj, AbstractPreparator* pPreparator)
|
||||||
{
|
{
|
||||||
poco_assert_dbg (pPreparator != 0);
|
poco_assert_dbg (pPreparator != 0);
|
||||||
if (obj.isNull())
|
if (obj.isNull())
|
||||||
{
|
{
|
||||||
pPreparator->prepare(pos++, (Poco::Any&)Poco::Data::Keywords::null);
|
pPreparator->prepare(pos++, (Poco::Any&)Poco::Data::Keywords::null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pPreparator->prepare(pos++, (T&)obj.getValue());
|
pPreparator->prepare(pos++, (T&)obj.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::size_t size()
|
static std::size_t size()
|
||||||
{
|
{
|
||||||
return 1u;
|
return 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extract(std::size_t pos, Nullable<T>& obj, const Nullable<T>& , AbstractExtractor* pExt)
|
static void extract(std::size_t pos, Nullable<T>& obj, const Nullable<T>& , AbstractExtractor* pExt)
|
||||||
{
|
{
|
||||||
poco_assert_dbg (pExt != 0);
|
poco_assert_dbg (pExt != 0);
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
if (pExt->extract(pos++, value))
|
if (pExt->extract(pos++, value))
|
||||||
{
|
{
|
||||||
obj.setValue(value);
|
obj.setValue(value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
obj.setNull(true);
|
obj.setNull(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TypeHandler();
|
TypeHandler();
|
||||||
~TypeHandler();
|
~TypeHandler();
|
||||||
TypeHandler(const TypeHandler&);
|
TypeHandler(const TypeHandler&);
|
||||||
TypeHandler& operator=(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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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:
|
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> >::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)
|
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>
|
template <class T0, class T1, class T2>
|
||||||
class TypeHandler<Poco::Tuple<T0, T1, T2, NullTypeList> >
|
class TypeHandler<Poco::Tuple<T0, T1, T2, NullTypeList> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, T2, NullTypeList> >::CONSTREFTYPE TupleConstRef;
|
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> >::REFTYPE TupleRef;
|
||||||
|
|
||||||
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
|
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:
|
public:
|
||||||
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, T1, NullTypeList> >::CONSTREFTYPE TupleConstRef;
|
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)
|
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:
|
public:
|
||||||
typedef typename Poco::TypeWrapper<Poco::Tuple<T0, NullTypeList> >::CONSTREFTYPE TupleConstRef;
|
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)
|
static void bind(std::size_t pos, TupleConstRef tuple, AbstractBinder* pBinder, AbstractBinder::Direction dir)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include "Poco/Dynamic/Var.h"
|
#include "Poco/Dynamic/Var.h"
|
||||||
#include "Poco/Data/DynamicLOB.h"
|
#include "Poco/Data/DynamicLOB.h"
|
||||||
#include "Poco/Data/DynamicDateTime.h"
|
#include "Poco/Data/DynamicDateTime.h"
|
||||||
|
#include "Poco/Data/Nullable.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -92,6 +93,7 @@ using Poco::Data::AbstractExtractionVec;
|
|||||||
using Poco::Data::AbstractExtractionVecVec;
|
using Poco::Data::AbstractExtractionVecVec;
|
||||||
using Poco::Data::AbstractBinding;
|
using Poco::Data::AbstractBinding;
|
||||||
using Poco::Data::AbstractBindingVec;
|
using Poco::Data::AbstractBindingVec;
|
||||||
|
using Poco::Data::Nullable;
|
||||||
using Poco::Data::NotConnectedException;
|
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()
|
void DataTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1415,6 +1449,7 @@ CppUnit::Test* DataTest::suite()
|
|||||||
CppUnit_addTest(pSuite, DataTest, testRowFormat);
|
CppUnit_addTest(pSuite, DataTest, testRowFormat);
|
||||||
CppUnit_addTest(pSuite, DataTest, testDateAndTime);
|
CppUnit_addTest(pSuite, DataTest, testDateAndTime);
|
||||||
CppUnit_addTest(pSuite, DataTest, testExternalBindingAndExtraction);
|
CppUnit_addTest(pSuite, DataTest, testExternalBindingAndExtraction);
|
||||||
|
CppUnit_addTest(pSuite, DataTest, testNullable);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ public:
|
|||||||
void testRowFormat();
|
void testRowFormat();
|
||||||
void testDateAndTime();
|
void testDateAndTime();
|
||||||
void testExternalBindingAndExtraction();
|
void testExternalBindingAndExtraction();
|
||||||
|
void testNullable();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user