Re: [sqlite] INSERT after creating an INDEX
Frank Fiedler <[EMAIL PROTECTED]> wrote: >assert(sqlite3_step(drop_table_stmt) == SQLITE_DONE); I don't know what is wrong with your program, but I do see that you are misusing assert() - misusing it rather badly. An assert() statement is intended to express an invariant. It is intended to express a fact that is always true about your code. If you compile with -DNDEBUG=1 then assert() becomes a no-op. You should think of an assert() as an executable comment - a comment about your code that is verified to be correct at runtime. Your program should always operate identically if all the assert() statements are removed. There are two problems with your use of assert(). This first is that you are calling sqlite3_step() from within assert(). I don't think you want your sqlite3_step() calls to become no-ops, do you? The second error is that asserts are intended to detect internal inconsistencies within your own code - not external error conditions. So you should never assert() that the return value from sqlite3_step() is going to be SQLITE_DONE unless SQLite promises that it will always return that value. And it makes no such promise. You might also get SQLITE_ERROR, or SQLITE_BUSY. -- D. Richard Hipp <[EMAIL PROTECTED]> - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] INSERT after creating an INDEX
Hi Simon, On 3.4.2 built from amalgamation on XP using Visual Studio I can follow your scenario without problems. I used command line shell and tcl shell. More detail will help (version etc). Ok...let's try the next level of detail: - We are using sqlite 3.4.0 on linux (Redhat Enterprise 3, Update 4) Please find below a summary of actions we do on C++ and TCL side: C++ - Open data base : sqlite3_open("TableName", &m_sqlite); - Issue begin-transaction: std::string begin_transaction_query("BEGIN TRANSACTION;"); sqlite3_prepare(m_sqlite, begin_transaction_query.c_str(), begin_transaction_query.size(), &m_begin_transaction_stmt, NULL); sqlite3_step(m_begin_transaction_stmt); sqlite3_reset(m_begin_transaction_stmt); - Create table: std::string commit_query("COMMIT;"); sqlite3_prepare(m_sqlite, commit_query.c_str(), commit_query.size(), &m_commit_stmt, NULL); if (have_pending_data) { check_step(sqlite3_step(m_commit_stmt),m_sqlite); check_result(sqlite3_reset(m_commit_stmt),m_sqlite); } std::string drop_table_query("DROP TABLE IF EXISTS '" + name + "';"); sqlite3_stmt* drop_table_stmt; sqlite3_prepare(m_sqlite, drop_table_query.c_str(), drop_table_query.size(), &drop_table_stmt, NULL); assert(sqlite3_step(drop_table_stmt) == SQLITE_DONE); sqlite3_finalize(drop_table_stmt); // Drop index std::string drop_index_query("DROP INDEX IF EXISTS '" + name + "_index';"); sqlite3_stmt* drop_index_stmt; sqlite3_prepare(m_sqlite, drop_index_query.c_str(), drop_index_query.size(), &drop_index_stmt, NULL); assert(sqlite3_step(drop_index_stmt) == SQLITE_DONE); sqlite3_finalize(drop_index_stmt); // Create table std::string create_table_query("CREATE TABLE '" + name + "' (" + schema + ")"); sqlite3_stmt* create_table_stmt; sqlite3_prepare(m_sqlite, create_table_query.c_str(), create_table_query.size(), &create_table_stmt, NULL); assert(sqlite3_step(create_table_stmt) == SQLITE_DONE); sqlite3_finalize(create_table_stmt); - Insert data: while (fill_with_data) { sqlite3_stmt* stmt = getInsertQuery(2); sqlite3_bind_int64(stmt, 1, a); sqlite3_bind_text(stmt, 2, b.c_str(), b.size(), SQLITE_TRANSIENT); assert(sqlite3_step(stmt) == SQLITE_DONE); sqlite3_reset(stmt); if (should_synchronize) { assert(sqlite3_step(m_commit_stmt) == SQLITE_DONE); sqlite3_reset(m_commit_stmt); assert(sqlite3_step(m_begin_transaction_stmt) == SQLITE_DONE); sqlite3_reset(m_begin_transaction_stmt); } - Flush data to file: // for flushing the data to a file we do a commit std::string commit_query("COMMIT;"); sqlite3_prepare(m_sqlite, commit_query.c_str(), commit_query.size(), &m_commit_stmt, NULL); check_step(sqlite3_step(m_commit_stmt),m_sqlite); sqlite3_reset(m_commit_stmt); TCL - Create index from within TCL # now we create an index from within a tcl script # Open data base from within tcl sqlite3 my_db "my_data_base.db" # Make index my_db eval { CREATE INDEX IF NOT EXISTS memory_access_pc ON 'memory access monitor'(pc) } # We never explicitely close this db from within tcl When now inserting data from within the C++ world, it exits with the SQLITE_ERROR as mentioned earlier. I hope this level of detailed was not too fine grain. Thanks for your help in advance, Frank. - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] INSERT after creating an INDEX
Hi Frank, On 3.4.2 built from amalgamation on XP using Visual Studio I can follow your scenario without problems. I used command line shell and tcl shell. More detail will help (version etc). Rgds, Simon On 13/09/2007, Frank Fiedler <[EMAIL PROTECTED]> wrote: > Hello everybody, > > I have a problem inserting elements into a data base (from process1 > accessing the data base) after creating an INDEX on a table (from > another process accessing the data base). > > I have the following setup: > - I have two processes accessing a single sqlite data base. process1 > accesses the data base via the C++ interface, process2 accesses it via > the tcl interface of sqlite. > - process1 creates the data base, creates a single table in the data > base and fills this table with life. This is done via INSERT commands. > - process2 displays the data comprised in the data base. process2 can > read the data from the data base without problems but after creating an > INDEX process1 is not able to do an INSERT to the table in the data base > any more. > > The error I get is the following: > "SQLITE_ERROR : SQL logic error or missing database" > > The index I created is an index on a single row of the table in the data > base. > > Has anyone a clue what I'm doing wrong. Any feedback is welcome. > Thanks, > Frank. > > > - > To unsubscribe, send email to [EMAIL PROTECTED] > - > > - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] INSERT after creating an INDEX
Hello everybody, I have a problem inserting elements into a data base (from process1 accessing the data base) after creating an INDEX on a table (from another process accessing the data base). I have the following setup: - I have two processes accessing a single sqlite data base. process1 accesses the data base via the C++ interface, process2 accesses it via the tcl interface of sqlite. - process1 creates the data base, creates a single table in the data base and fills this table with life. This is done via INSERT commands. - process2 displays the data comprised in the data base. process2 can read the data from the data base without problems but after creating an INDEX process1 is not able to do an INSERT to the table in the data base any more. The error I get is the following: "SQLITE_ERROR : SQL logic error or missing database" The index I created is an index on a single row of the table in the data base. Has anyone a clue what I'm doing wrong. Any feedback is welcome. Thanks, Frank. - To unsubscribe, send email to [EMAIL PROTECTED] -