- fixed broken 2010 projects

- session handle property for SQLite and ODBC
- SQLite database utility functions and test:
(1) loading from disk to memory
(2) saving from memory to disk
This commit is contained in:
Aleksandar Fabijanic 2012-03-22 03:02:08 +00:00
parent 1421d93684
commit 3df497d2bf
13 changed files with 519 additions and 377 deletions

View File

@ -553,7 +553,6 @@
<ClInclude Include="include\Poco\Data\Nullable.h" />
<ClInclude Include="include\Poco\Data\Position.h" />
<ClInclude Include="include\Poco\Data\Preparation.h" />
<ClInclude Include="include\Poco\Data\Prepare.h" />
<ClInclude Include="include\Poco\Data\Range.h" />
<ClInclude Include="include\Poco\Data\RecordSet.h" />
<ClInclude Include="include\Poco\Data\Row.h" />

View File

@ -66,9 +66,6 @@
<ClInclude Include="include\Poco\Data\MetaColumn.h">
<Filter>DataCore\Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Poco\Data\Prepare.h">
<Filter>DataCore\Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Poco\Data\Range.h">
<Filter>DataCore\Header Files</Filter>
</ClInclude>

View File

@ -64,6 +64,7 @@ SessionImpl::SessionImpl(const std::string& connect,
{
setFeature("bulk", true);
open();
setProperty("handle", _db.handle());
}
@ -81,6 +82,7 @@ SessionImpl::SessionImpl(const std::string& connect,
{
setFeature("bulk", true);
open();
setProperty("handle", _db.handle());
}

View File

@ -591,6 +591,7 @@
<ClInclude Include="src\ODBCPostgreSQLTest.h" />
<ClInclude Include="src\ODBCSQLiteTest.h" />
<ClInclude Include="src\ODBCSQLServerTest.h" />
<ClInclude Include="src\ODBCTest.h" />
<ClInclude Include="src\SQLExecutor.h" />
<ClInclude Include="src\ODBCTestSuite.h" />
</ItemGroup>
@ -602,6 +603,7 @@
<ClCompile Include="src\ODBCPostgreSQLTest.cpp" />
<ClCompile Include="src\ODBCSQLiteTest.cpp" />
<ClCompile Include="src\ODBCSQLServerTest.cpp" />
<ClCompile Include="src\ODBCTest.cpp" />
<ClCompile Include="src\SQLExecutor.cpp" />
<ClCompile Include="src\ODBCTestSuite.cpp" />
<ClCompile Include="src\WinDriver.cpp" />

View File

@ -1,90 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ODBC">
<UniqueIdentifier>{c5cec821-0524-43b8-81ea-5df3a1e4b946}</UniqueIdentifier>
</Filter>
<Filter Include="ODBC\Header Files">
<UniqueIdentifier>{a51e3807-e57e-4bb0-9d18-b523225cd3c9}</UniqueIdentifier>
</Filter>
<Filter Include="ODBC\Source Files">
<UniqueIdentifier>{8e3b07e7-9990-4378-98e1-1cbb100c0f61}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite">
<UniqueIdentifier>{4547d3b9-813f-4924-878d-a64840811788}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Header Files">
<UniqueIdentifier>{b2d8646e-bdce-49da-bcd7-ac3a7d8758a0}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Source Files">
<UniqueIdentifier>{a6d83c9b-b6ee-4d52-9fcb-28bac6819736}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver">
<UniqueIdentifier>{1abcef51-76ca-49fa-8b31-23e3180b9886}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver\Source Files">
<UniqueIdentifier>{a9ebdc24-5c46-4506-9bdb-1dbb66e2baca}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\ODBCAccessTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCDB2Test.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCMySQLTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCOracleTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCPostgreSQLTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCSQLiteTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCSQLServerTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SQLExecutor.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCTestSuite.h">
<Filter>_Suite\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ODBCAccessTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCDB2Test.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCMySQLTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCOracleTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCPostgreSQLTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCSQLiteTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCSQLServerTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SQLExecutor.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCTestSuite.cpp">
<Filter>_Suite\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\WinDriver.cpp">
<Filter>_Driver\Source Files</Filter>
</ClCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ODBC">
<UniqueIdentifier>{c5cec821-0524-43b8-81ea-5df3a1e4b946}</UniqueIdentifier>
</Filter>
<Filter Include="ODBC\Header Files">
<UniqueIdentifier>{a51e3807-e57e-4bb0-9d18-b523225cd3c9}</UniqueIdentifier>
</Filter>
<Filter Include="ODBC\Source Files">
<UniqueIdentifier>{8e3b07e7-9990-4378-98e1-1cbb100c0f61}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite">
<UniqueIdentifier>{4547d3b9-813f-4924-878d-a64840811788}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Header Files">
<UniqueIdentifier>{b2d8646e-bdce-49da-bcd7-ac3a7d8758a0}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Source Files">
<UniqueIdentifier>{a6d83c9b-b6ee-4d52-9fcb-28bac6819736}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver">
<UniqueIdentifier>{1abcef51-76ca-49fa-8b31-23e3180b9886}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver\Source Files">
<UniqueIdentifier>{a9ebdc24-5c46-4506-9bdb-1dbb66e2baca}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\ODBCAccessTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCDB2Test.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCMySQLTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCOracleTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCPostgreSQLTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCSQLiteTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCSQLServerTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SQLExecutor.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCTestSuite.h">
<Filter>_Suite\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ODBCTest.h">
<Filter>ODBC\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ODBCAccessTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCDB2Test.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCMySQLTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCOracleTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCPostgreSQLTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCSQLiteTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCSQLServerTest.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SQLExecutor.cpp">
<Filter>ODBC\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCTestSuite.cpp">
<Filter>_Suite\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\WinDriver.cpp">
<Filter>_Driver\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ODBCTest.cpp">
<Filter>ODBC\Header Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -80,6 +80,18 @@ public:
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;

View File

@ -67,6 +67,7 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
{
open();
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
setProperty("handle", _pDB);
}

View File

@ -1,212 +1,258 @@
//
// Utility.cpp
//
//
// Utility.cpp
//
// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#5 $
//
//
// Library: SQLite
// Package: SQLite
// Module: Utility
//
// Implementation 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.
//
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/NumberFormatter.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
namespace Poco {
namespace Data {
namespace SQLite {
// Package: SQLite
// Module: Utility
//
// Implementation 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.
//
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/NumberFormatter.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
namespace Poco {
namespace Data {
namespace SQLite {
const std::string Utility::SQLITE_DATE_FORMAT = "%Y-%m-%d";
const std::string Utility::SQLITE_TIME_FORMAT = "%H:%M:%S";
Utility::TypeMap Utility::_types;
Utility::TypeMap Utility::_types;
Utility::Utility()
{
{
Poco::FastMutex::ScopedLock l(_mutex);
if (_types.empty())
{
_types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("BOOL", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("BOOLEAN", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("BIT", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("UINT8", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("UTINY", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("UINTEGER8", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("INT8", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("TINY", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("INTEGER8", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("UINT16", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("USHORT", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("UINTEGER16", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("INT16", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("SHORT", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("INTEGER16", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("UINT", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("UINT32", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("UINTEGER32", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("INT", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INT32", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INTEGER", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INTEGER32", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("UINT64", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("ULONG", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("UINTEGER64", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("INT64", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("LONG", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("INTEGER64", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("COUNTER", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("AUTOINCREMENT", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("REAL", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("FLOA", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("FLOAT", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("DOUB", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("DOUBLE", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("CHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("CLOB", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("TEXT", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("VARCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NCLOB", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NTEXT", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NVARCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("BLOB", MetaColumn::FDT_BLOB));
if (_types.empty())
{
_types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("BOOL", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("BOOLEAN", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("BIT", MetaColumn::FDT_BOOL));
_types.insert(TypeMap::value_type("UINT8", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("UTINY", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("UINTEGER8", MetaColumn::FDT_UINT8));
_types.insert(TypeMap::value_type("INT8", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("TINY", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("INTEGER8", MetaColumn::FDT_INT8));
_types.insert(TypeMap::value_type("UINT16", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("USHORT", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("UINTEGER16", MetaColumn::FDT_UINT16));
_types.insert(TypeMap::value_type("INT16", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("SHORT", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("INTEGER16", MetaColumn::FDT_INT16));
_types.insert(TypeMap::value_type("UINT", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("UINT32", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("UINTEGER32", MetaColumn::FDT_UINT32));
_types.insert(TypeMap::value_type("INT", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INT32", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INTEGER", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("INTEGER32", MetaColumn::FDT_INT32));
_types.insert(TypeMap::value_type("UINT64", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("ULONG", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("UINTEGER64", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("INT64", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("LONG", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("INTEGER64", MetaColumn::FDT_INT64));
_types.insert(TypeMap::value_type("COUNTER", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("AUTOINCREMENT", MetaColumn::FDT_UINT64));
_types.insert(TypeMap::value_type("REAL", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("FLOA", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("FLOAT", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("DOUB", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("DOUBLE", MetaColumn::FDT_DOUBLE));
_types.insert(TypeMap::value_type("CHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("CLOB", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("TEXT", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("VARCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NCLOB", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NTEXT", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("NVARCHAR", MetaColumn::FDT_STRING));
_types.insert(TypeMap::value_type("BLOB", MetaColumn::FDT_BLOB));
_types.insert(TypeMap::value_type("DATE", MetaColumn::FDT_DATE));
_types.insert(TypeMap::value_type("TIME", MetaColumn::FDT_TIME));
_types.insert(TypeMap::value_type("DATETIME", MetaColumn::FDT_TIMESTAMP));
_types.insert(TypeMap::value_type("TIMESTAMP", MetaColumn::FDT_TIMESTAMP));
}
}
std::string Utility::lastError(sqlite3 *pDB)
{
return std::string(sqlite3_errmsg(pDB));
}
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
{
poco_assert_dbg (pStmt);
}
}
std::string Utility::lastError(sqlite3 *pDB)
{
return std::string(sqlite3_errmsg(pDB));
}
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
{
poco_assert_dbg (pStmt);
static Utility u;
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
std::string sqliteType = pc ? pc : "";
Poco::toUpperInPlace(sqliteType);
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;
}
void Utility::throwException(int rc, const std::string& addErrMsg)
{
switch (rc)
{
case SQLITE_OK:
break;
case SQLITE_ERROR:
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
std::string sqliteType = pc ? pc : "";
Poco::toUpperInPlace(sqliteType);
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;
}
void Utility::throwException(int rc, const std::string& addErrMsg)
{
switch (rc)
{
case SQLITE_OK:
break;
case SQLITE_ERROR:
throw InvalidSQLStatementException(std::string("SQL error or missing database"), addErrMsg);
case SQLITE_INTERNAL:
case SQLITE_INTERNAL:
throw InternalDBErrorException(std::string("An internal logic error in SQLite"), addErrMsg);
case SQLITE_PERM:
case SQLITE_PERM:
throw DBAccessDeniedException(std::string("Access permission denied"), addErrMsg);
case SQLITE_ABORT:
case SQLITE_ABORT:
throw ExecutionAbortedException(std::string("Callback routine requested an abort"), addErrMsg);
case SQLITE_BUSY:
case SQLITE_BUSY:
throw DBLockedException(std::string("The database file is locked"), addErrMsg);
case SQLITE_LOCKED:
case SQLITE_LOCKED:
throw TableLockedException(std::string("A table in the database is locked"), addErrMsg);
case SQLITE_NOMEM:
case SQLITE_NOMEM:
throw NoMemoryException(std::string("A malloc() failed"), addErrMsg);
case SQLITE_READONLY:
case SQLITE_READONLY:
throw ReadOnlyException(std::string("Attempt to write a readonly database"), addErrMsg);
case SQLITE_INTERRUPT:
case SQLITE_INTERRUPT:
throw InterruptException(std::string("Operation terminated by sqlite_interrupt()"), addErrMsg);
case SQLITE_IOERR:
case SQLITE_IOERR:
throw IOErrorException(std::string("Some kind of disk I/O error occurred"), addErrMsg);
case SQLITE_CORRUPT:
case SQLITE_CORRUPT:
throw CorruptImageException(std::string("The database disk image is malformed"), addErrMsg);
case SQLITE_NOTFOUND:
case SQLITE_NOTFOUND:
throw TableNotFoundException(std::string("Table or record not found"), addErrMsg);
case SQLITE_FULL:
case SQLITE_FULL:
throw DatabaseFullException(std::string("Insertion failed because database is full"), addErrMsg);
case SQLITE_CANTOPEN:
case SQLITE_CANTOPEN:
throw CantOpenDBFileException(std::string("Unable to open the database file"), addErrMsg);
case SQLITE_PROTOCOL:
case SQLITE_PROTOCOL:
throw LockProtocolException(std::string("Database lock protocol error"), addErrMsg);
case SQLITE_EMPTY:
case SQLITE_EMPTY:
throw InternalDBErrorException(std::string("(Internal Only) Database table is empty"), addErrMsg);
case SQLITE_SCHEMA:
case SQLITE_SCHEMA:
throw SchemaDiffersException(std::string("The database schema changed"), addErrMsg);
case SQLITE_TOOBIG:
case SQLITE_TOOBIG:
throw RowTooBigException(std::string("Too much data for one row of a table"), addErrMsg);
case SQLITE_CONSTRAINT:
case SQLITE_CONSTRAINT:
throw ConstraintViolationException(std::string("Abort due to constraint violation"), addErrMsg);
case SQLITE_MISMATCH:
case SQLITE_MISMATCH:
throw DataTypeMismatchException(std::string("Data type mismatch"), addErrMsg);
case SQLITE_MISUSE:
case SQLITE_MISUSE:
throw InvalidLibraryUseException(std::string("Library used incorrectly"), addErrMsg);
case SQLITE_NOLFS:
case SQLITE_NOLFS:
throw OSFeaturesMissingException(std::string("Uses OS features not supported on host"), addErrMsg);
case SQLITE_AUTH:
case SQLITE_AUTH:
throw AuthorizationDeniedException(std::string("Authorization denied"), addErrMsg);
case SQLITE_FORMAT:
case SQLITE_FORMAT:
throw CorruptImageException(std::string("Auxiliary database format error"), addErrMsg);
case SQLITE_NOTADB:
case SQLITE_NOTADB:
throw CorruptImageException(std::string("File opened that is not a database file"), addErrMsg);
case SQLITE_RANGE:
case SQLITE_RANGE:
throw InvalidSQLStatementException(std::string("Bind Parameter out of range (Access of invalid position 0? bind starts with 1!)"), addErrMsg);
case SQLITE_ROW:
break; // sqlite_step() has another row ready
case SQLITE_DONE:
break; // sqlite_step() has finished executing
default:
throw SQLiteException(std::string("Unkown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
}
}
} } } // namespace Poco::Data::SQLite
case SQLITE_ROW:
break; // sqlite_step() has another row ready
case SQLITE_DONE:
break; // sqlite_step() has finished executing
default:
throw SQLiteException(std::string("Unkown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
}
}
bool Utility::fileToMemory(sqlite3* pInMemory, const std::string& fileName)
{
int rc;
sqlite3* pFile;
sqlite3_backup* pBackup;
rc = sqlite3_open(fileName.c_str(), &pFile);
if(rc == SQLITE_OK )
{
pBackup = sqlite3_backup_init(pInMemory, "main", pFile, "main");
if( pBackup )
{
sqlite3_backup_step(pBackup, -1);
sqlite3_backup_finish(pBackup);
}
rc = sqlite3_errcode(pFile);
}
sqlite3_close(pFile);
return SQLITE_OK == rc;
}
bool Utility::memoryToFile(const std::string& fileName, sqlite3* pInMemory)
{
int rc;
sqlite3* pFile;
sqlite3_backup* pBackup;
rc = sqlite3_open(fileName.c_str(), &pFile);
if(rc == SQLITE_OK )
{
pBackup = sqlite3_backup_init(pFile, "main", pInMemory, "main");
if( pBackup )
{
sqlite3_backup_step(pBackup, -1);
sqlite3_backup_finish(pBackup);
}
rc = sqlite3_errcode(pFile);
}
sqlite3_close(pFile);
return SQLITE_OK == rc;
}
} } } // namespace Poco::Data::SQLite

View File

@ -41,6 +41,7 @@
#include "Poco/Data/SQLChannel.h"
#include "Poco/Data/SessionFactory.h"
#include "Poco/Data/SQLite/Connector.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/SQLite/SQLiteException.h"
#include "Poco/Data/TypeHandler.h"
#include "Poco/Data/DataException.h"
@ -334,6 +335,63 @@ void SQLiteTest::testSimpleAccess()
}
void SQLiteTest::testInMemory()
{
Session tmp (Poco::Data::SQLite::Connector::KEY, "dummy.db");
assert (tmp.isConnected());
std::string tableName("Person");
std::string lastName("lastname");
std::string firstName("firstname");
std::string address("Address");
int age = 133132;
int count = 0;
std::string result;
tmp << "DROP TABLE IF EXISTS Person", now;
tmp << "CREATE TABLE IF NOT EXISTS Person (LastName VARCHAR(30), FirstName VARCHAR, Address VARCHAR, Age INTEGER(3))", now;
tmp << "SELECT name FROM sqlite_master WHERE tbl_name=?", use(tableName), into(result), now;
assert (result == tableName);
tmp << "INSERT INTO PERSON VALUES(:ln, :fn, :ad, :age)", use(lastName), use(firstName), use(address), use(age), now;
// load db from file to memory
Session mem (Poco::Data::SQLite::Connector::KEY, ":memory:");
sqlite3* pMemHandle = AnyCast<sqlite3*>(mem.getProperty("handle"));
assert (Poco::Data::SQLite::Utility::fileToMemory(pMemHandle, "dummy.db"));
mem << "SELECT COUNT(*) FROM PERSON", into(count), now;
assert (count == 1);
mem << "SELECT LastName FROM PERSON", into(result), now;
assert (lastName == result);
mem << "SELECT Age FROM PERSON", into(count), now;
assert (count == age);
mem << "UPDATE PERSON SET Age = -1", now;
mem << "SELECT Age FROM PERSON", into(age), now;
assert (-1 == age);
// save db from memory to file on the disk
Session dsk (Poco::Data::SQLite::Connector::KEY, "dsk.db");
assert (Poco::Data::SQLite::Utility::memoryToFile("dsk.db", pMemHandle));
dsk << "SELECT COUNT(*) FROM PERSON", into(count), now;
assert (count == 1);
dsk << "SELECT LastName FROM PERSON", into(result), now;
assert (lastName == result);
dsk << "SELECT Age FROM PERSON", into(count), now;
assert (count == age);
dsk << "UPDATE PERSON SET Age = -1", now;
dsk << "SELECT Age FROM PERSON", into(age), now;
assert (-1 == age);
tmp.close();
mem.close();
dsk.close();
assert (!tmp.isConnected());
assert (!mem.isConnected());
assert (!dsk.isConnected());
}
void SQLiteTest::testNullCharPointer()
{
Session tmp (Poco::Data::SQLite::Connector::KEY, "dummy.db");
@ -2445,6 +2503,7 @@ CppUnit::Test* SQLiteTest::suite()
CppUnit_addTest(pSuite, SQLiteTest, testBinding);
CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);
CppUnit_addTest(pSuite, SQLiteTest, testInMemory);
CppUnit_addTest(pSuite, SQLiteTest, testNullCharPointer);
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer);
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer2);

View File

@ -48,6 +48,7 @@ public:
void testBinding();
void testSimpleAccess();
void testInMemory();
void testNullCharPointer();
void testInsertCharPointer();
void testInsertCharPointer2();

View File

@ -112,6 +112,10 @@ public:
&AbstractSessionImpl<C>::setStorage,
&AbstractSessionImpl<C>::getStorage);
addProperty("handle",
&AbstractSessionImpl<C>::setHandle,
&AbstractSessionImpl<C>::getHandle);
addFeature("bulk",
&AbstractSessionImpl<C>::setBulk,
&AbstractSessionImpl<C>::getBulk);
@ -208,6 +212,18 @@ public:
return _storage;
}
void setHandle(const std::string& name, const Poco::Any& handle)
/// Sets the native session handle.
{
_handle = handle;
}
Poco::Any getHandle(const std::string& name="")
/// Returns the native session handle.
{
return _handle;
}
void setBulk(const std::string& name, bool bulk)
/// Sets the execution type.
{
@ -308,6 +324,7 @@ private:
bool _bulk;
bool _emptyStringIsNull;
bool _forceEmptyString;
Poco::Any _handle;
};

View File

@ -589,7 +589,7 @@
<ClInclude Include="src\Binder.h" />
<ClInclude Include="src\Connector.h" />
<ClInclude Include="src\Extractor.h" />
<ClInclude Include="src\Preparation.h" />
<ClInclude Include="src\Preparator.h" />
<ClInclude Include="src\SessionImpl.h" />
<ClInclude Include="src\TestStatementImpl.h" />
<ClInclude Include="src\SessionPoolTest.h" />
@ -597,11 +597,11 @@
<ItemGroup>
<ClCompile Include="src\DataTest.cpp" />
<ClCompile Include="src\DataTestSuite.cpp" />
<ClCompile Include="src\Preparator.cpp" />
<ClCompile Include="src\WinDriver.cpp" />
<ClCompile Include="src\Binder.cpp" />
<ClCompile Include="src\Connector.cpp" />
<ClCompile Include="src\Extractor.cpp" />
<ClCompile Include="src\Preparation.cpp" />
<ClCompile Include="src\SessionImpl.cpp" />
<ClCompile Include="src\TestStatementImpl.cpp" />
<ClCompile Include="src\SessionPoolTest.cpp" />

View File

@ -1,108 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="DataCore">
<UniqueIdentifier>{4f84151b-17b6-4ebe-8412-c2b0d8a0c203}</UniqueIdentifier>
</Filter>
<Filter Include="DataCore\Header Files">
<UniqueIdentifier>{17708ec6-e276-4c5e-bfa8-20ad75850a85}</UniqueIdentifier>
</Filter>
<Filter Include="DataCore\Source Files">
<UniqueIdentifier>{d03bf32f-575d-495b-822e-16269ce5b16c}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite">
<UniqueIdentifier>{96f1507f-c487-46fd-9928-d1fceb5d3f72}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Header Files">
<UniqueIdentifier>{61370fc0-a938-465e-9a27-60c810bdc547}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Source Files">
<UniqueIdentifier>{4e80f02a-e1c4-4642-8973-854d79f7b3f7}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver">
<UniqueIdentifier>{5377880e-bd73-4db7-8af5-07f0d7361f77}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver\Source Files">
<UniqueIdentifier>{76dc1562-ba6e-4305-87ce-cd39f9ba9f2c}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession">
<UniqueIdentifier>{a6c4c62e-a498-4cbb-9767-28ef39f81028}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession\Header Files">
<UniqueIdentifier>{5c91cb00-a673-4a71-89f0-aa8cad011290}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession\Source Files">
<UniqueIdentifier>{980271eb-4a47-4f5b-a5ab-cd355579f110}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling">
<UniqueIdentifier>{b5d8a45a-2ad6-4273-8825-e03f26351539}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling\Header Files">
<UniqueIdentifier>{80ac3923-253e-4702-8b6a-9a7df6436749}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling\Source Files">
<UniqueIdentifier>{56884cc5-b348-4841-841a-5410d0e99f49}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\DataTest.h">
<Filter>DataCore\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DataTestSuite.h">
<Filter>_Suite\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Binder.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Connector.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Extractor.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Preparation.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SessionImpl.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\TestStatementImpl.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SessionPoolTest.h">
<Filter>SessionPooling\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\DataTest.cpp">
<Filter>DataCore\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DataTestSuite.cpp">
<Filter>_Suite\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\WinDriver.cpp">
<Filter>_Driver\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Binder.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Connector.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Extractor.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Preparation.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SessionImpl.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\TestStatementImpl.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SessionPoolTest.cpp">
<Filter>SessionPooling\Source Files</Filter>
</ClCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="DataCore">
<UniqueIdentifier>{4f84151b-17b6-4ebe-8412-c2b0d8a0c203}</UniqueIdentifier>
</Filter>
<Filter Include="DataCore\Header Files">
<UniqueIdentifier>{17708ec6-e276-4c5e-bfa8-20ad75850a85}</UniqueIdentifier>
</Filter>
<Filter Include="DataCore\Source Files">
<UniqueIdentifier>{d03bf32f-575d-495b-822e-16269ce5b16c}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite">
<UniqueIdentifier>{96f1507f-c487-46fd-9928-d1fceb5d3f72}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Header Files">
<UniqueIdentifier>{61370fc0-a938-465e-9a27-60c810bdc547}</UniqueIdentifier>
</Filter>
<Filter Include="_Suite\Source Files">
<UniqueIdentifier>{4e80f02a-e1c4-4642-8973-854d79f7b3f7}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver">
<UniqueIdentifier>{5377880e-bd73-4db7-8af5-07f0d7361f77}</UniqueIdentifier>
</Filter>
<Filter Include="_Driver\Source Files">
<UniqueIdentifier>{76dc1562-ba6e-4305-87ce-cd39f9ba9f2c}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession">
<UniqueIdentifier>{a6c4c62e-a498-4cbb-9767-28ef39f81028}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession\Header Files">
<UniqueIdentifier>{5c91cb00-a673-4a71-89f0-aa8cad011290}</UniqueIdentifier>
</Filter>
<Filter Include="TestSession\Source Files">
<UniqueIdentifier>{980271eb-4a47-4f5b-a5ab-cd355579f110}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling">
<UniqueIdentifier>{b5d8a45a-2ad6-4273-8825-e03f26351539}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling\Header Files">
<UniqueIdentifier>{80ac3923-253e-4702-8b6a-9a7df6436749}</UniqueIdentifier>
</Filter>
<Filter Include="SessionPooling\Source Files">
<UniqueIdentifier>{56884cc5-b348-4841-841a-5410d0e99f49}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\DataTest.h">
<Filter>DataCore\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DataTestSuite.h">
<Filter>_Suite\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Binder.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Connector.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Extractor.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SessionImpl.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\TestStatementImpl.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SessionPoolTest.h">
<Filter>SessionPooling\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Preparator.h">
<Filter>TestSession\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\DataTest.cpp">
<Filter>DataCore\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DataTestSuite.cpp">
<Filter>_Suite\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\WinDriver.cpp">
<Filter>_Driver\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Binder.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Connector.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Extractor.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SessionImpl.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\TestStatementImpl.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\SessionPoolTest.cpp">
<Filter>SessionPooling\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Preparator.cpp">
<Filter>TestSession\Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>