Hi everybody,
I have a question regarding multiple connections to the same DB from the same
process.
I was expecting that modifying a DB via a certain connection should also be
visible for all other opened connections. Is my assumption incorrect ? (both
operations being transactions).
In my test example, I am creating a table via connection no. 1 and drop it via
connection no. 2. Table is created correctly and then correctly dropped in the
first iteration. However, if I try to run this one more time I am receiving
'table already exists' error while trying to create it (connection no. 1) and
then 'no such table' for connection no. 2 while trying to drop it.
Is it intended behavior ?
Moreover, if I open connections with SQLITE_OPEN_SHAREDCACHE flag, everything
works as expected.
The code I use:
static const char* KCreateTable =
"CREATE TABLE MyTable("
" component TEXT not null,"
" key TEXT not null,"
" value INTEGER not null,"
" primary key (component, key)"
");";
static const char* KDropTable =
"DROP TABLE MyTable;";
void ExecuteInTransaction(sqlite3* aDb, const std::string& aQuery)
{
std::string finalQuery = "BEGIN TRANSACTION;" + aQuery + "COMMIT;";
EXPECT_EQ(SQLITE_OK, sqlite3_exec(aDb, finalQuery.c_str(), nullptr, nullptr,
nullptr)) << sqlite3_errmsg(aDb);
}
TEST_F(CEncryptedStreamTest, DroppingTablesTest)
{
sqlite3* writeDb1 = nullptr;
sqlite3* writeDb2 = nullptr;
EXPECT_EQ(SQLITE_OK, sqlite3_open_v2("db.sqlite", &writeDb1,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr));
EXPECT_EQ(SQLITE_OK, sqlite3_open_v2("db.sqlite", &writeDb2,
SQLITE_OPEN_READWRITE, nullptr));
for (int i = 0; i < 2; ++i)
{
ExecuteInTransaction(writeDb1, KCreateTable);
ExecuteInTransaction(writeDb2, KDropTable);
}
sqlite3_close_v2(writeDb1);
sqlite3_close_v2(writeDb2);
}
Cheers,
Albert
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users