Application with SQLite3 db included crashing on Snow Leopard

11 views
Skip to first unread message

Decoder

unread,
Jan 4, 2011, 11:17:15 PM1/4/11
to cocoa-unbound
Hi all,

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: A9320F03-79EA-467C-
B7BF-25AB6DD07E71

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?

Thanks,

Monaj

Jim Dovey

unread,
Jan 4, 2011, 11:23:27 PM1/4/11
to cocoa-...@googlegroups.com
On 2011-01-04, at 11:17 PM, Decoder wrote:

> Hi all,
>
> 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.

First guess— you're calling -openDB instead of -dbInit, so various things, including member variables, aren't being set up properly passing in a NULL path to the database.

Other than that, I'd suggest looking at the return value from sqlite3_open() for more information. It would be good practice to put that error and the string from (I think) sqlite3_error_string() into the exception that you're throwing, either as part of the reason or packed into the exception's userInfo dictionary.

-Jim

Brent Simmons

unread,
Jan 4, 2011, 11:23:52 PM1/4/11
to cocoa-...@googlegroups.com

On Jan 4, 2011, at 8:17 PM, Decoder wrote:
> - (void)openDB{
> if (sqlite3_open([databasePath UTF8String], &database) !=
> SQLITE_OK)
> {
> sqlite3_close(database);
> NSAssert(0, @"Failed to open database");
>

What would be very helpful is to know what sqlite3_open is returning -- if it's not SQLITE_OK, then what is it? That would give you an important clue as to what's going wrong.

-Brent

Duncan Campbell

unread,
Jan 4, 2011, 11:35:14 PM1/4/11
to cocoa-...@googlegroups.com
I'd suggest not rolling your own, but instead using Gus' excellent wrapper:

https://github.com/ccgus/fmdb

---------------------------------------------------------------
Duncan Campbell
http://objective-d.com
Twitter: dunk
---------------------------------------------------------------

Matter will be damaged in direct proportion to its value.

Decoder

unread,
Jan 4, 2011, 11:56:35 PM1/4/11
to cocoa-unbound
It is giving this message for sqlite3_open : SQLITE_CANTOPEN

Decoder

unread,
Jan 5, 2011, 12:04:24 AM1/5/11
to cocoa-unbound
Is there anything else which I can provide to help me to resolve this
problem?

Brent Simmons

unread,
Jan 5, 2011, 12:08:21 AM1/5/11
to cocoa-...@googlegroups.com
I think your next step is to do a Google search on SQLITE_CANTOPEN. The odds are good that other people have had the same problem, and there is most likely some good advice on what to do next.

-Brent

Gus Mueller

unread,
Jan 5, 2011, 3:15:19 PM1/5/11
to cocoa-...@googlegroups.com
What Duncan says, and if not that, then maybe use:
[databasePath fileSystemRepresentation]
instead of:
[databasePath UTF8String]

-gus

P.S:

You've got:


databaseName = [[NSString alloc] initWithString:@"test10.sql"];

make sure you're releasing that in your dealloc, or at least do:
databaseName = @"test10.sql";


--

August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/

Decoder

unread,
Jan 6, 2011, 4:23:32 AM1/6/11
to cocoa-unbound
Hi all,

Finally I got the reason for my problem.. thanx for all your
replies :)

Solution found:

I checked permission of Documents folder and found that some
permission were not read & write. When I changed all to read & write,
it started working properly :)

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?
Reply all
Reply to author
Forward
0 new messages