Why Database is Locked while inserting data in sqlite in IOS? -
why i'm getting database locked while inserting data in sqlite? open , close database code? have code:
-(void)insertdatain_tbl_selectitem_data: (nsstring *)empid prodid: (nsstring *)prodid prodname: (nsstring *)prodname genname: (nsstring *)genname computetype: (nsstring *)computetype uom: (nsstring *)uom listprice: (nsstring *)listprice uomqty: (nsstring *)uomqty{ const char *query = "insert tbl_selectitem_data (femployeeid,fproductid,fname,fgeneric_name,fcompute_type,fuom,flist_price,fuomqty) values (?,?, ?, ?, ?, ?, ?, ?)"; sqlite3_stmt *stmt; if (sqlite3_open([sqlitedb utf8string], &(_database)) == sqlite_ok) { if (sqlite3_prepare_v2(_database, query, -1, &stmt, nil) == sqlite_ok) { sqlite3_bind_text(stmt, 1, [empid utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 2, [prodid utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 3, [prodname utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 4, [genname utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 5, [computetype utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 6, [uom utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 7, [listprice utf8string], -1, sqlite_transient); sqlite3_bind_text(stmt, 8, [uomqty utf8string], -1, sqlite_transient); if(sqlite3_step(stmt) == sqlite_done){ nslog(@"insert successful"); sqlite3_finalize(stmt); }else{ nslog(@"insertdatain_tbl_selectitem_data error: %s", sqlite3_errmsg(_database)); } } } sqlite3_close(_database);
}
first off all... try 'finalize" statement if there errors... method:
if(sqlite3_step(stmt) == sqlite_done){ nslog(@"insert successful"); sqlite3_finalize(stmt); }else{ nslog(@"insertdatain_tbl_selectitem_data error: %s", sqlite3_errmsg(_database)); } } } sqlite3_close(_database);
is better be:
if(sqlite3_step(stmt) == sqlite_done){ nslog(@"insert successful"); }else{ nslog(@"insertdatain_tbl_selectitem_data error: %s", sqlite3_errmsg(_database)); } } sqlite3_finalize(stmt); } sqlite3_close(_database);
the second...
you can try use sqlite3_open_v2
instead sqlite3_open
more here: http://www.sqlite.org/c3ref/open.html
so... instead:
if (sqlite3_open([sqlitedb utf8string], &(_database)) == sqlite_ok) {...}
will be: if (sqlite3_open_v2([sqlitedb utf8string], &(_database), sqlite_open_readwrite, null) == sqlite_ok) {....}
Comments
Post a Comment