sqlite를 사용하여 데이터베이스를 쿼리하는 중 이상한 오류가 발생했습니다. SQLlite error: near "SE": syntax error
왜 나는 그가 보내는 쿼리 문자열이 마음에 들지 않는지 알 수 없습니다. 내 코드는 다음과 같습니다.sqlite 오류 쿼리 구문
-(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;
}
아무것도 너무 상상할 수 없습니다. 뭐가 잘못 되었나요? 감사합니다.
Objective-C에 들어가기 전에 C를 올바르게 배워주세요.'[[NSString stringWithFormat : @ "mywallet.sqlite3"]'는 "mywalled.sqlite3"''로 줄일 수 있습니다 ... 또한 쿼리 문자열입니다. 또한 NSLog()가 printf 스타일 형식을 허용하는 이유가 있습니다. NSLog ([NSString stringWithFormat : whatever]')'는 중복적이고 안전하지 않습니다. –
SQLite는 [ANSI SQL 따옴표] (http://www.sqlite.org/faq.html#q24)를 사용합니다. ''거래 ''는 잘못된 식별자입니다. ''트랜잭션 ''을 시도하십시오. –
@ H2CO3 당신은 이런 종류의 웹 사이트가 매우 유용한 이유입니다! <3 – Eux