sqlite - Strange order when retrieves data from android database -


i trying data database using sqldatabase.query method:

public cursor getlist() {     dataprovider.dbhelper mdbhelper = dataprovider.getdbhelper();     sqlitedatabase db = mdbhelper.getwritabledatabase();     return db.query(shotstable.table_name,                      new string[]{shotstable.json},                      null,                      null,                      null,                      null,                      shotstable.views + " desc"); }   private list<shots> getallfromdb() {     gson gson = new gson();     cursor cursor = new shotsdatahelper().getlist();     list<shots> data = new arraylist<>();     if (cursor.movetofirst()) {         {             data.add(gson.fromjson(cursor.getstring(cursor.getcolumnindex(shotsdatahelper.shotstable.json)),             shots.class);         } while (cursor.movetonext());     }     cursor.close();     return data; }   public void insert(shots shots) {     contentvalues contentvalues = new contentvalues();     contentvalues.put(shotstable.id, shots.getid());     contentvalues.put(shotstable.views, integer.valueof(shots.getviews_count()));     contentvalues.put(shotstable.comments, integer.valueof(shots.getcomments_count()));     contentvalues.put(shotstable.likes, integer.valueof(shots.getlikes_count()));     contentvalues.put(shotstable.json, shots.getjson());     insert(contentvalues);      // insert database using getcontentresolver().insert(getcontenturi(), contentvalues); } 

and table:

sqlitetable table = new sqlitetable(table_name)                     .addcolumn(id, column.datatype.text)                     .addcolumn(views, column.datatype.integer)                     .addcolumn(comments, column.datatype.integer)                     .addcolumn(likes, column.datatype.integer)                     .addcolumn(json, column.datatype.text); 

however, when application loads data database, retrieved data successfully, order here strange(ordered views think), , list looks this(views listed below, returned method getallfromdb() above):

976

958

956

927

925

903

2115

1978

1936

1589

1574

1487

1363

1298

1265

1210

1130

1106

1104

1081

and cursor in getlist() contains mquery: "sqlitequery: select json shots order views desc"

i wonder whether wrong operation database, desc order of data here strange, datas views_count smaller 1000, have desc order , datas views_count greater 1000, have desc order too.

you should post little more, query return output. output paste suit data order id in case string (i don't recommend (long more suitable type, if know doing ok)).

so displayed numbers alphabetically sorted; order work correctly. because asci value of '1' lover value of '9' number 19999 appeare before number 9.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -