SQLite3错误 – iOS

我怎样才能弄清SQLite3在我进行SQL调用时给我的错误:

int success = sqlite3_prepare_v2(database, sql, -1, &stmt, NULL); if(success != SQLITE_OK) { NSLog(@"create stmt failed %@",stmt); } 

所有我知道的是,如果它失败了,但有没有办法得到实际的错误,或者为什么失败?

当然,如果success != SQLITE_OK ,那么它必须是以下错误代码之一:

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

你可以使用sqlite3_errmsg函数。 你需要传入数据库句柄。 以下代码将logging错误

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