mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
new trunk (base for 1.5)
windows build only
This commit is contained in:
239
Data/SQLite/include/Poco/Data/SQLite/Binder.h
Normal file
239
Data/SQLite/include/Poco/Data/SQLite/Binder.h
Normal file
@@ -0,0 +1,239 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Binder.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Binder_INCLUDED
|
||||
#define Data_SQLite_Binder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
Binder(sqlite3_stmt* pStmt);
|
||||
/// Creates the Binder.
|
||||
|
||||
~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int8 &val, Direction dir);
|
||||
/// Binds an Int8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt8 &val, Direction dir);
|
||||
/// Binds an UInt8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int16 &val, Direction dir);
|
||||
/// Binds an Int16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt16 &val, Direction dir);
|
||||
/// Binds an UInt16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int32 &val, Direction dir);
|
||||
/// Binds an Int32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt32 &val, Direction dir);
|
||||
/// Binds an UInt32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int64 &val, Direction dir);
|
||||
/// Binds an Int64.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt64 &val, Direction dir);
|
||||
/// Binds an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
void bind(std::size_t pos, const long &val, Direction dir);
|
||||
/// Binds a long
|
||||
#endif
|
||||
|
||||
void bind(std::size_t pos, const bool &val, Direction dir);
|
||||
/// Binds a boolean.
|
||||
|
||||
void bind(std::size_t pos, const float &val, Direction dir);
|
||||
/// Binds a float.
|
||||
|
||||
void bind(std::size_t pos, const double &val, Direction dir);
|
||||
/// Binds a double.
|
||||
|
||||
void bind(std::size_t pos, const char &val, Direction dir);
|
||||
/// Binds a single character.
|
||||
|
||||
void bind(std::size_t pos, const char* const &pVal, Direction dir);
|
||||
/// Binds a const char ptr.
|
||||
|
||||
void bind(std::size_t pos, const std::string& val, Direction dir);
|
||||
/// Binds a string.
|
||||
|
||||
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.
|
||||
|
||||
void bind(std::size_t pos, const Time& val, Direction dir);
|
||||
/// Binds a Time.
|
||||
|
||||
void bind(std::size_t pos, const DateTime& val, Direction dir);
|
||||
/// Binds a DateTime.
|
||||
|
||||
void bind(std::size_t pos, const NullData& val, Direction dir);
|
||||
/// Binds a null.
|
||||
|
||||
private:
|
||||
void checkReturn(int rc);
|
||||
/// 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;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int8 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt8 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int16 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt16 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt32 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = static_cast<Poco::Int32>(val);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt64 &val, Direction dir)
|
||||
{
|
||||
Poco::Int64 tmp = static_cast<Poco::Int64>(val);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const bool &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = (val ? 1 : 0);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const float &val, Direction dir)
|
||||
{
|
||||
double tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char* const &pVal, Direction dir)
|
||||
{
|
||||
std::string val(pVal);
|
||||
bind(pos, val, 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
|
||||
|
||||
|
||||
#endif // Data_SQLite_Binder_INCLUDED
|
||||
101
Data/SQLite/include/Poco/Data/SQLite/Connector.h
Normal file
101
Data/SQLite/include/Poco/Data/SQLite/Connector.h
Normal file
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Connector.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Connector.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Connector
|
||||
//
|
||||
// Definition of the Connector class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Connector_INCLUDED
|
||||
#define Data_SQLite_Connector_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Connector: public Poco::Data::Connector
|
||||
/// Connector instantiates SqLite SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating SQLite sessions ("SQLite").
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
|
||||
~Connector();
|
||||
/// Destroys the Connector.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString,
|
||||
std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates a SQLite SessionImpl object and initializes it with the given connectionString.
|
||||
|
||||
static void registerConnector();
|
||||
/// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void unregisterConnector();
|
||||
/// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void enableSharedCache(bool flag = true);
|
||||
/// Enables or disables SQlite shared cache mode
|
||||
/// (see http://www.sqlite.org/sharedcache.html for a discussion).
|
||||
|
||||
static void enableSoftHeapLimit(int limit);
|
||||
/// Sets a soft upper limit to the amount of memory allocated
|
||||
/// by SQLite. For more information, please see the SQLite
|
||||
/// sqlite_soft_heap_limit() function (http://www.sqlite.org/c3ref/soft_heap_limit.html).
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline const std::string& Connector::name() const
|
||||
{
|
||||
return KEY;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_Connector_INCLUDED
|
||||
328
Data/SQLite/include/Poco/Data/SQLite/Extractor.h
Normal file
328
Data/SQLite/include/Poco/Data/SQLite/Extractor.h
Normal file
@@ -0,0 +1,328 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Extractor.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Extractor_INCLUDED
|
||||
#define Data_SQLite_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/Data/Constants.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "sqlite3.h"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values form the result row returned by SQLite.
|
||||
/// 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.
|
||||
|
||||
~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
bool extract(std::size_t pos, long& val);
|
||||
/// Extracts a long.
|
||||
#endif
|
||||
|
||||
bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
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.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::Time& val);
|
||||
/// Extracts a Time.
|
||||
|
||||
bool extract(std::size_t pos, Poco::DateTime& val);
|
||||
/// Extracts a DateTime.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Any& val);
|
||||
/// Extracts an Any.
|
||||
|
||||
bool extract(std::size_t pos, Poco::DynamicAny& val);
|
||||
/// Extracts a DynamicAny.
|
||||
|
||||
bool isNull(std::size_t pos, std::size_t row = POCO_DATA_INVALID_ROW);
|
||||
/// 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.
|
||||
/// The row argument, needed for connectors with bulk capabilities,
|
||||
/// is ignored in this implementation.
|
||||
|
||||
void reset();
|
||||
/// Clears the cached nulls indicator vector.
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
bool extractImpl(std::size_t pos, T& val)
|
||||
/// Utility function for extraction of Any and DynamicAny.
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
|
||||
bool ret = false;
|
||||
|
||||
switch (Utility::getColumnType(_pStmt, pos))
|
||||
{
|
||||
case MetaColumn::FDT_BOOL:
|
||||
{
|
||||
bool i = false;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT8:
|
||||
{
|
||||
Poco::Int8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT8:
|
||||
{
|
||||
Poco::UInt8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT16:
|
||||
{
|
||||
Poco::Int16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT16:
|
||||
{
|
||||
Poco::UInt16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT32:
|
||||
{
|
||||
Poco::Int32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT32:
|
||||
{
|
||||
Poco::UInt32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT64:
|
||||
{
|
||||
Poco::Int64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT64:
|
||||
{
|
||||
Poco::UInt64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_STRING:
|
||||
{
|
||||
std::string s;
|
||||
ret = extract(pos, s);
|
||||
val = s;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_DOUBLE:
|
||||
{
|
||||
double d(0.0);
|
||||
ret = extract(pos, d);
|
||||
val = d;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_FLOAT:
|
||||
{
|
||||
float f(0.0);
|
||||
ret = extract(pos, f);
|
||||
val = f;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_BLOB:
|
||||
{
|
||||
BLOB b;
|
||||
ret = extract(pos, b);
|
||||
val = b;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_DATE:
|
||||
{
|
||||
Date d;
|
||||
ret = extract(pos, d);
|
||||
val = d;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_TIME:
|
||||
{
|
||||
Time t;
|
||||
ret = extract(pos, t);
|
||||
val = t;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_TIMESTAMP:
|
||||
{
|
||||
DateTime dt;
|
||||
ret = extract(pos, dt);
|
||||
val = dt;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Poco::Data::UnknownTypeException("Unknown type during extraction");
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline void Extractor::reset()
|
||||
{
|
||||
_nulls.clear();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
#endif // Data_SQLite_Extractor_INCLUDED
|
||||
92
Data/SQLite/include/Poco/Data/SQLite/SQLite.h
Normal file
92
Data/SQLite/include/Poco/Data/SQLite/SQLite.h
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// SQLite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLite.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLIte
|
||||
// Module: SQLite
|
||||
//
|
||||
// Basic definitions for the Poco SQLite library.
|
||||
// This file must be the first file included by every other SQLite
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLite_INCLUDED
|
||||
#define SQLite_SQLite_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the SQLite_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// SQLite_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(SQLite_EXPORTS)
|
||||
#define SQLite_API __declspec(dllexport)
|
||||
#else
|
||||
#define SQLite_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(SQLite_API)
|
||||
#define SQLite_API
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Data library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(SQLite_EXPORTS)
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoDataSQLited.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoDataSQLite.lib")
|
||||
#endif
|
||||
#else
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoDataSQLitemtd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoDataSQLitemt.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SQLite_SQLite_INCLUDED
|
||||
82
Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h
Normal file
82
Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// SQLiteException.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteException
|
||||
//
|
||||
// Definition of SQLiteException.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLiteException_INCLUDED
|
||||
#define SQLite_SQLiteException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SQLiteException, Poco::Data::DataException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidSQLStatementException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InternalDBErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBAccessDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ExecutionAbortedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, NoMemoryException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ReadOnlyException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InterruptException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, IOErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CorruptImageException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableNotFoundException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DatabaseFullException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CantOpenDBFileException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, LockProtocolException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SchemaDiffersException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, RowTooBigException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ConstraintViolationException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DataTypeMismatchException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ParameterCountMismatchException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidLibraryUseException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, OSFeaturesMissingException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, AuthorizationDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TransactionException, SQLiteException)
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif
|
||||
177
Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h
Normal file
177
Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h
Normal file
@@ -0,0 +1,177 @@
|
||||
//
|
||||
// SQLiteStatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// Definition of the SQLiteStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
#define Data_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SQLiteStatementImpl: public Poco::Data::StatementImpl
|
||||
/// Implements statement functionality needed for SQLite
|
||||
{
|
||||
public:
|
||||
SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB);
|
||||
/// Creates the SQLiteStatementImpl.
|
||||
|
||||
~SQLiteStatementImpl();
|
||||
/// Destroys the SQLiteStatementImpl.
|
||||
|
||||
protected:
|
||||
std::size_t columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
std::size_t affectedRowCount() const;
|
||||
/// Returns the number of affected rows.
|
||||
/// Used to find out the number of rows affected by insert, delete or update.
|
||||
/// All changes are counted, even if they are later undone by a ROLLBACK or ABORT.
|
||||
/// Changes associated with creating and dropping tables are not counted.
|
||||
/// SQLite implements the command "DELETE FROM table" without a WHERE clause by
|
||||
/// dropping and recreating the table. Because of this optimization, the change count
|
||||
/// for "DELETE FROM table" will be zero regardless of the number of elements that
|
||||
/// were originally in the table. To get an accurate count of the number of rows deleted,
|
||||
/// use "DELETE FROM table WHERE 1".
|
||||
|
||||
const MetaColumn& metaColumn(std::size_t pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
std::size_t next();
|
||||
/// Retrieves the next row from the resultset and returns 1.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
bool canCompile() const;
|
||||
/// Returns true if statement can compile.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet.
|
||||
/// Returns true if the statement was succesfully compiled.
|
||||
/// The way SQLite handles batches of statmeents is by compiling
|
||||
/// one at a time and returning a pointer to the next one.
|
||||
/// The remainder of the statement is kept in a string
|
||||
/// buffer pointed to by _pLeftover member.
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
void clear();
|
||||
/// Removes the _pStmt
|
||||
|
||||
typedef Poco::SharedPtr<Binder> BinderPtr;
|
||||
typedef Poco::SharedPtr<Extractor> ExtractorPtr;
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
typedef Poco::Data::AbstractExtractionVec Extractions;
|
||||
typedef std::vector<Poco::Data::MetaColumn> MetaColumnVec;
|
||||
typedef std::vector<MetaColumnVec> MetaColumnVecVec;
|
||||
typedef Poco::SharedPtr<std::string> StrPtr;
|
||||
typedef Bindings::iterator BindIt;
|
||||
|
||||
sqlite3* _pDB;
|
||||
sqlite3_stmt* _pStmt;
|
||||
bool _stepCalled;
|
||||
int _nextResponse;
|
||||
BinderPtr _pBinder;
|
||||
ExtractorPtr _pExtractor;
|
||||
MetaColumnVecVec _columns;
|
||||
std::size_t _affectedRowCount;
|
||||
StrPtr _pLeftover;
|
||||
BindIt _bindBegin;
|
||||
bool _canBind;
|
||||
bool _isExtracted;
|
||||
bool _canCompile;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtractor& SQLiteStatementImpl::extractor()
|
||||
{
|
||||
return *_pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder& SQLiteStatementImpl::binder()
|
||||
{
|
||||
return *_pBinder;
|
||||
}
|
||||
|
||||
|
||||
inline bool SQLiteStatementImpl::canBind() const
|
||||
{
|
||||
return _canBind;
|
||||
}
|
||||
|
||||
|
||||
inline bool SQLiteStatementImpl::canCompile() const
|
||||
{
|
||||
return _canCompile;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
163
Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h
Normal file
163
Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h
Normal file
@@ -0,0 +1,163 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_SessionImpl_INCLUDED
|
||||
#define Data_SQLite_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// Implements SessionImpl interface.
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& fileName,
|
||||
std::size_t loginTimeout = LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates the SessionImpl. Opens a connection to the database.
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an SQLite StatementImpl.
|
||||
|
||||
void open(const std::string& connect = "");
|
||||
/// Opens a connection to the Database.
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true if connected, false otherwise.
|
||||
|
||||
void setConnectionTimeout(std::size_t timeout);
|
||||
/// Sets the session connection timeout value.
|
||||
|
||||
std::size_t getConnectionTimeout();
|
||||
/// Returns the session connection timeout value.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction.
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction.
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction.
|
||||
|
||||
bool canTransact();
|
||||
/// Returns true if session has transaction capabilities.
|
||||
|
||||
bool isTransaction();
|
||||
/// Returns true iff a transaction is a transaction is in progress, false otherwise.
|
||||
|
||||
void setTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Sets the transaction isolation level.
|
||||
|
||||
Poco::UInt32 getTransactionIsolation();
|
||||
/// Returns the transaction isolation level.
|
||||
|
||||
bool hasTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Returns true iff the transaction isolation level corresponding
|
||||
/// to the supplied bitmask is supported.
|
||||
|
||||
bool isTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Returns true iff the transaction isolation level corresponds
|
||||
/// to the supplied bitmask.
|
||||
|
||||
const std::string& connectorName();
|
||||
/// Returns the name of the connector.
|
||||
|
||||
private:
|
||||
|
||||
std::string _connector;
|
||||
sqlite3* _pDB;
|
||||
bool _connected;
|
||||
bool _isTransaction;
|
||||
int _timeout;
|
||||
|
||||
static const std::string DEFERRED_BEGIN_TRANSACTION;
|
||||
static const std::string COMMIT_TRANSACTION;
|
||||
static const std::string ABORT_TRANSACTION;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool SessionImpl::canTransact()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isTransaction()
|
||||
{
|
||||
return _isTransaction;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& SessionImpl::connectorName()
|
||||
{
|
||||
return _connector;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SessionImpl::getConnectionTimeout()
|
||||
{
|
||||
return static_cast<std::size_t>(_timeout);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_SessionImpl_INCLUDED
|
||||
104
Data/SQLite/include/Poco/Data/SQLite/Utility.h
Normal file
104
Data/SQLite/include/Poco/Data/SQLite/Utility.h
Normal file
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// Utility.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Utility.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Definition of Utility.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_Utility_INCLUDED
|
||||
#define SQLite_Utility_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Utility
|
||||
/// Various utility functions for SQLite, mostly return code handling
|
||||
{
|
||||
public:
|
||||
static const std::string SQLITE_DATE_FORMAT;
|
||||
static const std::string SQLITE_TIME_FORMAT;
|
||||
typedef std::map<std::string, MetaColumn::ColumnDataType> TypeMap;
|
||||
|
||||
Utility();
|
||||
/// Maps SQLite column declared types to Poco::Data types through
|
||||
/// static TypeMap member.
|
||||
/// Note: SQLite is type-agnostic and it is the end-user responsibility
|
||||
/// to ensure that column declared data type corresponds to the type of
|
||||
/// data actually held in the database.
|
||||
/// Column types are case-insensitive.
|
||||
|
||||
static std::string lastError(sqlite3* pDb);
|
||||
/// Retreives the last error code from sqlite and converts it to a string
|
||||
|
||||
static void throwException(int rc, const std::string& addErrMsg = std::string());
|
||||
/// Throws for an error code the appropriate exception
|
||||
|
||||
static MetaColumn::ColumnDataType getColumnType(sqlite3_stmt* pStmt, std::size_t pos);
|
||||
/// Returns column data type.
|
||||
|
||||
static bool fileToMemory(sqlite3* pInMemory, const std::string& fileName);
|
||||
/// Loads the contents of a database file on disk into an opened
|
||||
/// database in memory.
|
||||
///
|
||||
/// Returns true if succesful
|
||||
|
||||
static bool memoryToFile(const std::string& fileName, sqlite3* pInMemory);
|
||||
/// Saves the contents of an opened database in memory to the
|
||||
/// database on disk.
|
||||
///
|
||||
/// Returns true if succesful
|
||||
|
||||
private:
|
||||
static TypeMap _types;
|
||||
Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user