我是这里的新手。在我的设备上运行时,我无法将任何数据插入我的 SQLite 数据库。我正在使用下面的代码来连接 SQLite。它在我的模拟器中完美运行,但不适用于我的 iPad 设备。有人可以帮忙吗?谢谢你。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"DADatabase1.sqlite"];
NSLog(@"%@", writableDBPath);
FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
/*if ([fileManager fileExistsAtPath:writableDBPath] == NO) {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"DADatabase1.sqlite" ofType:@"sqlite"];
[fileManager copyItemAtPath:resourcePath toPath:writableDBPath error:nil];
}*/
[db open];
[db traceExecution];
[db beginTransaction];
BOOL success = [db executeUpdate:[NSString stringWithFormat:@"insert into PatientDetails (patAge) values (?)",patAge.text]];
if(!success)
{
NSLog(@"Query not success!");
}
else {
NSLog(@"Query success!");
}
//NSString *query = [NSString stringWithFormat:];
[db commit];
[db close];