I wan to insert "title" and "description" into database using the following code but i am having problem in displaying the "title" into uitableview..instead of "title" it display the "description"...what could be the reason??am i inserting into the wrong column?i am sure i called the correct object.
-this is how i create my table...
CREATE TABLE "Snap" ("snapID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "snapTitle" VARCHAR, "snapDesc" VARCHAR, "snapImage" BLOB)
-(void) addSnap {
if(addStmt == nil) {
const char *sql = "insert into Snap(snapTitle, snapDesc) Values(?, ?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [snapTitle UTF8String], -1, SQLITE_TRANSIENT);//bind title to insert statement
sqlite3_bind_text(addStmt, 2, [snapDescription UTF8String], -2, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))//execute step statement if it return SQLITE_DONE
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//sqlite3_last_insert_rowid
snapID = sqlite3_last_insert_rowid(database);//get primary key for the row which was inserted
//reset add statement
sqlite3_reset(addStmt);
}
(void) getInitialDataToDisplay:(NSString *)dbPath {
Snap2PlayAppDelegate *appDelegate = (Snap2PlayAppDelegate *)[[UIApplication sharedApplication]delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select snapID, snapTitle from Snap";
sqlite3_stmt *selectstmt;
if (sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
snap2play *snap2playObj = [[snap2play alloc] initWithPrimaryKey:primaryKey];
snap2playObj.snapTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)];
snap2playObj.isDirty = NO;
[appDelegate.snapArray addObject:snap2playObj];
[snap2playObj release];
}
}
}
else
sqlite3_close(database); //close database even if it fails to open to release all memory
}