petdance / bobby-tables

bobby-tables.com, the site for preventing SQL injections
http://bobby-tables.com/
245 stars 85 forks source link

Android examples #61

Open 4a-j opened 8 years ago

4a-j commented 8 years ago

I don't know whether you'd want to list it under "Java" or "Android" -- I note that you have both "C#" and ".NET" -- but the platform provides its own database API.

The object you're running queries against can be either a ContentResolver:

Cursor result = contentResolver.query(uri, projection, selection, args, orderBy);

or an SQLiteDatabase object:

Cursor result = database.query(table, projection, selection, args, groupBy, having, orderBy);

In either case, your selection string should contain question marks, which are bound to the args array from left to right, as in this example:

static final String my_table = "users"; static final String[] my_projection = new String[] { "username", "last_login" }; String checkdate = "2015-11-01"; Cursor result = object.query(my_table, my_projection, "date(last_login) < date(?)", new String[] { checkdate }, null, null, null);

petdance commented 8 years ago

Excellent, thank you.