I have a SQLite database in my Android app. I be able to select random lines based on the YEAR column in the database Want to I'm already able to select a random line from the entire table:
  public string [] getTEST3RandChVERScrip () {cursor cursor = this.db.query ("order (randomly ordered) 1 LIMIT ", new string [] {KEY_MAKE, KEY_MODEL, KEY_NOTE}, empty, blank, empty, empty, empty); If (cursor! = Null) {for (cursor.movatofst (); cursor.isApplelast ();) {string colstrings [] = new string [3]; Colstrings [0] = cursor.getstring (0); Colstrings [1] = cursor.gate string (1); Colstrings [2] = cursor.gate string (2); Return colStrings; }} Return tap; }    But when I try and add a selection argument, app errors are here where I've added the selection argument:  
  Public string [] getTEST3RandChVERScrip () {cursor cursor = this.db.query ("probate order by Random)" (LIMIT 1 "), new string [] {KEY_MAKE, KEY_MODEL, KEY_NOTE}, KEY_YEAR =" 1964 ", blank , Empty, null, empty); If (cursor! = Null) {for (cursor.movatofst (); cursor.isApplelast ();) {string colstrings [] = new string [3]; Colstrings [0] = cursor.getstring (0); Colstrings [1] = cursor.gate string (1); Colstrings [2] = cursor.gate string (2); Return colStrings; }} Return tap; }    Is the syntax  wrong in "KEY_YEAR =" 1964 "? If there is any idea what this should be?   According to Tanjaz, I have modified this question:  
  cursor cursor = this.db.query ("provabel order random () LIMIT 1", New string [] {KEY_MAKE, KEY_MODEL, KEY_NOTE}, KEY_YEAR + "=?", New string [] {"1964"}, blank, empty, empty);    ... and I'm still getting an error which says:  06-20 15: 18: 33.644: E / Androordantum (4758): android.database. Sqlite SQLiteException: near "WHERE": Syntax Error:, while compiling: Select, Model, Random Note by order sorted by () range 1 where year =?     
  You should not place an order in the table name area  
 < Code> this.db.query ("provtable", new string [] {KEY_MAKE, KEY_MODEL, KEY_NOTE}, KEY_YEAR + "=?", New string [] {"1964"}, empty, blank, "random ( ) LIMIT 1 ");    
 
No comments:
Post a Comment