android - SQLite: no such table: while compiling -
i've got long running task run onresume on activity. task involves querying database decrypting data, manually sorting updating sort order in database using transaction.
this works fine when run activities main ui thread, when execute same task within asynctask these errors:
- i/sqlitedatabasecpp(5166): sqlite returned: error code = 1, msg = no such table: household, db=/mnt/sdcard/mydatabase.db
- no such table: while compiling: no such table: household: , while compiling:
select distinct street household street not null , length(ltrim(rtrim(street)))>0
i know database exists , sql statement fine because runs fine outside asynctask. there access database within asynctask causes problems?
i'm getting errors on "select distinct" raw query below.
private boolean update_street_sort_order() { boolean returnvalue = false; dbutilities objdbutil = null; cursor ccases = null; final string sort_attribute = "street_sort_order"; final int street_index = 0; final int encrypted_street = 0; final int decrypted_street = 1; try { objdbutil = dbutilities.getinstance(this); if (objdbutil != null) { // list of cases arraylist<string[]> alstreet = new arraylist<string[]>(); sqlitedatabase sqlitedatabase = objdbutil.getdatabase(); if (sqlitedatabase != null && sqlitedatabase.isopen()) { ccases = sqlitedatabase.rawquery("select distinct street " + "from household " + "where street not null " + "and length(ltrim(rtrim(street)))>0", null); string _password = this.context.getpassword(); if (ccases != null && ccases.movetofirst()) { { // create list of en/decrypted streets alstreet.add(new string[] { ccases.getstring(street_index), crypto.decrypt(_password, ccases.getstring(street_index)) }); } while (ccases.movetonext()); } if (ccases != null) { ccases.close(); ccases = null; } int alstreet_length = alstreet.size(); if (alstreet_length > 0) { collections.sort(alstreet, new comparator<string[]>() { @override public int compare(string[] lhs, string[] rhs) { return lhs[decrypted_street] .comparetoignorecase(rhs[decrypted_street]); } }); // sort decrypted street using custom comparator stringbuilder sql_transaction = new stringbuilder( "begin transaction;" + "update household set " + sort_attribute + "=null;"); (int = 0; < alstreet_length; i++) { sql_transaction.append(string.format( "update household " + "set " + sort_attribute + "=%1$d " + "where street=\"%2$s\";", i, alstreet.get(i)[encrypted_street])); } sql_transaction.append("commit;"); // execute transaction sqlitedatabase.execsql(sql_transaction.tostring()); } returnvalue = true; } } } catch (exception e) { log.e(utilities.getfullmethodname(e), e.getmessage()); } { if (objdbutil != null) { // release resources objdbutil.close(); objdbutil = null; } } return returnvalue;
Comments
Post a Comment