Saurabh Verma
Saurabh Verma

Reputation: 6718

SQLite select query with Integer Binding in Android

I'm trying to execute the following sqlite statement inside my android app:

String sql = "SELECT ID, lt, lg FROM Location WHERE ABS(lt-?) <= ? AND ABS(lg-?) <= ?";

I have tried using 'rawQuery' in the following sql statement:

String sql = "SELECT ID, lt, lg FROM Location WHERE ABS(lt-" + lt + ") <= " + ltGridLen  + " AND ABS(lg-" + lg + ") <= " + lgGridLen + " LIMIT 1";

which worked. However, I want to know whether there is any other more efficient way to do this.

Upvotes: 0

Views: 1038

Answers (1)

CL.
CL.

Reputation: 180010

rawQuery accepts parameters to bind, but only as an array of Strings. Comparing an integer against a string will not work correctly.

With integers, there are no problems with formatting or SQL injection, so you do not need to use parameters for them.

Upvotes: 2

Related Questions