0

Android sqlite string parameter value not working. For example,

SELECT t0.id FROM Employer t0 
WHERE (select count(t1.id) from Employee t1 where t1.employerId=t0.id) > ?

The parameter(?) value is a Number. Android sqlite needs parameter values to be String.

rawQuery(sql, String[] arguments)

From sqlite3 console:

If passing the parameter value as string such as "1", the query will always return empty set.

SELECT t0.id FROM Employer t0 
WHERE (select count(t1.id) from Employee t1 where t1.employerId=t0.id) > '1'

If It is a number such as 1:

SELECT t0.id FROM Employer t0 
WHERE (select count(t1.id) from Employee t1 where t1.employerId=t0.id) > 1

Works.

how to pass the number as a parameter value for the example above?

eastwater
  • 4,624
  • 9
  • 49
  • 118
  • Look at this [answer](https://stackoverflow.com/a/11320788/1797950) that may help you – crgarridos May 12 '18 at 20:12
  • Thanks. Unfortunately compiled statement is not for query(select). – eastwater May 12 '18 at 20:41
  • Build your raw query with your parameters set and pass null for arguments. You can use String.format() to build your query. – Luis May 12 '18 at 21:00
  • This is just a simple example. Same issues will go with other object types. Android sqlite really need to allow object type as parameter values like JDBC. – eastwater May 12 '18 at 22:20

0 Answers0