Am 26.06.2012 16:49, schrieb Richard Hipp:
On Tue, Jun 26, 2012 at 10:46 AM, deltagam...@gmx.net
<deltagam...@gmx.net>wrote:
I have a c++ GUI application from where the db is read and the content is
displayed in a Clistbox.
Then I try to delete some rows from the sqlite3-db from the console.
After rereading from within the GUI the deleted rows are still there.
How is this possible ?
The GUI is holding a read transaction open. Hence it sees a consistent
snapshot of the database from the moment in time when the transaction was
started. Subsequent writes to the database are ignored by the GUI until it
closes its current transaction and starts a new one.
How can I close the transaction , and later open a new one ?
BTW, transaction is still open although i use a sqlite3_close(db) ?
Here is the code for reading from the db. By changing within the GUI
from tab viewevents to another tab and back again to tab viewevents, the
db is read again and should display all changes to the db which appeared
during that time.
======================================================================
int ReadViewEventsFormDBData()
{
int nRetCode = ERROR_SUCCESS;
// Remove all events from array
m_arrEvents.RemoveAll();
// write events
Event newEvent;
int rc, id, total_events;
char *sql, *sqltotal;
char *evdate, *evtype;
int evctr;
int the_event_ctr = 0;
CString datetime;
CString datepart;
CString timepart;
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_open("ah.db", &db);
// check if table eventlog exists
char create_sql[] = "CREATE TABLE if not exists eventlog ("
"id INTEGER PRIMARY KEY,"
"eventdate DATETIME default current_timestamp,"
"eventtype TEXT,"
"counter INTEGER"
")";
rc = sqlite3_exec(db, create_sql, NULL, NULL, NULL);
// select count(*) from eventlog
sqltotal = "Select count(*) from eventlog";
rc = sqlite3_prepare(db, sqltotal, strlen(sqltotal), &stmt, NULL);
rc = sqlite3_step(stmt);
total_events = sqlite3_column_int(stmt, 0 );
// select * from eventlog
sql = "Select id, eventdate, eventtype, counter FROM eventlog";
sqlite3_prepare(db, sql, strlen(sql), &stmt, NULL);
rc = sqlite3_step(stmt);
while(rc == SQLITE_ROW) {
id = sqlite3_column_int(stmt, 0 );
//cid = sqlite3_column_int(stmt, 1 );
evdate = (char*)sqlite3_column_text(stmt, 1 );
evtype = (char*)sqlite3_column_text(stmt, 2 );
evctr = sqlite3_column_int(stmt, 3 );
datetime = evdate;
datepart = datetime.Mid(0,10);
timepart = datetime.Mid(11,5);
std::cout << datepart << "\t" << timepart << std::endl;
newEvent.m_nEvent = the_event_ctr;
newEvent.m_strLastEventDate = datepart ;
newEvent.m_strEventTime = timepart;
newEvent.m_strEventType = evtype;
newEvent.m_nCount = evctr;
// add the new element to array
m_arrEvents.Add(newEvent);
rc = sqlite3_step(stmt);
// increment eventcounter
the_event_ctr++;
} // while
sqlite3_finalize(stmt);
sqlite3_close(db);
nRetCode = rc;
return nRetCode;
} // ReadViewEventsFormDBData
=========================================================================
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users