SQLite途径iOS

时间:2012-10-25 13:26:06

标签: ios sqlite select

我正在尝试使用以下代码访问我的SQLite中的表:

fileMgr = [NSFileManager defaultManager];
    NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"movieData.sqlite"];

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){

        const char *sql = "SELECT movieName FROM myMovies";
        sqlite3_stmt *sqlStatement;
        if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
        {
            NSLog(@"Problem with prepare statement");
        }

我的输出是“准备声明问题”。我很确定我的表名和* sql中的其他东西。但仍然行不通。任何想法的人?!

1 个答案:

答案 0 :(得分:0)

添加了

BOOL success = [fileMgr fileExistsAtPath:dbPath];
    if(!success)
    {
        NSLog(@"Cannot locate database file '%@'.", dbPath);
    }
    if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
    {
        NSLog(@"An error has occured.");
    } 

cont char *sql之前,它现在正在运作:)