Here is the code. It works on the simulator:

-(NSMutableArray *)statesWithinMiles:(NSString *)miles{
        NSMutableArray *states = [[NSMutableArray alloc]init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"whatsfresh.sql"];

    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
sqlite3_create_function(database, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL); NSString *tmp = @"SELECT DISTINCT state_abbr as state FROM geoinfo WHERE distance(Latitude, Longitude, ";
                tmp = [tmp stringByAppendingString:[self currentLatitude]];
                tmp = [tmp stringByAppendingString:@","];
                tmp = [tmp stringByAppendingString:[self currentLongitude]];
                tmp = [tmp stringByAppendingString:@") < "];
                tmp = [tmp stringByAppendingString:miles];
                tmp = [tmp stringByAppendingString:@" and state_abbr NOT NULL 
;"];
                
                const char *sql = [tmp 
cStringUsingEncoding:NSUTF8StringEncoding];
        sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
            while (sqlite3_step(statement) == SQLITE_ROW) {
                                char *str = (char 
*)sqlite3_column_text(statement, 0);
[states addObject:(str) ? [NSString stringWithUTF8String:str] : @""];
                        }
                }
        }
        return states;
}


Why doesn't this work on the device?
Help this is causing me hours of grief with errors like these.

Thanks from a noobie who is almost there.

James
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to