sqlite3_prepare_v2没有这样的表错误

时间:2011-09-24 16:03:57

标签: ios xcode sqlite

我有一个sqlite问题。

我上面的代码:

-(NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *dbPath = [documentsDir stringByAppendingPathComponent:@"Yok_Artik.sqlite"];
    return dbPath;
}

-(void) openDB {

    if (sqlite3_open([[self filePath] UTF8String], &db) == SQLITE_OK) {

        const char *sqlStatement = "SELECT content, image FROM yok_artik ORDER BY RANDOM() LIMIT 1;";

        sqlite3_stmt *compiledStatement;

        if (sqlite3_prepare_v2(db, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

            if (sqlite3_step(compiledStatement) == SQLITE_ROW) {

                NSString *myContent = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];

                yaContent.text = myContent;

            } else {

                NSLog(@"Error (sqlite3_step): %s", sqlite3_errmsg(db));

            }

        } else {

            NSLog(@"Error (sqlite3_prepare): %s", sqlite3_errmsg(db));

        }

    } else {

        NSLog(@"Error (sqlite3_open): %s", sqlite3_errmsg(db));

   }

}

我在sqlite3_prepare_v2命令

时遇到错误

错误讯息: 错误(sqlite3_prepare):没有这样的表:yok_artik

如何解决此问题?

BTW,sqlite3_open工作正常。

1 个答案:

答案 0 :(得分:-2)

我的错误是filePath。我改变了。