null bindings and RecordSet::isNull (SQLite done and tested, ODBC todo)

This commit is contained in:
Aleksandar Fabijanic
2007-06-19 23:24:16 +00:00
parent 6a5afde278
commit 7fac905b65
21 changed files with 402 additions and 44 deletions

View File

@@ -63,57 +63,61 @@ public:
~Binder();
/// Destroys the Binder.
void bind(std::size_t pos, const Poco::Int8 &val, Direction dir);
void bind(std::size_t pos, const Poco::Int8 &val, Direction dir = PD_IN);
/// Binds an Int8.
void bind(std::size_t pos, const Poco::UInt8 &val, Direction dir);
void bind(std::size_t pos, const Poco::UInt8 &val, Direction dir = PD_IN);
/// Binds an UInt8.
void bind(std::size_t pos, const Poco::Int16 &val, Direction dir);
void bind(std::size_t pos, const Poco::Int16 &val, Direction dir = PD_IN);
/// Binds an Int16.
void bind(std::size_t pos, const Poco::UInt16 &val, Direction dir);
void bind(std::size_t pos, const Poco::UInt16 &val, Direction dir = PD_IN);
/// Binds an UInt16.
void bind(std::size_t pos, const Poco::Int32 &val, Direction dir);
void bind(std::size_t pos, const Poco::Int32 &val, Direction dir = PD_IN);
/// Binds an Int32.
void bind(std::size_t pos, const Poco::UInt32 &val, Direction dir);
void bind(std::size_t pos, const Poco::UInt32 &val, Direction dir = PD_IN);
/// Binds an UInt32.
void bind(std::size_t pos, const Poco::Int64 &val, Direction dir);
void bind(std::size_t pos, const Poco::Int64 &val, Direction dir = PD_IN);
/// Binds an Int64.
void bind(std::size_t pos, const Poco::UInt64 &val, Direction dir);
void bind(std::size_t pos, const Poco::UInt64 &val, Direction dir = PD_IN);
/// Binds an UInt64.
void bind(std::size_t pos, const bool &val, Direction dir);
void bind(std::size_t pos, const bool &val, Direction dir = PD_IN);
/// Binds a boolean.
void bind(std::size_t pos, const float &val, Direction dir);
void bind(std::size_t pos, const float &val, Direction dir = PD_IN);
/// Binds a float.
void bind(std::size_t pos, const double &val, Direction dir);
void bind(std::size_t pos, const double &val, Direction dir = PD_IN);
/// Binds a double.
void bind(std::size_t pos, const char &val, Direction dir);
void bind(std::size_t pos, const char &val, Direction dir = PD_IN);
/// Binds a single character.
void bind(std::size_t pos, const char* const &pVal, Direction dir);
void bind(std::size_t pos, const char* const &pVal, Direction dir = PD_IN);
/// Binds a const char ptr.
void bind(std::size_t pos, const std::string& val, Direction dir);
void bind(std::size_t pos, const std::string& val, Direction dir = PD_IN);
/// Binds a string.
void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir);
void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir = PD_IN);
/// Binds a BLOB.
void bind(std::size_t pos, const DateTime& val, Direction dir);
void bind(std::size_t pos, const DateTime& val, Direction dir = PD_IN);
/// Binds a DateTime.
void bind(std::size_t pos, const NullData& val, Direction dir = PD_IN);
/// Binds a null.
private:
void checkReturn(int rc);
/// Checks the SQLite return code and throws an appropriate exception.
/// Checks the SQLite return code and throws an appropriate exception
/// if error has occurred.
sqlite3_stmt* _pStmt;
};

View File

@@ -43,6 +43,8 @@
#include "Poco/Data/SQLite/SQLite.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Any.h"
#include <vector>
#include <utility>
struct sqlite3_stmt;
@@ -58,6 +60,9 @@ class SQLite_API Extractor: public Poco::Data::AbstractExtractor
/// If NULL is received, the incoming val value is not changed and false is returned
{
public:
typedef std::vector<std::pair<bool, bool> > NullIndVec;
/// Type for null indicators container.
Extractor(sqlite3_stmt* pStmt);
/// Creates the Extractor.
@@ -112,14 +117,38 @@ public:
bool extract(std::size_t pos, Poco::Any& val);
/// Extracts an Any.
private:
bool isNull(std::size_t pos);
/// Returns true if a non null value can be extracted
/// Returns true if the current row value at pos column is null.
/// Because of the loss of information about null-ness of the
/// underlying database values due to the nature of SQLite engine,
/// (once null value is converted to default value, SQLite API
/// treats it as non-null), a null indicator container member
/// variable is used to cache the indicators of the underlying nulls
/// thus rendering this function idempotent.
/// The container is a vector of [bool, bool] pairs.
/// The vector index corresponds to the column position, the first
/// bool value in the pair is true if the null indicator has
/// been set and the second bool value in the pair is true if
/// the column is actually null.
void reset();
/// Clears the cached nulls indicator vector.
private:
sqlite3_stmt* _pStmt;
NullIndVec _nulls;
};
///
/// inlines
///
inline void Extractor::reset()
{
_nulls.clear();
}
} } } // namespace Poco::Data::SQLite