CodeGuy
CodeGuy

Reputation: 28907

SQLite3 error - iOS

How can I figure out the error that SQLite3 is giving me when I make an SQL call:

int success = sqlite3_prepare_v2(database, sql, -1, &stmt, NULL);

if(success != SQLITE_OK) {
  NSLog(@"create stmt failed %@",stmt);
}

All as I know is if it failed, but is there a way to get the actual error, or reason why it failed?

Upvotes: 3

Views: 7263

Answers (2)

Bharat Ahluwalia
Bharat Ahluwalia

Reputation: 446

You can use the sqlite3_errmsg function. You need to pass in the db handle. The following code will log the error

NSLog(@"Error %s while preparing statement", sqlite3_errmsg(_dbHandle));

Upvotes: 17

rid
rid

Reputation: 63442

Sure, if success != SQLITE_OK, then it must be one of these error codes:

http://www.sqlite.org/c3ref/c_abort.html

Upvotes: 3

Related Questions