i am trying to run this query but neither NSLog is working nor the alert is showing .. query does not executes it does not gets into the if loop
viewDidLoad{
pin_lat = pinAnnotation.coordinate.latitude;
NSLog(@"pin latitude is %f",pin_lat); //This one is only working
sqlite3_stmt *statement;
NSString *qsql = [NSString stringWithFormat:@"SELECT name FROM site WHERE latitude LIKE %f AND longitude LIKE %f",pin_lat,pin_long];
if (sqlite3_open([qsql UTF8String], &db) == SQLITE_OK){
// sqlite3_exec(db, [statement UTF8String],NULL, NULL, &err == SQLITE_OK);
NSLog(@"QUERY IS WORKING IN OPEN DB");
if (sqlite3_prepare_v2(db, [qsql UTF8String], -1, &statement, nil)== SQLITE_OK)
{
NSLog(@"QUERY IS WORKING IN DB PREPARE");
while(sqlite3_step(statement)==SQLITE_ROW)
{
/* char *field1 = (char *) sqlite3_column_text(statement, 3); getting name value in field1
NSString *field1Str =
[[NSString alloc] initWithUTF8String: field1];
[field1Str release];*/
NSLog(@"QUERY IS WORKING");
UIAlertView *alert_pin = [[UIAlertView alloc] initWithTitle:@"" message:@"Cannot create a duplicate location" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Done", nil];
[alert_pin show];
[alert_pin release];
}
//—-deletes the compiled statement from memory—-
sqlite3_finalize(statement);
}
else{
[mapView addAnnotation:pinAnnotation]; // this is working ... but i want the if loop to also work
}
}
sqlite3_close(db);
// not exist to show alert
}
what is wrong with my query why is it not executing the query and opening the DB or printing the Log’s inside the if loop … can any one correct my code .. any help?
Midhun is correct. I’d further advise that each of these
ifstatements should have a correspondingelseclause that displays the return code as well as, if possible, the error message. Or, equivalently, check for failure at each step and, if so, report diagnostic information and return. Thus, it might look like: