Pradeep P Bomble
Pradeep P Bomble

Reputation: 19

What is wrong with this SQLite query?

c=MyDB.rawQuery("SELECT Distance FROM " +
            Table1 + "WHERE Source = '" + source + "' AND Distance = " +
                distance + " ' ", null);

distance = c.getFloat(c.getColumnIndex("Distance"));

Upvotes: 0

Views: 208

Answers (2)

Sijmen Mulder
Sijmen Mulder

Reputation: 5819

You're missing an apostrophe before the distance value, and a space after the table name.

However, this way of constructing queries makes you prone to SQL injection attacks. Instead, use proper parameters. How to do this will be documented in the library you are using.

Upvotes: 0

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43088

c=MyDB.rawQuery("SELECT Distance FROM " + Table1 + " WHERE Source = '" + source + "' AND Distance = '" + distance + " ' ", null);

Pay attention to the space before WHERE keyword and " ' " after Distance = . Also, better to use not rawQuery, but query method, as it use prepared statement, which is more safe.

Upvotes: 2

Related Questions