NSString*path = [[NSBundlemainBundle]pathForResource:@"DB.sqlite"ofType:nil]; FMDatabase*db = [FMDatabasedatabaseWithPath:path]; if(![dbopen]) { NSLog(@"數據庫打開失敗"); return; }else{ NSLog(@"打開成功"); } FMResultSet*results = [dbexecuteQuery:@"SELECT * FROM BatteryUTF8"]; while ([results next]) { NSLog(@"%@ %@ %@ %@ %@ %@", [results objectForColumnIndex:0],[results objectForColumnIndex:1],[results objectForColumnIndex:2],[results objectForColumnIndex:3],[results objectForColumnIndex:4],[results objectForColumnIndex:5]); }
五、代碼寫入plist文件,而後從沙盒中拷貝出該文件sql
NSArray*doc =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString*docPath = [ docobjectAtIndex:0]; [ arraywriteToFile:[docPathstringByAppendingPathComponent:@"Battery.plist"]atomically:YES]; NSLog(@"pathPlist:%@",docPath);