On 19/05/2009 1:42 AM, Christopher Taylor wrote: > I took a slightly different approach and used a trigger. This is the create > table function from my event log class. The string handler is proprietary > but other than that there should be enough there to give you an idea. > > void DbEventLog::CreateTable(sqlite3* pDatabase) > { > // create the table and insert the record > char* db_err; > CmnNarrowString createQuery = "create table tbl_EventLog ("; > createQuery += "m_key integer primary key autoincrement, "; > createQuery += "m_eventCode integer, "; > createQuery += "m_timestamp integer, ";
Are you sure about that comma? C:\junk>sqlite3 SQLite version 3.6.14 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table foo(col0, col1, col2,); SQL error: near ")": syntax error sqlite> > createQuery += ");"; > int rc = sqlite3_exec(pDatabase, createQuery.c_str(), NULL, 0, &db_err); > if ( rc != SQLITE_OK ) > { > // TODO - log error > } > else > { > // create the index on the unique id used for queries from ics > createQuery = "create index idx_EventLog on tbl_EventLog (m_key)"; > rc = sqlite3_exec(pDatabase, createQuery.c_str(), NULL, 0, &db_err); > if ( rc != SQLITE_OK ) > { > // TODO - log error > } > else > { > createQuery = "create trigger trg_EventLog after insert on > tbl_EventLog begin delete from tbl_EventLog where m_key <= (SELECT > max(m_key) FROM tbl_EventLog) - 4000; end;"; > rc = sqlite3_exec(pDatabase, createQuery.c_str(), NULL, 0, > &db_err); > if ( rc != SQLITE_OK ) > { > // TODO - log the error > } > } > } > } > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users