我为表和数据库提供了相同的名称。但是我没有找到这样的表错误。
sqlite3 *dbConnection = nil;
NSArray *documentDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [documentDirectory objectAtIndex:0];
NSString *documentPath = [path stringByAppendingPathComponent:@"locations.sqlite"];
sqlite3_open([documentPath UTF8String], &dbConnection);
sqlite3_stmt *statement = nil;
@try {
if(sqlite3_open([documentPath UTF8String], &dbConnection)!=SQLITE_OK)
{
sqlite3_close(dbConnection);
}
else
{
//create editable database copy
}
NSString *selectQuery=[[NSString alloc] initWithFormat:@"select * from address_locations"];
const char * retrieveQuery = [selectQuery UTF8String];
if(sqlite3_prepare_v2(dbConnection,retrieveQuery, -1, &statement, nil)==SQLITE_OK)
{
while (sqlite3_step(statement)==SQLITE_ROW)
{
NSMutableDictionary * dictionaryAboutInfo = [[NSMutableDictionary alloc]init];
[dictionaryAboutInfo setValue:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 0)] forKey:@"ZIP"];
[dictionaryAboutInfo setValue:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 1)] forKey:@"LATITUDE"];
[dictionaryAboutInfo setValue:[NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)] forKey:@"LONGITUDE"];
////NSLog(@"Retrived Dict values %@",dictionaryAboutInfo);
[dealersInfoArray addObject:dictionaryAboutInfo];
[dictionaryAboutInfo release];
}
}
[selectQuery release];
}
@catch (NSException *exception) {
}
@finally {
sqlite3_finalize(statement);
sqlite3_close(dbConnection);
}
感谢提前