mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-12 14:59:19 +01:00
Merge pull request #1381 from dhossein/issue-1375
Issue 1375 - Add API for defining SQLite types at runtime & improve behavior for unknown types
This commit is contained in:
commit
3feaaa6987
@ -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));
|
||||
@ -147,9 +167,12 @@ MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size
|
||||
sqliteType = sqliteType.substr(0, sqliteType.find_first_of(" ("));
|
||||
|
||||
TypeMap::const_iterator it = _types.find(Poco::trimInPlace(sqliteType));
|
||||
if (_types.end() == it) throw Poco::NotFoundException();
|
||||
|
||||
return it->second;
|
||||
if (_types.end() == it) {
|
||||
return MetaColumn::FDT_BLOB;
|
||||
}
|
||||
else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user