Ios 为什么我的SELECT语句总是返回0.0000?

Ios 为什么我的SELECT语句总是返回0.0000?,ios,select,sqlite,Ios,Select,Sqlite,好的,我的SQLite3 SELECT语句遇到了很多问题。我的应用程序将GPS坐标以双精度存储在我的表格中。然后它以与double相同的方式检索它们。我的问题是,每次我尝试检索它们时,它都会返回0.000000作为我的纬度/经度值 我知道SELECT语句是有效的,因为我在SQLiteBrowser中对它进行了测试,我知道DB就在那里,因为我在模拟器文档中找到了它,并再次使用SQLiteBrowser打开了它 如果有人能告诉我为什么它返回0.000000而不是37.337434(表中的实际值),那

好的,我的SQLite3 SELECT语句遇到了很多问题。我的应用程序将GPS坐标以双精度存储在我的表格中。然后它以与double相同的方式检索它们。我的问题是,每次我尝试检索它们时,它都会返回0.000000作为我的纬度/经度值

我知道SELECT语句是有效的,因为我在SQLiteBrowser中对它进行了测试,我知道DB就在那里,因为我在模拟器文档中找到了它,并再次使用SQLiteBrowser打开了它

如果有人能告诉我为什么它返回0.000000而不是37.337434(表中的实际值),那么我将感谢您的帮助

-(double)getLatitudeBysourceMonitor:(NSString *)asourceMonitor andpositionNo:(NSNumber *)apositionNo {
double latitude;
NSLog(@"sourcemonitor:%@ positionno:%@",asourceMonitor, apositionNo);
// Open the database from the users filessytem
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"GPS.db"];
if (sqlite3_open([databasePath UTF8String], &databaseHandle) == SQLITE_OK)
    NSLog(@"Database opened properly");
{
    // Setup the SQL Statement and compile it for faster access
    NSString *sqlStatement = [NSString stringWithFormat:@"SELECT latitude FROM GPSJob;"];
    NSLog(@"Searching for values %@ and %d", asourceMonitor, [apositionNo intValue]);
    sqlite3_stmt *statement;
    if(sqlite3_prepare_v2(databaseHandle, [sqlStatement UTF8String], -1, &statement, NULL) == SQLITE_OK) {
        NSLog(@"Statement prepared");
        while(sqlite3_step(statement) == SQLITE_ROW) 
        {
            // Need to get data from database...
            latitude = sqlite3_column_double(statement, 3); 
            NSLog(@"%f", sqlite3_column_double(statement, 3));
        }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(statement);
}
        NSLog(@"Reading latitude as: %f", latitude);
        return latitude;
}

您对
sqlite3\u column\u double
的调用不正确。第二个参数需要是查询返回的列列表的索引。您只查询1列,因此索引必须为
0

latitude = sqlite3_column_double(statement, 0);
NSLog(@"latitude = %f", latitude);

其他一些问题。仅当您实际准备了语句时才调用
sqlite3\u finalize
。如果打开数据库,不要忘记关闭它。如果
sqlite3\u open
sqlite3\u prepapre\u v2
失败,请使用
sqlite3\u errmsg
记录错误。

FYI-这被标记为Xcode 4.2。你真的在使用这样一个过时的Xcode版本吗?如果需要,您确实需要升级。