App crashes on sqlite after updating the app

0

After updating the app, there is a problem with sqlite database. The app crashes. Here ist my log, but I am not sure what can be wrong:

Stack: (
"0   MyApp                       0x00085bdb MyApp + 543707",
"1   MyApp                       0x0008633d MyApp + 545597",
"2   libsystem_c.dylib                   0x3af73e8b _sigtramp + 34",
"3   libsqlite3.dylib                    0x3792c447 sqlite3_log + 4986",
"4   libsqlite3.dylib                    0x3792c447 sqlite3_log + 4986",
"5   libsqlite3.dylib                    0x3791d1cb sqlite3_exec + 11954",
"6   libsqlite3.dylib                    0x3791b989 sqlite3_exec + 5744",
"7   libsqlite3.dylib                    0x3791b119 sqlite3_exec + 3584",
"8   libsqlite3.dylib                    0x3791ac17 sqlite3_exec + 2302",
"9   libsqlite3.dylib                    0x3791a977 sqlite3_exec + 1630",
"10  libsqlite3.dylib                    0x3795195f sqlite3_prepare_v2 + 30",
"11  MyApp                       0x00091ca7 MyApp + 593063",
"12  MyApp                       0x00094211 MyApp + 602641",
"13  MyApp                       0x000c09d9 MyApp + 784857",
"14  UIKit                               0x3a044545 <redacted> + 412",
"15  UIKit                               0x3a02930b <redacted> + 1310",
"16  UIKit                               0x3a0407c7 <redacted> + 206",
"17  UIKit                               0x39ffc803 <redacted> + 258",
"18  QuartzCore                          0x3bcd0d63 <redacted> + 214",
"19  QuartzCore                          0x3bcd0901 <redacted> + 460",
"20  QuartzCore                          0x3bcd1835 <redacted> + 16",
"21  QuartzCore                          0x3bcd121b <redacted> + 238",
"22  QuartzCore                          0x3bcd1029 <redacted> + 316",
"23  UIKit                               0x3a1cc1e1 <redacted> + 112",
"24  UIKit                               0x3a07c627 <redacted> + 34",
"25  CoreFoundation                      0x342be6cd <redacted> + 20",
"26  CoreFoundation                      0x342bc9c1 <redacted> + 276",
"27  CoreFoundation                      0x342bcc91 <redacted> + 608",
"28  CoreFoundation                      0x3422febd CFRunLoopRunSpecific + 356",
"29  CoreFoundation                      0x3422fd49 CFRunLoopRunInMode + 104",
"30  GraphicsServices                    0x377742eb GSEventRunModal + 74",
"31  UIKit                               0x3a04d2f9 UIApplicationMain + 1120",
"32  MyApp                       0x000036e3 MyApp + 9955",
"33  MyApp                       0x0000369c MyApp + 9884"
)

Row 11 shows that a problem is with the function sqlite3_prepare_v2 in my function:

- (BOOL) checkIfTableExist:(NSString *) tableName
{
BOOL exist = NO;
sqlite3_stmt *stmt;

NSString *sql = [[NSString alloc] initWithFormat:@"SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%@'", tableName];

if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &stmt, NULL) == SQLITE_OK) { 
    if (sqlite3_step(stmt) == SQLITE_ROW)
        exist = YES;

    sqlite3_finalize(stmt);
}

[sql release];

return exist;
}

Could be that after updating the app the database file was broken or something?

ios
database
sqlite
crash

1 Answer

0

The issue is you didn't opened your database. There is no sqlite3_open call in your code.

So the database variable will contain a garbage value. That's why it is crashing.

- (BOOL) checkIfTableExist:(NSString *) tableName
{
  BOOL exist = NO;
  if (sqlite3_open([yourDatabasePath UTF8String], &dataBase) == SQLITE_OK)
  {
    NSString *sql = [NSString stringWithFormat:@"SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%@'", tableName];
    const char *query = [sql UTF8String];
    sqlite3_stmt *stmt;
    if (sqlite3_prepare_v2(database, query, -1, &stmt, NULL) == SQLITE_OK)
    { 
       if (sqlite3_step(stmt) == SQLITE_ROW)
           exist = YES;

       sqlite3_finalize(stmt);
    }
  }
 return exist;
}
answered on Stack Overflow Dec 3, 2012 by Midhun MP

User contributions licensed under CC BY-SA 3.0