0
votes

i have a problem for some time which i can't solve:

In the applicationDidFinishLaunching i have this code:

[self checkAndCreateDatabase];
[self readCharsFromDatabase];// which stores into an array some objects
[self readGlyphsFromDatabaseAtId:@"a"];// idem

The second array i'm using into a secondary ViewController and i'm getting the array in the viewDidLoad with:

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
self.array = delegate.array2;

All perfect till now, just that i want to run a new query before getting the array2. I'm trying with this:

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate readGlyphsFromDatabaseAtId:@"b"];// which is supposed to override my array2 with new values
self.array = delegate.array2;

This stops my application without error. I get this message only:

GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 4736.

My method is called till this point, after it i don't get a NSLog neither in the if, neither in the else:

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)

Can someone help? Or if the logic is wrong to point me to the correct way of doing it? If it's not to large for the memory i can store all the database in some arrays, it has 400kb Thanks!

EDIT: This is how my function looks:

-(void) readGlyphsFromDatabaseAtId:(NSString *)charId {
    NSLog(@"reading glyphs for id %@", charId);
    // Setup the database object
    sqlite3 *database;

    // Init the animals Array
    glyphs = [[NSMutableArray alloc] init];
    NSLog(@"1");
    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        NSLog(@"reading row");
        // Setup the SQL Statement and compile it for faster access
        NSString *query = [NSString stringWithFormat:@"SELECT nr,title,description FROM `glyphs` WHERE `id`='%@'", charId];
        NSLog(@"%@", query);
        //const char *sqlStatement = "SELECT nr,title,description FROM `glyphs` WHERE `id`='b'";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, [query UTF8String], -1, &compiledStatement, nil) == SQLITE_OK) {
            NSLog(@"prepared OK");
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                //NSLog(@"reading row");
                NSString *aNr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
                NSString *aTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                //NSLog(@"glyph: %@ %@ %@", aNr, aTitle, aDescription);

                Glyph *g = [[Glyph alloc] initWithCharId:charId glyphNr:aNr glyphTitle:aTitle glyphDescription:aDescription];

                [glyphs addObject:g];
                [g release];
            }
        }
        else {
            NSLog(@"not prepared");
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);
    }
    else{
        NSLog(@"sqlite not ok");
    }
    sqlite3_close(database);
    NSLog(@"fin reading database2");
}
2
If it just drops into GDB without an error message appearing, how do you know there is actually an error? Have you tried running "Build and Analyse", and using the memory leak detector and all of the other tools very often useful in resolving these sorts of issues?Jay
Also make sure you don't simply have a breakpoint set there that you forgot about.nall
Thank you for the tips, i'm at begining with the iphone, 2-3 weeks so will be hard for me to use that tools, but i'll try. I also have no break points. So there's nothing wrong with my method?Cristi Băluță
If the application isn't responsible anymore and the NSLog doesn't log anything in "if else", there must be an error, isn't it?Cristi Băluță
It sounds like the sqlite3_open call may be hanging for some reason. If you don't get a gdb prompt and NSLog messages after that statement aren't printed, that seems to be the only explanation.nall

2 Answers

1
votes

Ok, seems that the databasePath wasn't accessible, so i re-inited it and now works. If someone can enlighten a bit about why....

databasePath was inited in applicationDidFinishLaunching

0
votes

Are you calling sqlite3_open() in each invocation of readGlyphsFromDatabaseAtId? If you're doing that with the database already open, that may cause issues.