sqlite3_prepare_v2 失败(Xcode sqlite 3) [英] sqlite3_prepare_v2 failed (Xcode sqlite 3)
本文介绍了sqlite3_prepare_v2 失败(Xcode sqlite 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很想连接 sqlite 但不能.有人可以帮助我吗?我在这里根本没有看到任何错误,我已经在谷歌和这里搜索了这个问题的高低,但我找不到任何方法来解决这个问题.
I'm so trying to connect the sqlite but can't. Can someone help me? I don't see any error here at all and I've searched high and low for this problem on google and here but I can't find any way to fix this.
我正在这里
请帮帮我,我对这个错误快要疯了.=(
Do help me, I'm going crazy over this error. =(
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
sqlite3 *contactDB; //declare pointer to database structurery
const char *dbPath = [databasePath UTF8String]; //convert NSString to UTF8String
//open database file. TRUE = success, FALSE = failed
if (sqlite3_open(dbPath, &contactDB)== SQLITE_OK){
NSLog(@"Opened");
sqlite3_stmt *statement;
NSString *querySQL = @"SELECT address, phone FROM contacts";
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(contactDB, query_stmt, 1, &statement, NULL) == SQLITE_OK) {
NSLog(@"Statement is OK");
}else{
NSLog(@"Statement FAILED");
}
}else{
NSLog(@"Failed");
}
日志只读取打开"然后语句失败"
The log only reads "Opened" then "Statement FAILED"
推荐答案
我就是这样做的.(编译我的数据库类)
也显示了 sql 错误.
This is how I do it. (Compiled piece of my database class)
Shows you the sql error too.
sqlite3 *_database;
sqlite3_open([databasePath UTF8String], &_database);
NSString *sqlStatement = @"SELECT address, phone FROM contacts";
const char *sql = [sqlStatement UTF8String];
static sqlite3_stmt *compiledStatement;
int result = sqlite3_prepare_v2(_database, sql, -1, &compiledStatement, NULL);
if(result != SQLITE_OK) {
NSLog(@"Prepare-error #%i: %s", result, sqlite3_errmsg(_database));
}
result = sqlite3_step(compiledStatement);
if (result != SQLITE_DONE) {
NSLog(@"Step-error #%i for '%@': %s", result, sqlStatement, sqlite3_errmsg(_database));
}
sqlite3_finalize(compiledStatement);
这篇关于sqlite3_prepare_v2 失败(Xcode sqlite 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文