How to set data type in raw SQLiteDatabase query binding?

The arguments in SQLiteDatabase raw query are bound as Strings , and this creates problems for me.

Request example (binding 50 ):

SELECT ? < 68 

returns: 0

  SELECT min(?, 68) 

returns: 68

Such results are due to the fact that 50 bound as a String, and the query looks like SELECT '50' < 68 ; which returns false .

A complex query created at runtime should use SQLiteDatabase.rawQuery .

How to connect data as a whole ?

I found one solution:

 SELECT CAST( ? AS INTEGER ) < 68 ; 

but looks ugly. Is there any other way? I can not find adequate methods in the Android API.

+4
source share
1 answer

I understand this is an old question now, but you should use compileStatement and then bindLong in the resulting SQLiteProgram class. This is a Google method that gives people reasonably smart ways to use SQL to speed up compilation of statements for better performance.

+2
source

Source: https://habr.com/ru/post/1379620/


All Articles