sqlite_prepare_v2无效,不返回sqlite_ok

时间:2013-12-12 07:44:02

标签: ios sqlite

NSArray *documentpath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* path = [documentpath objectAtIndex:0];

NSString *dbpath = [path stringByAppendingString:@"check1.sqlite"];

if (sqlite3_open([dbpath UTF8String], &db) == SQLITE_OK) {
    NSLog(@"get database");

    const char *sql = "select name from login where ID = 1";

    sqlite3_stmt *statement;


    int sqlresult = sqlite3_prepare_v2(db, sql, -1, &statement, NULL);

    if ( sqlresult == SQLITE_OK) {

        while (sqlite3_step(statement) == SQLITE_ROW) {
            NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1) ];
            NSLog(@"%@",name);
        }
    }

 }

0 个答案:

没有答案