开发者

Application with SQLite3 db included crashing on Snow Leopard

开发者 https://www.devze.com 2023-02-02 18:48 出处:网络
I have included SQLite3 db within a cocoa application, from a Leopard system and saving and retrieving some data from it.

I have included SQLite3 db within a cocoa application, from a Leopard system and saving and retrieving some data from it.

Problem is - although it is running fine on Leopard, it is crashing on Snow Leopard.

Part of the crash report is as follows:

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

The method(s) which I call in beginning to initialize and open db are as follow:

-(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");
    }
}

Can anyone suggest some solution for it » solution is found. I have posted it as answer.


Now there are some doubts :

  1. Is there any-other folder in which I should store SQLite3 db... other than documents.. should I store it in ~/Library/Application Support/ or any other folder?

  2. Can we check it via our code that- folder in which we are storing the db file has appropriate permissions or not?

  3. If folder does not have appropriate permission then can we change it via code?

Can anyone clear these doubts or tell me the standard way to implement my requirements?

Thanks,

Miraaj


The only problem I think of is that you're accidentally using a bad set of sqlite libraries. Check your system for any instance of them, or even statically link them? If it isn't that, I don't see anything wrong. (I'm assuming database is declared and set to nil elsewhere.)


To resolve the problem reported above I tried to log the result returned from sqlite3_open. I got 14 ie. SQLITE_CANTOPEN. I checked directory permission and found that some permission were not read & write. When I changed all to read & write, it started working properly :)

0

精彩评论

暂无评论...
验证码 换一张
取 消