在这里我优化了以下代码,我得到了完美的数据库路径意味着 NSLog(@"in save data::%s",dbasePath); 但之后如果条件代码无法优化
-(void)saveData{
sqlite3_stmt *statment;
dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir=[dirPath objectAtIndex:0];
const char *dbasePath=[dbPath UTF8String];
NSLog(@"in save data::%s",dbasePath);
if (sqlite3_open(dbasePath, &sqlDatabase)) {
NSString *insert_query=[NSString stringWithFormat:@"INSERT INTO PRJDATA VALUES(\"%@\",\"%@\"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\")",title,timeGet1.text,timeGet2.text,timeGet3.text,dateField.text,interval1.text,interval2.text];
NSLog(@"query string::%@",insert_query);
const char *insert_stmt=[insert_query UTF8String];
NSLog(@"error in insert::%s",sqlite3_errmsg(sqlDatabase));
sqlite3_prepare_v2(sqlDatabase, insert_stmt, -1, &statment, NULL);
if (sqlite3_step(statment)==SQLITE_DONE) {
status.text=@"content added";
timeGet1.text=@"";
timeGet2.text=@"";
timeGet3.text=@"";
dateField.text=@"";
interval1.text=@"";
interval2.text=@"";
}
else{
status.text=@"failed to add";
}
sqlite3_finalize(statment);
sqlite3_close(sqlDatabase);
}
}