[英]Im getting no such table <table name> error when i retrieve the data from sqlite?
I gave same name for table and database .But i am getting no such table found error. 我给表和数据库起了相同的名字。但是我没有得到这样的表发现错误。
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);
}
Thanks for advance 谢谢前进
I think your database file in bundle and you are retrieving the database from documentDirectory.. not from bundle!!!! 我认为您的数据库文件在捆绑中,而您正在从documentDirectory ..而不是捆绑中检索数据库!
you can change the path as 您可以将路径更改为
NSString *documentPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"locations.sqlite"];
BOOL success;
NSFileManager *fileManager=[NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:documentPath];
if (success)
{
NSLog(@"file found at the document path");
}
//bundle path
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"address_locations.sqlite"];
[fileManager copyItemAtPath:databasePathFromApp toPath:documentPath error:nil];
sqlite3_open([documentPath UTF8String], &dbConnection); sqlite3_open([[documentPath UTF8String],&dbConnection);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.