0

I use SQLdelight to create sql code,Like

SELECT * FROM CoachService WHERE shop_id in (?) and brand_id = ?

and I query Like:

briteDatabase.createQuery(CoachService.TABLE_NAME, CoachService.GETBYBRANDIDANDSHOPS,  "'1','5','11'","2");

but result is empty. Then,I change sqlcode like

SELECT * FROM CoachService WHERE shop_id in ('1','5','11') and brand_id = ?

it returns me 3 result. Why?

paperhs
  • 194
  • 2
  • 6

1 Answers1

0

when you pass in a query parameter it gets turned into a string by the android bindings. So when you pass in "'1','5','11'","2" it shows up in the query as

SELECT * FROM CoachService WHERE shop_id in (''1','5','11'') and brand_id = ?

or something like this, where '1','5','11' is actually one whole string.

Anstrong
  • 734
  • 3
  • 7
  • I know what's wrong,but how can I pass parameter ? the shop_id maybe is '1','11' or '1','2','3','4', Thank u anyway! – paperhs Oct 13 '16 at 06:25
  • you need to have the right number of parameters in your sqlite text. `SELECT * FROM CoachService WHERE shop_id in (?, ?, ?) and brand_id = ?` will work with `briteDatabase.createQuery(CoachService.TABLE_NAME, CoachService.GETBYBRANDIDANDSHOPS, "1","5","11","2");` variable amounts of bind parameters is not possible. You'll have to create the query manually in code and add the number of parameters you need. – Anstrong Oct 13 '16 at 12:51