【发布时间】:2012-12-22 13:14:21
【问题描述】:
我正在尝试运行此查询,但 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 循环中打印日志……任何人都可以更正我的代码……有什么帮助吗?
【问题讨论】:
-
NS在控制台中记录查询并在sqlite管理器上执行。我认为查询有问题
-
是的,它可以工作..即使我进行查询“SELECT * from site”..它应该进入循环并显示也不起作用的 NSLog ...
-
我只需要执行查询并显示警报 ..
-
sqlite_open 和 sqlite_prepare 中的 NSlogs 是否正常工作?
-
没有一个工作...
标签: ios sql database xcode sqlite