开发者

sqlite3_prepare_v2 no such table error

开发者 https://www.devze.com 2023-04-07 12:31 出处:网络
I have a sqlite problem. My code above: -(NSString *) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

I have a sqlite problem.

My code above:

-(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 yo开发者_StackOverflowk_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));

   }

}

I have error at sqlite3_prepare_v2 command

error message: Error (sqlite3_prepare): no such table: yok_artik

How can I fix this problem?

BTW, sqlite3_open working fine.


My error is filePath. I change it.

0

精彩评论

暂无评论...
验证码 换一张
取 消