ios - Assertion failure in MainViewController -
i trying insert records table in sqlite3 following code, code working fine ios 8 gives assertion error in ios 7.1.2.
table creation:
nslog(@"database path %@",self.databasepath); if ([manager copyitematpath:sourcepath topath:self.databasepath error:&error] == no) { nslog(@"error : %@", [error localizeddescription]); } // createstmt = nil; if (sqlite3_open([self.databasepath utf8string], &database) == sqlite_ok) { const char *sql_stmt = "create table if not exists categorytable (mainimg blob,addimg blob,cat_nm text,image_nm text,lastmodified text,cat_desc text,prod_id text,prod_nm text,prod_desc text,sku text,supplier_id text,supplier_phone text,product_dosage text,unit_size text,unit_price text)"; //nsstring *query=[nsstring stringwithformat:@"create table %@(rollno integer, name text)",tablename]; if (sqlite3_prepare_v2(database, sql_stmt, -1, &statement, null) != sqlite_ok) { } sqlite3_exec(database,sql_stmt, null, null, null); const char *sql_stmt_promo = "create table if not exists promotionaldata (imagedata blob,thumbdata blob)"; if (sqlite3_prepare_v2(database, sql_stmt_promo, -1, &statement, null) != sqlite_ok) { } sqlite3_exec(database,sql_stmt_promo, null, null, null); } sqlite3_close(database); record insertion :
sqlite3 *database; if (sqlite3_open([appdelegate.databasepath utf8string], &database) == sqlite_ok) { sqlite3_stmt *statement; const char* sqlitequery = "insert categorytable (mainimg,addimg,cat_nm,image_nm,lastmodified,cat_desc,prod_id,prod_nm,prod_desc,sku,supplier_id,supplier_phone,product_dosage,unit_size,unit_price) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; if (sqlite3_prepare_v2(database, sqlitequery, -1, &statement, null) == sqlite_ok) { sqlite3_bind_blob(statement, 1, [mainimg bytes], [mainimg length], sqlite_static); sqlite3_bind_text(statement, 2, [addimg utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 3, [cat_nm utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 4, [image_nm utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 5, [lastmodified utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 6, [cat_desc utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 7, [prod_id utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 8, [prod_nm utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 9, [prod_desc utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 10, [sku utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 11, [supplier_id utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 12, [supplier_phone utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 13, [product_dosage utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 14, [unit_size utf8string], -1, sqlite_transient); sqlite3_bind_text(statement, 15, [unit_price utf8string], -1, sqlite_transient); sqlite3_step(statement); sqlite3_finalize(statement); nslog(@"inserted "); } else { nsassert1(0, @"error:'%s'", sqlite3_errmsg(database)); // nslog(@"not inserted "); } sqlite3_close(database); } the error message:
2015-07-08 08:54:17.819 swaroopagro[365:60b] assertion failure in -[mainviewcontroller savemainimg:withaddimg:withcat_nm:withimage_nm:withlastmodified:withcat_desc:withprod_id:withprod_nm:withprod_desc:withsku:withsupplier_id:withsupplier_phone:withproduct_dosage:withunit_size:withunit_price:], /users/dhananjaypatil/desktop/swaroop/sw copy 8.1/swaroopagro_iphone 2/swaroopagro/mainviewcontroller.m:700 2015-07-08 08:54:22.616 swaroopagro[365:60b] terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'error:'table categorytable has no column named mainimg'' *** first throw call stack: (0x30ba0f83 0x3b351ccf 0x30ba0e5d 0x3154ed5b 0xeae13 0xea563 0xe993f 0xedd7d 0x314e0fc3 0x314e0f07 0x314e0e21 0x308070e7 0x30805cf7 0x30ad48f1 0x3079d6bb 0x3079d579 0x3079d40d 0x30b6c20b 0x30b6b6db 0x30b69ecf 0x30ad4ebf 0x30ad4ca3 0x359da663 0x3342114d 0xc1ea5 0x3b85eab7) libc++abi.dylib: terminating uncaught exception of type nsexception
the error message tells terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'error:'table categorytable has no column named mainimg''. pretty self-explanatory: table categorytable has no column mainimg when trying insert value - i assuming happens during insert.
since create table if not exists statement creates column guess have changed data schema of table in past. on ios8 device have installed app afterwards. on ios7 have installed app before already. causes table on ios7 present, wrong schema, present. therefore not created , retains invalid schema.
try deleting app ios7 device , rerunning app after that.
Comments
Post a Comment