mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-20 18:00:05 +01:00
Add API to allow SQLite types to be added at runtime
- new types can be added via Poco::Data::SQLite::Utility::addColumnType() issue-1375
This commit is contained in:
parent
cb25a7f4a9
commit
60ecf597c4
@ -56,6 +56,15 @@ public:
|
||||
static const int OPERATION_DELETE;
|
||||
static const int OPERATION_UPDATE;
|
||||
|
||||
static void addColumnType(std::string sqliteType, MetaColumn::ColumnDataType pocoType);
|
||||
/// Adds or replaces the mapping for SQLite column type \p sqliteType
|
||||
/// to a Poco type \p pocoType
|
||||
///
|
||||
/// \p sqliteType is a case-insensitive desription of the column type with
|
||||
/// any value \p pocoType value but MetaColumn::FDT_UNKNOWN. A
|
||||
/// Poco::Data::NotSupportedException is thrown if \p pocoType is invalid.
|
||||
|
||||
|
||||
static sqlite3* dbHandle(const Session& session);
|
||||
/// Returns native DB handle.
|
||||
|
||||
@ -190,6 +199,8 @@ private:
|
||||
Utility(const Utility&);
|
||||
Utility& operator = (const Utility&);
|
||||
|
||||
static void initializeDefaultTypes();
|
||||
|
||||
static void* eventHookRegister(sqlite3* pDB, UpdateCallbackType callbackFn, void* pParam);
|
||||
static void* eventHookRegister(sqlite3* pDB, CommitCallbackType callbackFn, void* pParam);
|
||||
static void* eventHookRegister(sqlite3* pDB, RollbackCallbackType callbackFn, void* pParam);
|
||||
|
@ -62,6 +62,11 @@ Poco::Mutex Utility::_mutex;
|
||||
|
||||
|
||||
Utility::Utility()
|
||||
{
|
||||
initializeDefaultTypes();
|
||||
}
|
||||
|
||||
void Utility::initializeDefaultTypes()
|
||||
{
|
||||
if (_types.empty())
|
||||
{
|
||||
@ -125,6 +130,21 @@ Utility::Utility()
|
||||
}
|
||||
|
||||
|
||||
void Utility::addColumnType(std::string sqliteType, MetaColumn::ColumnDataType pocoType)
|
||||
{
|
||||
// Check for errors in the mapping
|
||||
if (MetaColumn::FDT_UNKNOWN == pocoType)
|
||||
throw Poco::Data::NotSupportedException("Cannot map to unknown poco type.");
|
||||
|
||||
// Initialize default types
|
||||
initializeDefaultTypes();
|
||||
|
||||
// Add type to internal map
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
_types[sqliteType] = pocoType;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3* pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
|
Loading…
x
Reference in New Issue
Block a user