Hi I have a function which basically tries to insert some data returned from a REST call.
- (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); }
everything seems fine query string in log statement is also fine but the data does not gets inserted. Where as a counterpart of this function for select statement works well. Here is the counter part
- (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);
}
I have implemented callback & it works fine.
I am a little new to Sqlite can someone please point out what am I doing wrong. Thanx