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?

4
  • Look at this answer that may help you Commented May 12, 2018 at 20:12
  • Thanks. Unfortunately compiled statement is not for query(select). Commented May 12, 2018 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. Commented May 12, 2018 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. Commented May 12, 2018 at 22:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.