dimanche 25 janvier 2015

Updates aren't reflecting on SQLite file in iOS

I have a sqlite file that i added to my Xcode project and have duplicated it into the Documents directory on the iPhone. I have verified it exists but still can't seem to update the file. The code below is the action method that should pass the data into the sqlite file:



-(IBAction)saveButtonPressed:(id)sender
{
//Catch current time in specified format
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *currentDate = [NSDate date];
NSString *localDateString = [dateFormat stringFromDate:currentDate];

//Catch location
CLLocation *location = [self.locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *currentCoordinate = [NSString stringWithFormat:@"%f, %f",coordinate.latitude,coordinate.longitude];
NSLog(@"%@ ... %@",localDateString,currentCoordinate);


NSString *query = [NSString stringWithFormat:@"INSERT INTO sqliteData values(null, 'near', '%@', '%@')", localDateString, currentCoordinate];

[self.dbManager executeQuery:query];

if (self.dbManager.affectedRows != 0) {
NSLog(@"Query was executed");

}
else{
NSLog(@"Could not execute query.");
}
}


executeQuery method:



- (void)executeQuery:(NSString *)query
{
[self runQuery:[query UTF8String] isQueryExecutable:YES];
}

Aucun commentaire:

Enregistrer un commentaire