I'm writing a simple navigation view iphone program using sqlite for learning purposes. I previously had a single table in the database, but have now updated it to two and my INNER JOIN statement crashes out. The SQL statement seems to work just fine running it directly. In the code below the uncommented statement works just fine, but the commented one will kick out to the error if I switch them out.
static sqlite3_stmt *init_statement = nil;
static sqlite3_stmt *dehydrate_statment = nil;
@implementation ICD9
@synthesize primaryKey,text,priority,status,match;
- (id)initWithPrimaryKey:(NSInteger)pk database:(sqlite3 *)db {
if (self = [super init]) {
primaryKey = pk;
database = db;
if (init_statement == nil) {
const char *sql = "SELECT text,priority,complete FROM todo WHERE pk=?";
//const char *sql = "SELECT todo.*, match.code10 FROM todo INNER JOIN match ON match.text = todo.text WHERE pk=1;";
if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
}
return self;
}
The tables are in the same db:
CREATE TABLE todo(pk INTEGER PRIMARY KEY, text VARCHAR(25), priority INTEGER, complete BOOLEAN);
CREATE TABLE match(matchid INTEGER PRIMARY KEY, text VARCHAR(25), name VARCHAR(25));
I'm pretty new to this so any help would be appreciated.