我想在应用程序的加载时检查table
中是否有数据可用,所以我在第一个文件的viewload上使用以下代码(如果可用)然后移动到其他文件,保留相同但它不能给出完美的结果,主要是行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;
}
答案 0 :(得分:0)
我相信,这是错误
SELECT COUNT(*) PRJDATA
你应该使用这个
SELECT COUNT(*) FROM PRJDATA