我正在使用下面的代码..在某些语句中可以正常使用模拟器,但不能与设备一起使用..在IF语句中失败但在模拟器中工作正常。 可能是什么问题..请帮忙
DB PAth
-(void) openDB {
NSString *databaseFilename = @"A.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseFilename];
NSLog(@"file address %@",databasePath);
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:databasePath error:nil];
//copying
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseFilename];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
if (sqlite3_open([databasePath UTF8String], &db) != SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, @"Database failed to open.");
}
}
和代码是
sqlite3_stmt *statement;
NSString *sql;
sql=@"INSERT into db values(?,?)";
if (sqlite3_prepare_v2(db1, [sql UTF8String], -1, &statement, nil) == SQLITE_OK){
sqlite3_bind_text(statement, 1, [A.text UTF8String], -1, NULL);
sqlite3_bind_text(statement, 2, [B_text.text UTF8String], -1, NULL);
sqlite3_step(statement);
sqlite3_finalize(statement);
}