0
嗨我有一個函數,基本上試圖插入從REST調用返回的一些數據。Sqlite iPhone數據插入問題
- (void)syncLocalDatabase{
NSString *file = [[NSBundle mainBundle] pathForResource:@"pickuplines" ofType:@"db"];
NSMutableString *query = [[NSMutableString alloc] initWithFormat:@""];
sqlite3 *database = NULL;
char *errorMsg = NULL;
if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
for(PickUpLine *pickupline in pickUpLines){
[query appendFormat:@"INSERT INTO pickuplines VALUES(%d,%d,%d,'%@','YES')", pickupline.line_id, pickupline.thumbsUps, pickupline.thumbsDowns, [pickupline.line stringByReplacingOccurrencesOfString:@"'" withString:@"`"]];
NSLog(query);
int result = sqlite3_exec(database, [query UTF8String], NULL, NULL, &errorMsg);
if (result!=SQLITE_OK) {
printf("\n%s",errorMsg);
sqlite3_free(errorMsg);
}
//sqlite3_step([query UTF8String]);
[query setString:@""];
}//end for
}//end if
[query release];
sqlite3_close(database); }
一切似乎罰款在日誌語句中的查詢字符串也很好,但數據沒有被插入。作爲select語句的這個函數的一個副本,其效果很好。 這裏是計數器部分
- (void)loadLinesFromDatabase{
NSString *file = [[NSBundle mainBundle] pathForResource:@"pickuplines" ofType:@"db"];
sqlite3 *database = NULL;
if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
sqlite3_exec(database, "SELECT * FROM pickuplines", MyCallback, linesFromDatabase, NULL);
}
sqlite3_close(database);
}
我已經實現的回調&它工作正常。
我對Sqlite有點新,有人可以指出我做錯了什麼。 感謝名單