我在一个可可应用程序中包含了SQLite3数据库,来自Leopard系统并保存并从中检索一些数据。
问题是 - 虽然它在Leopard上正常运行,但它正在Snow Leopard上崩溃。
部分崩溃报告如下:
Process: RCS [84283]
Path: /Volumes/RCS Project/~RCS APPLICATIONS/~RCS (Macintosh)/2011/26-January 2011/RCS.app/Contents/MacOS/RCS
Identifier: com.tprf.RCS
Version: 2.0 build-0235 (2.0)
Code Type: X86 (Native)
Parent Process: launchd [173]
Date/Time: 2011-01-04 07:51:59.950 -0800
OS Version: Mac OS X 10.6.5 (10H574)
Report Version: 6
Interval Since Last Report: 494528 sec
Crashes Since Last Report: 24
Per-App Interval Since Last Report: 25 sec
Per-App Crashes Since Last Report: 2
Anonymous UUID: A9023F03-79EA-4444-B7BF-25AB6DD07985
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to open database'
*** Call stack at first throw:
(
0 CoreFoundation 0x947e76ba __raiseError + 410
1 libobjc.A.dylib 0x9182e509 objc_exception_throw + 56
2 CoreFoundation 0x947e73e8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x913e6bb3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 RCS 0x002af73c -[LocalDBController openDB] + 214
5 RCS 0x00075157 -[SplashScreen awakeFromNib] + 32
6 CoreFoundation 0x9477f9b4 -[NSSet makeObjectsPerformSelector:] + 196
7 AppKit 0x94d2721c -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1566
8 AppKit 0x94d251f4 loadNib + 257
9 AppKit 0x94d245ed +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 228
10 AppKit 0x94d244fe +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 158
11 AppKit 0x94d24449 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 383
12 AppKit 0x94d2124d NSApplicationMain + 434
13 RCS 0x00002ce6 start + 54
)
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x94832a37 ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ + 7
1 libobjc.A.dylib 0x9182e509 objc_exception_throw + 56
2 com.apple.CoreFoundation 0x947e73e8 +[NSException raise:format:arguments:] + 136
3 com.apple.Foundation 0x913e6bb3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 com.tprf.RCS 0x002af73c -[LocalDBController openDB] + 214
5 com.tprf.RCS 0x00075157 -[SplashScreen awakeFromNib] + 32
6 com.apple.CoreFoundation 0x9477f9b4 -[NSSet makeObjectsPerformSelector:] + 196
7 com.apple.AppKit 0x94d2721c -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1566
8 com.apple.AppKit 0x94d251f4 loadNib + 257
9 com.apple.AppKit 0x94d245ed +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 228
10 com.apple.AppKit 0x94d244fe +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 158
11 com.apple.AppKit 0x94d24449 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 383
12 com.apple.AppKit 0x94d2124d NSApplicationMain + 434
13 com.tprf.RCS 0x00002ce6 start + 54
我在开始初始化和打开db时调用的方法如下:
-(void)dbInit{ // call in awake from NIB
databaseName = [[NSString alloc] initWithString:@"test10.sql"];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString:[documentsDir stringByAppendingPathComponent:databaseName]];
NSLog(@"databasePath - %@",databasePath);
[self checkAndCreateDatabase];
}
-(void)checkAndCreateDatabase{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:databasePath];
NSLog(@"checkAndCreateDatabase, success - %d",success);
if(success){
[self openDB];
return;
}
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
// opening db
[self openDB];
}
- (void)openDB{
if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK)
{
sqlite3_close(database);
NSAssert(0, @"Failed to open database");
}
else{
NSLog(@"db successfully opened");
}
}
任何人都可以建议一些解决方案»找到解决方案。我把它作为答案发布了。
现在有一些疑问:
是否有任何其他文件夹,我应该存储SQLite3 db ...除了文档..我应该将它存储在〜/ Library / Application Support /或任何其他文件夹中吗?
我们可以通过我们的代码检查它 - 我们存储db文件的文件夹是否具有适当的权限?
如果文件夹没有相应的权限,我们可以通过代码更改吗?
任何人都可以清除这些疑问或告诉我实现我的要求的标准方法吗?
谢谢,
Miraaj
答案 0 :(得分:0)
我想到的唯一问题是你不小心使用了一组糟糕的sqlite库。检查您的系统是否有任何实例,甚至静态链接它们?如果不是这样,我没有看到任何错误。 (我假设数据库已声明并在其他地方设置为nil。)
答案 1 :(得分:0)
要解决上面报告的问题,我尝试记录从sqlite3_open返回的结果。我得到14即。 SQLITE_CANTOPEN。我检查了目录权限,发现有些权限未被阅读&写。当我把所有内容都改为阅读&写,它开始正常工作:))