简体   繁体   English

在设备上测试 sqlite 数据库应用程序

[英]Testing sqlite database application on device

I am working on a database application that works fine in the simulator (inserts, updates, deletes all function correctly).我正在开发一个在模拟器中运行良好的数据库应用程序(正确插入、更新、删除所有 function)。 My problem starts when attempting to install/run the application on an iPhone.尝试在 iPhone 上安装/运行应用程序时,我的问题就开始了。

On the initial run, the program creates an editable version of the database in the documents directory of the application.在初始运行时,程序会在应用程序的文档目录中创建数据库的可编辑版本。 My test fails when the database is not found in the application bundle.当在应用程序包中找不到数据库时,我的测试失败。 The database has been added to the Resources folder in XCode.该数据库已添加到 XCode 的 Resources 文件夹中。

The code to check for an existing version of the database (coupled with several NSLog statements), and to create one if one does not already exist is as follows:检查数据库的现有版本(加上几个 NSLog 语句),如果不存在则创建一个的代码如下:

-(NSString *) createWriteableDatabase { BOOL databaseExists; -(NSString *) createWriteableDatabase { BOOL databaseExists; NSError *error; NSError *错误;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *writeableDB = [documentsDir stringByAppendingPathComponent:@"flashCard.db"];

NSLog(@"writeableDB = '%@'.", writeableDB);

databaseExists = [fileManager fileExistsAtPath:writeableDB];

NSLog(@"databaseExists = %d.", databaseExists);

if (databaseExists)
    return writeableDB;

//--- Writeable version of database does not exist -- copy from bundled software. ---

NSString *defaultPath = [[[NSBundle mainBundle] resourcePath] 
                         stringByAppendingPathComponent:@"flashCard.db"];

NSLog(@"defaultPath = '%@'.", defaultPath);

databaseExists = [fileManager fileExistsAtPath:defaultPath];

NSLog(@"databaseExists = %d.", databaseExists);

databaseExists = [fileManager copyItemAtPath:defaultPath toPath:writeableDB error:&error];

if (!databaseExists)
{
    NSAssert1(0, @"Failed to create writeable database file: '%@'.", [error localizedDescription]);
    return @"";
}

return writeableDB;

} }

The messages displayed in the debugger are as follows:调试器中显示的消息如下:

warning: Unable to read symbols for /XCode 3.2.5/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/System/Library/AccessibilityBundles/AccessibilitySettingsLoader.bundle/AccessibilitySettingsLoader (file not found).警告:无法读取 /XCode 3.2.5/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/System/Library/AccessibilityBundles/AccessibilitySettingsLoader.bundle/AccessibilitySettingsLoader 的符号(找不到文件)。 2011-06-10 21:12:11.130 FlashEm[3768:707] writeableDB = '/var/mobile/Applications/9DBC50B5-2559-4E6A-BD21-B5B56D9DA18A/Documents/flashCard.db'. 2011-06-10 21:12:11.130 FlashEm[3768:707] writeableDB = '/var/mobile/Applications/9DBC50B5-2559-4E6A-BD21-B5B56D9DA18A/Documents/flashCard.db'。 2011-06-10 21:12:11.144 FlashEm[3768:707] databaseExists = 0. 2011-06-10 21:12:11.149 FlashEm[3768:707] defaultPath = '/var/mobile/Applications/9DBC50B5-2559-4E6A-BD21-B5B56D9DA18A/FlashEm.app/flashCard.db'. 2011-06-10 21:12:11.144 FlashEm[3768:707] databaseExists = 0。2011-06-10 21:12:11.149 FlashEm[3768:707] defaultPath = '/var/mobile/Applications/9DBC50B5-2559- 4E6A-BD21-B5B56D9DA18A/FlashEm.app/flashCard.db'。 2011-06-10 21:12:11.154 FlashEm[3768:707] databaseExists = 0. 2011-06-10 21:12:11.169 FlashEm[3768:707] * Assertion failure in -[DBAccess createWriteableDatabase], /Users/marathoner1234/Projects/FlashEm/Classes/../DBAccess.m:92 2011-06-10 21:12:11.201 FlashEm[3768:707] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writeable database file: 'The operation couldn't be completed. 2011-06-10 21:12:11.154 FlashEm[3768:707] databaseExists = 0。2011-06-10 21:12:11.169 FlashEm[3768:707] * -[DBAccess createWriteableDatabase] 中的断言失败,/Users/marathoner1234 /Projects/FlashEm/Classes/../DBAccess.m:92 2011-06-10 21:12:11.201 FlashEm[3768:707] *由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法创建可写数据库file: '操作无法完成。 No such file or directory'.'没有这样的文件或目录'。'

Thanks in advance for any help you can give me, and I apologize if my question text is not formatted properly -- this is my first time asking a question on this site.提前感谢您可以给我的任何帮助,如果我的问题文本格式不正确,我深表歉意——这是我第一次在这个网站上提问。

(I looked at two other questions where the same problem was occurring, and checked to see if the same issues they had applied to my situation, but they do not.) (我查看了发生相同问题的另外两个问题,并检查了它们是否适用于我的情况,但它们没有。)

your crash report says your database file not found your document directory.您的崩溃报告说您的数据库文件未找到您的文档目录。 This happen only if you not properly install database file inside your resources folder means inside your bundle, so the program on iphone device not able to read your database file.仅当您未在资源文件夹中正确安装数据库文件时才会发生这种情况,这意味着在您的捆绑包中,因此 iphone 设备上的程序无法读取您的数据库文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM