我正在尝试运行此查询,但 NSLog 既不工作也不显示警报.. 查询不执行它不进入 if 循环
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
}
我的查询有什么问题为什么它不执行查询并打开数据库或在 if 循环中打印日志……任何人都可以更正我的代码……有什么帮助吗?