I am new to iphone development. I want to insert several values ββinto my sqlite3 database and display the contents in a table. I can insert one row of data into my database and get it and display the data, but I cannot do with inserting several rows of data. Here is my code ...
-(void)initializeTableData{ sqlite3 *db=[DatabaseTestAppDelegate getNewDBConnection]; sqlite3_stmt *statement=nil; sqlite3_stmt *statement1=nil; if (insert_MyObj_statement == nil) { const char *sql2="DELETE FROM user"; sqlite3_prepare_v2(db, sql2, -1, &statement1, NULL); sqlite3_step(statement1); //const char *sql1 = "INSERT INTO user (id,name) VALUES ('0','ash'),('3','karna'),('2','kumar'),('5','siva')"; const char *sql1 = "INSERT INTO user (id,name) VALUES ('0','xxx')"; int result=sqlite3_prepare_v2(db, sql1, -1, &insert_MyObj_statement, NULL); NSAssert1(result == SQLITE_OK, @"addMyObjectIntoDatabase: failed to prepare statement with err '%s'", sqlite3_errmsg(db)); } sqlite3_step(insert_MyObj_statement); const char *sql="select * from user"; if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL)!=SQLITE_OK) NSAssert1(0,@"error in preparing staement",sqlite3_errmsg(db)); else{ while(sqlite3_step(statement)==SQLITE_ROW) [tableData addObject:[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(statement,1)]]; } sqlite3_finalize(statement); }
Is there any other way to insert multiple rows of data into my table. Please help me. Thanks.
source share