它没有在目标c中手动显示更新的数据库 [英] It is not showing updated database manually in objective c
问题描述
我在iOS开发中使用SQLite数据库(firefox插件).我将数据手动插入到数据库中.但是第一次运行程序,显示该数据.但是在手动将数据再次插入数据库后,该数据未显示.我是ios开发的初学者.贝娄有我的数据库连接.请帮忙.
I am using SQLite database (firefox addon) to my iOS development. I insert data manually to my database. but first time run the program , show that data. but after insert again data to database in manually that data is not showing. I'm beginner for ios development. Bellow has my database connection. please help.
- (void)viewDidLoad
{
NSString *defaultDBPath;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *ddPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:ddPath];
if(!success) {
defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"AddressBook.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:ddPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
// const char *dbpath=[ddPath UTF8String];
const char *dbpath1=[ddPath UTF8String];
sqlite3_stmt *statement;
NSMutableArray *company =[[NSMutableArray alloc]init];
if (sqlite3_open(dbpath1, &contactDB)==SQLITE_OK)
{
NSString *querySQL=[NSString stringWithFormat:@"SELECT CompanyName FROM tblCompany order by CompanyName"];
const char *query_stmt=[querySQL UTF8String];
if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL)==SQLITE_OK)
{
int i=0;
while(sqlite3_step(statement)==SQLITE_ROW)
{
NSString *my=[[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(statement, 0)];
NSLog(@"name %@",my);
[company insertObject:my atIndex:i];
i=i+1;
companyDetails=[NSDictionary dictionaryWithContentsOfFile:my];
// [[cell textlabel] setText:my];
}
companies =company;
companyKey=[companyDetails allKeys];
sqlite3_finalize(statement);
}
else
NSLog(@"Not connected");
sqlite3_close(contactDB);
}
Getdatabase路径方法::
Getdatabase path method ::
- (NSString *) getDBPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"Address.sqlite"];
}
我尝试了这些,但是ti没有在我的iOS应用程序中显示更新的数据库数据.请给我一个解决方案.
I tried these but ti is not showing updated database data in my iOS application. Please give me a solution.
推荐答案
您不检查项目文件夹中的.sqlite文件,而是像这样检查文件路径
you not check .sqlite file in project folder,to check file path like this
/Users/username/Library/Application Support/iPhone Simulator/5.0/Applications/4F4574E2-AD8A-493E-9B16-2D456AFAEB6C/Documents/your file.sqlite
//username - your user name
//4F4574E2-AD8A-493E-9B16-2D456AFAEB6C -it changed for projects
这篇关于它没有在目标c中手动显示更新的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!