我想在应用程序的加载时检查数据是否可用,table
因此我在我的第一个文件的视图负载上使用以下代码(如果可用)然后移动到其他文件,否则保留相同但它不能给出完美的结果主要是行count
不工作
NSString *dbPath;
NSString *docsDir;
NSArray *dirPath;
int count=0;
dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir=[dirPath objectAtIndex:0];
dbPath=[[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent:@"TimerDataBaseMain.db"]];
NSFileManager *fileManager=[NSFileManager defaultManager];
if([fileManager fileExistsAtPath: dbPath] == YES)
{
const char *databsPath=[dbPath UTF8String];
NSLog(@"from created;");
if(sqlite3_open(databsPath,&sqlDatabase) == SQLITE_OK)
{
const char *query="SELECT COUNT(*) FROM PRJDATA";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(sqlDatabase, query, -1, &statement, NULL)==SQLITE_OK) {
while(sqlite3_step(statement)==SQLITE_ROW)
{
count++;
NSLog(@"from count");
}
NSLog(@"from row count");
}
sqlite3_finalize(statement);
}
sqlite3_close(sqlDatabase);
}
if (count>0) {
ListEventCreated *listObject=[[ListEventCreated alloc] initWithNibName:@"ListEventCreated" bundle:[NSBundle mainBundle]];
listObject.title=@"List of event";
NSLog(@"from if condition");
NSLog(@"%i",count);
[self.navigationController pushViewController:listObject animated:YES];
[listObject release];
listObject=nil;
}