I’m receiving a strange error querying a database with sqlite:
SQLlite error: near "SE": syntax error
I don’t really get why he doesn’t like the query string I’m sending to it. Here’s my code:
-(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;
}
Nothing too fancy.. what’s wrong with it?
Thanks!
The third parameter of sqlite3_prepare_v2 must be the length of the query string, or just
-1.With SQLite complaining about “
SE“, I’d guess that the value ofSQLITE_OPEN_READWRITEis2.:-)