[SF 2272430] BLOB and CLOB

Renamed:
(Abstract)Preparation => (Abstract)Preparator
(Abstract)Prepare => (Abstract)Preparation
This commit is contained in:
Aleksandar Fabijanic
2008-11-24 00:38:23 +00:00
parent 161e49a6d4
commit a42e8d919b
75 changed files with 2616 additions and 2832 deletions

View File

@@ -42,11 +42,10 @@
#include "Poco/Data/SQLite/SQLite.h"
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/LOB.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
struct sqlite3_stmt;
#include "sqlite3.h"
namespace Poco {
@@ -114,6 +113,9 @@ public:
void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir);
/// Binds a BLOB.
void bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir);
/// Binds a CLOB.
void bind(std::size_t pos, const Date& val, Direction dir);
/// Binds a Date.
@@ -131,6 +133,17 @@ private:
/// Checks the SQLite return code and throws an appropriate exception
/// if error has occurred.
template <typename T>
void bindLOB(std::size_t pos, const Poco::Data::LOB<T>& val, Direction dir)
{
// convert a blob to a an unsigned char* array
const T* pData = reinterpret_cast<const T*>(val.rawContent());
int valSize = static_cast<int>(val.size());
int rc = sqlite3_bind_blob(_pStmt, static_cast<int>(pos), pData, valSize, SQLITE_STATIC); // no deep copy, do not free memory
checkReturn(rc);
}
sqlite3_stmt* _pStmt;
};
@@ -208,6 +221,18 @@ inline void Binder::bind(std::size_t pos, const char* const &pVal, Direction dir
}
inline void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir)
{
bindLOB<Poco::Data::BLOB::ValueType>(pos, val, dir);
}
inline void Binder::bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir)
{
bindLOB<Poco::Data::CLOB::ValueType>(pos, val, dir);
}
} } } // namespace Poco::Data::SQLite

View File

@@ -48,13 +48,11 @@
#include "Poco/Data/Constants.h"
#include "Poco/Any.h"
#include "Poco/DynamicAny.h"
#include "sqlite3.h"
#include <vector>
#include <utility>
struct sqlite3_stmt;
namespace Poco {
namespace Data {
namespace SQLite {
@@ -121,6 +119,9 @@ public:
bool extract(std::size_t pos, Poco::Data::BLOB& val);
/// Extracts a BLOB.
bool extract(std::size_t pos, Poco::Data::CLOB& val);
/// Extracts a CLOB.
bool extract(std::size_t pos, Poco::Data::Date& val);
/// Extracts a Date.
@@ -285,6 +286,16 @@ private:
return ret;
}
template <typename T>
bool extractLOB(std::size_t pos, Poco::Data::LOB<T>& val)
{
if (isNull(pos)) return false;
int size = sqlite3_column_bytes(_pStmt, (int) pos);
const T* pTmp = reinterpret_cast<const T*>(sqlite3_column_blob(_pStmt, (int) pos));
val = Poco::Data::LOB<T>(pTmp, size);
return true;
}
sqlite3_stmt* _pStmt;
NullIndVec _nulls;
};
@@ -299,6 +310,18 @@ inline void Extractor::reset()
}
inline bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
{
return extractLOB<Poco::Data::BLOB::ValueType>(pos, val);
}
inline bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
{
return extractLOB<Poco::Data::CLOB::ValueType>(pos, val);
}
} } } // namespace Poco::Data::SQLite