after adding in the obviously missing #include's for <sqlite3.h> and <string> the provided code does not compile. It is looking for an undefined something called EXPECT_EQ ...
Kind of hard to reproduce if incomplete code is presented. As an aside, it works properly written in python using apsw. It does not work when using Pythons sqlite3 wrapper (but then, since that wrapper "buggers about" with no way to tell what it is doing, I find that unsurprising). >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). You are correct. Committed transactions on connection A should be visible to connection B provided that the transaction committed on A before the transaction commenced on connection B. --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-----Original Message----- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Albert Banaszkiewicz >Sent: Tuesday, 20 November, 2018 08:35 >To: sqlite-users@mailinglists.sqlite.org >Subject: [sqlite] Creating and dropping tables with multiple >connections > >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 >sqlite-users@mailinglists.sqlite.org >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users