mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-10 08:32:30 +02:00
- 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:
@@ -553,7 +553,6 @@
|
|||||||
<ClInclude Include="include\Poco\Data\Nullable.h" />
|
<ClInclude Include="include\Poco\Data\Nullable.h" />
|
||||||
<ClInclude Include="include\Poco\Data\Position.h" />
|
<ClInclude Include="include\Poco\Data\Position.h" />
|
||||||
<ClInclude Include="include\Poco\Data\Preparation.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\Range.h" />
|
||||||
<ClInclude Include="include\Poco\Data\RecordSet.h" />
|
<ClInclude Include="include\Poco\Data\RecordSet.h" />
|
||||||
<ClInclude Include="include\Poco\Data\Row.h" />
|
<ClInclude Include="include\Poco\Data\Row.h" />
|
||||||
|
@@ -66,9 +66,6 @@
|
|||||||
<ClInclude Include="include\Poco\Data\MetaColumn.h">
|
<ClInclude Include="include\Poco\Data\MetaColumn.h">
|
||||||
<Filter>DataCore\Header Files</Filter>
|
<Filter>DataCore\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="include\Poco\Data\Prepare.h">
|
|
||||||
<Filter>DataCore\Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\Poco\Data\Range.h">
|
<ClInclude Include="include\Poco\Data\Range.h">
|
||||||
<Filter>DataCore\Header Files</Filter>
|
<Filter>DataCore\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@@ -64,6 +64,7 @@ SessionImpl::SessionImpl(const std::string& connect,
|
|||||||
{
|
{
|
||||||
setFeature("bulk", true);
|
setFeature("bulk", true);
|
||||||
open();
|
open();
|
||||||
|
setProperty("handle", _db.handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ SessionImpl::SessionImpl(const std::string& connect,
|
|||||||
{
|
{
|
||||||
setFeature("bulk", true);
|
setFeature("bulk", true);
|
||||||
open();
|
open();
|
||||||
|
setProperty("handle", _db.handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -591,6 +591,7 @@
|
|||||||
<ClInclude Include="src\ODBCPostgreSQLTest.h" />
|
<ClInclude Include="src\ODBCPostgreSQLTest.h" />
|
||||||
<ClInclude Include="src\ODBCSQLiteTest.h" />
|
<ClInclude Include="src\ODBCSQLiteTest.h" />
|
||||||
<ClInclude Include="src\ODBCSQLServerTest.h" />
|
<ClInclude Include="src\ODBCSQLServerTest.h" />
|
||||||
|
<ClInclude Include="src\ODBCTest.h" />
|
||||||
<ClInclude Include="src\SQLExecutor.h" />
|
<ClInclude Include="src\SQLExecutor.h" />
|
||||||
<ClInclude Include="src\ODBCTestSuite.h" />
|
<ClInclude Include="src\ODBCTestSuite.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -602,6 +603,7 @@
|
|||||||
<ClCompile Include="src\ODBCPostgreSQLTest.cpp" />
|
<ClCompile Include="src\ODBCPostgreSQLTest.cpp" />
|
||||||
<ClCompile Include="src\ODBCSQLiteTest.cpp" />
|
<ClCompile Include="src\ODBCSQLiteTest.cpp" />
|
||||||
<ClCompile Include="src\ODBCSQLServerTest.cpp" />
|
<ClCompile Include="src\ODBCSQLServerTest.cpp" />
|
||||||
|
<ClCompile Include="src\ODBCTest.cpp" />
|
||||||
<ClCompile Include="src\SQLExecutor.cpp" />
|
<ClCompile Include="src\SQLExecutor.cpp" />
|
||||||
<ClCompile Include="src\ODBCTestSuite.cpp" />
|
<ClCompile Include="src\ODBCTestSuite.cpp" />
|
||||||
<ClCompile Include="src\WinDriver.cpp" />
|
<ClCompile Include="src\WinDriver.cpp" />
|
||||||
|
@@ -54,6 +54,9 @@
|
|||||||
<ClInclude Include="src\ODBCTestSuite.h">
|
<ClInclude Include="src\ODBCTestSuite.h">
|
||||||
<Filter>_Suite\Header Files</Filter>
|
<Filter>_Suite\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\ODBCTest.h">
|
||||||
|
<Filter>ODBC\Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\ODBCAccessTest.cpp">
|
<ClCompile Include="src\ODBCAccessTest.cpp">
|
||||||
@@ -86,5 +89,8 @@
|
|||||||
<ClCompile Include="src\WinDriver.cpp">
|
<ClCompile Include="src\WinDriver.cpp">
|
||||||
<Filter>_Driver\Source Files</Filter>
|
<Filter>_Driver\Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\ODBCTest.cpp">
|
||||||
|
<Filter>ODBC\Header Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@@ -80,6 +80,18 @@ public:
|
|||||||
static MetaColumn::ColumnDataType getColumnType(sqlite3_stmt* pStmt, std::size_t pos);
|
static MetaColumn::ColumnDataType getColumnType(sqlite3_stmt* pStmt, std::size_t pos);
|
||||||
/// Returns column data type.
|
/// 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:
|
private:
|
||||||
static TypeMap _types;
|
static TypeMap _types;
|
||||||
Poco::FastMutex _mutex;
|
Poco::FastMutex _mutex;
|
||||||
|
@@ -67,6 +67,7 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
|
|||||||
{
|
{
|
||||||
open();
|
open();
|
||||||
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
|
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
|
||||||
|
setProperty("handle", _pDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -209,4 +209,50 @@ void Utility::throwException(int rc, const std::string& 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
|
} } } // namespace Poco::Data::SQLite
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "Poco/Data/SQLChannel.h"
|
#include "Poco/Data/SQLChannel.h"
|
||||||
#include "Poco/Data/SessionFactory.h"
|
#include "Poco/Data/SessionFactory.h"
|
||||||
#include "Poco/Data/SQLite/Connector.h"
|
#include "Poco/Data/SQLite/Connector.h"
|
||||||
|
#include "Poco/Data/SQLite/Utility.h"
|
||||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||||
#include "Poco/Data/TypeHandler.h"
|
#include "Poco/Data/TypeHandler.h"
|
||||||
#include "Poco/Data/DataException.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()
|
void SQLiteTest::testNullCharPointer()
|
||||||
{
|
{
|
||||||
Session tmp (Poco::Data::SQLite::Connector::KEY, "dummy.db");
|
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, testBinding);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);
|
CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);
|
||||||
|
CppUnit_addTest(pSuite, SQLiteTest, testInMemory);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testNullCharPointer);
|
CppUnit_addTest(pSuite, SQLiteTest, testNullCharPointer);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer);
|
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer);
|
||||||
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer2);
|
CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer2);
|
||||||
|
@@ -48,6 +48,7 @@ public:
|
|||||||
|
|
||||||
void testBinding();
|
void testBinding();
|
||||||
void testSimpleAccess();
|
void testSimpleAccess();
|
||||||
|
void testInMemory();
|
||||||
void testNullCharPointer();
|
void testNullCharPointer();
|
||||||
void testInsertCharPointer();
|
void testInsertCharPointer();
|
||||||
void testInsertCharPointer2();
|
void testInsertCharPointer2();
|
||||||
|
@@ -112,6 +112,10 @@ public:
|
|||||||
&AbstractSessionImpl<C>::setStorage,
|
&AbstractSessionImpl<C>::setStorage,
|
||||||
&AbstractSessionImpl<C>::getStorage);
|
&AbstractSessionImpl<C>::getStorage);
|
||||||
|
|
||||||
|
addProperty("handle",
|
||||||
|
&AbstractSessionImpl<C>::setHandle,
|
||||||
|
&AbstractSessionImpl<C>::getHandle);
|
||||||
|
|
||||||
addFeature("bulk",
|
addFeature("bulk",
|
||||||
&AbstractSessionImpl<C>::setBulk,
|
&AbstractSessionImpl<C>::setBulk,
|
||||||
&AbstractSessionImpl<C>::getBulk);
|
&AbstractSessionImpl<C>::getBulk);
|
||||||
@@ -208,6 +212,18 @@ public:
|
|||||||
return _storage;
|
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)
|
void setBulk(const std::string& name, bool bulk)
|
||||||
/// Sets the execution type.
|
/// Sets the execution type.
|
||||||
{
|
{
|
||||||
@@ -308,6 +324,7 @@ private:
|
|||||||
bool _bulk;
|
bool _bulk;
|
||||||
bool _emptyStringIsNull;
|
bool _emptyStringIsNull;
|
||||||
bool _forceEmptyString;
|
bool _forceEmptyString;
|
||||||
|
Poco::Any _handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -589,7 +589,7 @@
|
|||||||
<ClInclude Include="src\Binder.h" />
|
<ClInclude Include="src\Binder.h" />
|
||||||
<ClInclude Include="src\Connector.h" />
|
<ClInclude Include="src\Connector.h" />
|
||||||
<ClInclude Include="src\Extractor.h" />
|
<ClInclude Include="src\Extractor.h" />
|
||||||
<ClInclude Include="src\Preparation.h" />
|
<ClInclude Include="src\Preparator.h" />
|
||||||
<ClInclude Include="src\SessionImpl.h" />
|
<ClInclude Include="src\SessionImpl.h" />
|
||||||
<ClInclude Include="src\TestStatementImpl.h" />
|
<ClInclude Include="src\TestStatementImpl.h" />
|
||||||
<ClInclude Include="src\SessionPoolTest.h" />
|
<ClInclude Include="src\SessionPoolTest.h" />
|
||||||
@@ -597,11 +597,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\DataTest.cpp" />
|
<ClCompile Include="src\DataTest.cpp" />
|
||||||
<ClCompile Include="src\DataTestSuite.cpp" />
|
<ClCompile Include="src\DataTestSuite.cpp" />
|
||||||
|
<ClCompile Include="src\Preparator.cpp" />
|
||||||
<ClCompile Include="src\WinDriver.cpp" />
|
<ClCompile Include="src\WinDriver.cpp" />
|
||||||
<ClCompile Include="src\Binder.cpp" />
|
<ClCompile Include="src\Binder.cpp" />
|
||||||
<ClCompile Include="src\Connector.cpp" />
|
<ClCompile Include="src\Connector.cpp" />
|
||||||
<ClCompile Include="src\Extractor.cpp" />
|
<ClCompile Include="src\Extractor.cpp" />
|
||||||
<ClCompile Include="src\Preparation.cpp" />
|
|
||||||
<ClCompile Include="src\SessionImpl.cpp" />
|
<ClCompile Include="src\SessionImpl.cpp" />
|
||||||
<ClCompile Include="src\TestStatementImpl.cpp" />
|
<ClCompile Include="src\TestStatementImpl.cpp" />
|
||||||
<ClCompile Include="src\SessionPoolTest.cpp" />
|
<ClCompile Include="src\SessionPoolTest.cpp" />
|
||||||
|
@@ -60,9 +60,6 @@
|
|||||||
<ClInclude Include="src\Extractor.h">
|
<ClInclude Include="src\Extractor.h">
|
||||||
<Filter>TestSession\Header Files</Filter>
|
<Filter>TestSession\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\Preparation.h">
|
|
||||||
<Filter>TestSession\Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\SessionImpl.h">
|
<ClInclude Include="src\SessionImpl.h">
|
||||||
<Filter>TestSession\Header Files</Filter>
|
<Filter>TestSession\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -72,6 +69,9 @@
|
|||||||
<ClInclude Include="src\SessionPoolTest.h">
|
<ClInclude Include="src\SessionPoolTest.h">
|
||||||
<Filter>SessionPooling\Header Files</Filter>
|
<Filter>SessionPooling\Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Preparator.h">
|
||||||
|
<Filter>TestSession\Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\DataTest.cpp">
|
<ClCompile Include="src\DataTest.cpp">
|
||||||
@@ -92,9 +92,6 @@
|
|||||||
<ClCompile Include="src\Extractor.cpp">
|
<ClCompile Include="src\Extractor.cpp">
|
||||||
<Filter>TestSession\Source Files</Filter>
|
<Filter>TestSession\Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\Preparation.cpp">
|
|
||||||
<Filter>TestSession\Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\SessionImpl.cpp">
|
<ClCompile Include="src\SessionImpl.cpp">
|
||||||
<Filter>TestSession\Source Files</Filter>
|
<Filter>TestSession\Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -104,5 +101,8 @@
|
|||||||
<ClCompile Include="src\SessionPoolTest.cpp">
|
<ClCompile Include="src\SessionPoolTest.cpp">
|
||||||
<Filter>SessionPooling\Source Files</Filter>
|
<Filter>SessionPooling\Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Preparator.cpp">
|
||||||
|
<Filter>TestSession\Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user