How to get error code if sqlite3_prepare_v2 () returns one?

Basically, after the tutorial on SQLite Ray Wenderlich , I am writing a fairly simple application that displays information dumped from the server. The basic structure of my SQLite queries (to the local database, not to the server) is as follows:

{ NSMutableArray *list = [[NSMutableArray alloc] init]; NSString *query = @"SELECT _id, type FROM table ORDER BY type"; // As appropriate. sqlite3_stmt *statement; if (sqlite3_prepare_v2(_db, [query UTF8String], -1, &statement, nil) == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { // Process the returned values... int rowNumber = sqlite3_column_int(statement, 0); // Initialize the object. // Push the object onto the array. } sqlite3_finalize(statement); } else { // Log the error. } return list; } 

My question is: what is the best way to check for an error if the if returns false? The simplest solution for me seems to keep the return value of sqlite3_prepare_v2() as int and check that against SQLITE_OK . What about calling sqlite_errmsg() ?

I looked through sqlite_exec() , but I was out of luck with overlays, and I don’t feel confident enough in my understanding of C callbacks to properly support code that uses them. He passes the argument for the error, although this made me look into it first.

+7
source share
1 answer

If you want to receive an error message, you really should call sqlite3_errmsg .

sqlite3_exec will give you the same row.

+3
source

All Articles