1

我在使用 sqlite 查询数据库时收到一个奇怪的错误: SQLlite error: near "SE": syntax error 我真的不明白为什么他不喜欢我发送给它的查询字符串。这是我的代码:

-(Wallet*)loadDataFromSQL{
    sqlite3 *database;
    NSLog(@"opening..");
    if (sqlite3_open([[NSString stringWithFormat:@"mywallet.sqlite3"] UTF8String], &database) == SQLITE_OK) {
        NSLog(@"opened..");
        const char *query = [[NSString stringWithFormat:@"SELECT * FROM 'Transaction';"] UTF8String]; // "insert into \"Transaction\" values (\"2013-01-01\",\"tipo\",\"cat\",1)";
        sqlite3_stmt *selectstmt;
        NSLog(@"preparing stmnt..");
        if(sqlite3_prepare_v2(database, query, SQLITE_OPEN_READWRITE, &selectstmt, nil) == SQLITE_OK) {
            NSLog(@"Prepared..");
            while(sqlite3_step(selectstmt) == SQLITE_ROW) {
                NSLog(@"row..");
                NSString *data = [NSString stringWithUTF8String: (char*)sqlite3_column_text(selectstmt, 0)];
                NSString *type = [NSString stringWithUTF8String: (char*)sqlite3_column_text(selectstmt, 1)];
                NSString *category = [NSString stringWithUTF8String: (char*)sqlite3_column_text(selectstmt, 2)];
                float amount = (float)sqlite3_column_double(selectstmt, 0);

                Transaction *t = [[Transaction alloc]init:data transactionType:type transactionCategory:category transactionAmount:[NSString stringWithFormat:@"%f",amount]];
                NSLog(@"%@",t);
            }
        }else{
            NSLog([NSString stringWithFormat:@"SQLlite error: %s\n", sqlite3_errmsg(database)]);
        }
    }
    sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
    return nil;
}

没什么太花哨的..有什么问题?谢谢!

4

1 回答 1

1

sqlite3_prepare_v2的第三个参数必须是查询字符串的长度,或者只是-1.

sqlite3_prepare_v2(database, query, SQLITE_OPEN_READWRITE, &selectstmt, nil)

由于 SQLite 抱怨“ SE”,我猜想 的值SQLITE_OPEN_READWRITE2:-)

于 2012-11-28T07:51:34.253 回答