SQLite .query() method, WHERE clause is only taking double quotes strings

前端 未结 6 594
执笔经年
执笔经年 2020-12-14 20:43

I have variable:

String owner=\"Mike\";
String[] columns ={\"quantity\", \"price\",\"owner\"}

My cursor is trying to get
Curso

相关标签:
6条回答
  • 2020-12-14 21:01

    the simplest way is to use SELECT col1,col2 FROM table_name WHERE col =' something' ; just like Leandros said , my problem was the single quotes , thnx

    0 讨论(0)
  • 2020-12-14 21:11

    SELECT quantity, price, owner, FROM sku_table WHERE owner='Mike' this is the correct SELECT. You forget the ' ' (single quotes)

    0 讨论(0)
  • 2020-12-14 21:12
    Cursor findEntry = db.query("sku_table", columns, "owner='"+owner+"'", null, null, null, null);
    
    0 讨论(0)
  • 2020-12-14 21:15
     public Cursor show_vol(String  vol,String bk,String hadnu)
               { 
                  SQLiteDatabase db = this.getReadableDatabase();
                  String[] columns ={"hadith"};//colums name that you select
    
                  Cursor res = db.query("volume2", columns, "hadithno=?", new String[] { hadnu }, null, null, null);
    
     //volume2 is table name  and hadithno is colume name  l
    //select hadith from volume2 where hadithno=hadnu  //working like s
    
     1. List item
    
                  return res;
               }
    
    0 讨论(0)
  • 2020-12-14 21:19

    Sorry, but that is exactly the reason why you should work with what the method offers! @Leandros and @Jake are helping in the totally wrong direction! Sorry to say that...

    The only solution you should use is this:

    Cursor findEntry = db.query("sku_table", columns, "owner=?", new String[] { owner }, null, null, null);
    

    ps: Yes I down voted both answers as they may work but providing a solution that shouldn't be used.

    Update:

    If you need more than one where condition, just add it like you would do in a normal query

    Cursor findEntry = db.query("sku_table", columns, "owner=? and price=?", new String[] { owner, price }, null, null, null);
    

    The order of the ? and the new String[] {...} elements must be the same!

    0 讨论(0)
  • 2020-12-14 21:26

    I know this is an old question, but you can also do it like this:

    Cursor findEntry = db.query("sku_table", columns, "owner=\'"+owner+"\'", null, null, null, null);

    I just did it in my app and it worked as expected.

    Jake's answer was similar, but probably wouldn't work without the \ before the '

    0 讨论(0)
提交回复
热议问题