0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.