What steps will reproduce the problem?
1. Call [[SQLiteInstanceManager sharedManager] tableExists:@"..."] before
accessing a persistent
object.
What is the expected output? What do you see instead?
expect to get true or false, get a null pointer error
Fix:
use [self database] instead of the member variable in the tableExists: method.
Bonus:
here's a new method to see if a column exists in a table, which is great for
doing schema
updates:
- (BOOL)columnExists:(NSString *)columnName inTable:(NSString *)tableName {
BOOL ret = NO;
NSString *query = [NSString stringWithFormat:@"pragma table_info(%@);", tableName];
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2( [self database], [query UTF8String], -1, &stmt, nil) == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
const char *name = (const char *)sqlite3_column_text(stmt, 1);
if (name != NULL && [columnName isEqualToString:[NSString
stringWithCString:name]]) {
ret = YES;
break;
}
}
sqlite3_finalize(stmt);
}
return ret;
}
Original issue reported on code.google.com by paule...@gmail.com on 28 Apr 2009 at 7:26
Original issue reported on code.google.com by
paule...@gmail.com
on 28 Apr 2009 at 7:26