mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-24 06:14:31 +01:00
SQLite fixes; minor cosmetic fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Binder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Binder.cpp#4 $
|
||||
// $Id: //poco/Main/Data/SQLite/src/Binder.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
@@ -38,10 +38,16 @@
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::DateTimeFormatter;
|
||||
using Poco::DateTimeFormat;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
@@ -58,35 +64,35 @@ Binder::~Binder()
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32 &val)
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32 &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_int(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int64 &val)
|
||||
void Binder::bind(std::size_t pos, const Poco::Int64 &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_int64(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const double &val)
|
||||
void Binder::bind(std::size_t pos, const double &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_double(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const std::string& val)
|
||||
void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_text(_pStmt, (int) pos, val.c_str(), (int) val.size()*sizeof(char), SQLITE_TRANSIENT);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
|
||||
void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir)
|
||||
{
|
||||
// convert a blob to a an unsigned char* array
|
||||
const unsigned char* pData = reinterpret_cast<const unsigned char*>(val.rawContent());
|
||||
@@ -97,6 +103,13 @@ void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
|
||||
{
|
||||
std::string dt(DateTimeFormatter::format(val, DateTimeFormat::ISO8601_FORMAT));
|
||||
bind(pos, dt, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::checkReturn(int rc)
|
||||
{
|
||||
if (rc != SQLITE_OK)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#4 $
|
||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
@@ -38,11 +38,15 @@
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::DateTimeParser;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
@@ -190,6 +194,16 @@ bool Extractor::extract(std::size_t pos, char& val)
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SQLiteStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#6 $
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
@@ -48,7 +48,8 @@ namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
SQLiteStatementImpl::SQLiteStatementImpl(sqlite3* pDB):
|
||||
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
|
||||
StatementImpl(rSession),
|
||||
_pDB(pDB),
|
||||
_pStmt(0),
|
||||
_stepCalled(false),
|
||||
@@ -177,13 +178,17 @@ bool SQLiteStatementImpl::hasNext()
|
||||
// _pStmt is allowed to be null for conditional SQL statements
|
||||
if (_pStmt == 0)
|
||||
{
|
||||
_stepCalled = true;
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_stepCalled = true;
|
||||
_stepCalled = true;
|
||||
_nextResponse = sqlite3_step(_pStmt);
|
||||
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
|
||||
{
|
||||
Utility::throwException(_nextResponse);
|
||||
}
|
||||
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SessionImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SessionImpl.cpp#4 $
|
||||
// $Id: //poco/Main/Data/SQLite/src/SessionImpl.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
@@ -69,13 +69,13 @@ SessionImpl::~SessionImpl()
|
||||
Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
{
|
||||
poco_check_ptr (_pDB);
|
||||
return new SQLiteStatementImpl(_pDB);
|
||||
return new SQLiteStatementImpl(*this, _pDB);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
@@ -83,7 +83,7 @@ void SessionImpl::begin()
|
||||
|
||||
void SessionImpl::commit()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(COMMIT_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ void SessionImpl::commit()
|
||||
|
||||
void SessionImpl::rollback()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(ABORT_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user