iOS的SQLite利用FMDB进行操作时无法打开数据库
1.按照FMDB文档格式进行SQLite的数据库建立,以及建表、插入、关闭的操作。但是真机测试时似乎是权限问题,不让在手机的documentation目录下进行读写操作。
2.源代码如下:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *infraredDataBasePath = [documentDirectory stringByAppendingPathComponent:@"ifraredDataBase.sqlite"];
//建立ifraredDataBase
FMDatabase *ifraredDataBase = [FMDatabase databaseWithPath:infraredDataBasePath];
BOOL res1111 = [ifraredDataBase open];
if (res1111 == YES)
{
NSLog(@"ifraredDataBase 打开成功!");
//建表
[ifraredDataBase executeUpdate:@"CREATE TABLE IF NOT EXISTS ifraredTable (temp REAL, date TEXT)"];
//插入数据
NSString *insertTempAndDate = [NSString stringWithFormat:
@"INSERT INTO ifraredTable (temp, date) VALUES ('%@', '%@')",
tempForDB, timeForDB];
BOOL res = [ifraredDataBase executeUpdate:insertTempAndDate];
if (res == YES)
{
NSLog(@"SQLite插入数据成功!");
}
else
{
NSLog(@"SQLite插入数据失败!");
}
}
else
{
NSLog(@"ifraredDataBase 打开失败!");
}
[ifraredDataBase close];
3.Xcode反馈的错误信息如下:
2015-09-07 21:36:24.833 iWorkaides[1242:156531] error opening!: 14
2015-09-07 21:36:24.833 iWorkaides[1242:156531] ifraredDataBase 打开失败!
Printing description of infraredDataBasePath:
/var/mobile/Containers/Data/Application/C13AB1F7-B11C-4E4F-887B-A8CD76E16599/Library/Documentation/ifraredDataBase.sqlite
Printing description of infraredDataBasePath:
/var/mobile/Containers/Data/Application/C13AB1F7-B11C-4E4F-887B-A8CD76E16599/Library/Documentation/ifraredDataBase.sqlite
Printing description of ifraredDataBase:
<FMDatabase: 0x170669dc0>
4.找了好久文档仍旧无法解决,着急,希望能有人能帮帮我。 :)
影子dē逆袭
9 years, 4 months ago