views:

161

answers:

2

Hello, 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");
}
A: 

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

nall
I edited the first post. If i'm calling it from the AppDelegate i can call it as many times as i want
Cristi Băluță
when this hang happens, type ctrl-c in the gdb console window. then type 'where' to get a stack trace and post that.
nall
Seems there's a problem with the databasePath, i can't access it. So this line is not executed if i introduce it there:NSLog(@"DATABASE PATH %@", databasePath);Any ideas now?
Cristi Băluță
I pasted here the result with "where":http://paste.org/pastebin/view/10723
Cristi Băluță
+1  A: 

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

Cristi Băluță
Find all the places databasePath is initialized. Don't forget to check the XIB if you're using IB bindings.
nall