SQLite error handling

Feb 1, 2011 at 4:17pm

SQLite error handling

Is there a way to check errors occurring in the SQLite exec method? According to the docs it has no return value.

Something stupid like forgetting to wrap a string value inside quotes when inserting into a table seems to be completely silent, which makes it difficult to debug. Is there something like a global last_error variable maybe?

#54724
Feb 2, 2011 at 8:40pm

I’ve been wondering about this, too. I have an ongoing project which makes heavy use of SQLite from Javascript, and not being able to get any errors makes working on it so much more difficult.

My strategy now is to try out all queries in the command-line SQLite client first to see if they are correct. In addition, I made all queries traceable (controlled by a Global), so I can manually check them for correctness in the Max window. So all my SQL code looks like this:


var sql = '';
db.exec(sql, result);
if (my_global.debug_sql) { post(sql); post(); }

BTW, talking about SQLite API shortcomings, it would be very nice to have access to the last_insert_rowid from Javascript…

#197096
Feb 4, 2011 at 7:06am

I have no experience using sql lite with max, but maybe it’s useful to check what’s printed in the Console.app. I remember at least seeing some sqlite errors and status update there

#197097

You must be logged in to reply to this topic.