lorless
lorless

Reputation: 4478

Selecting specific values in SQLite in Android using the WHERE clause

im trying to get the row id where the title equals the string i pass in.

Im pretty shakey on the syntax and i've been surfing around this site trying to find an example Eclipse will like. Usually it tells me that the arguments im providing are not valid but i cant seem to make sense of it. I've tried adding nulls to fill the other arguments like groupBy but it keeps telling me the arguments are wrong.

Heres my code

private String[] folderID = {MySQLiteHelper.COLUMN_FOLDERID};
private String[] folderTitle = {MySQLiteHelper.COLUMN_FOLDERNAME};


public Cursor findFolderId(String i){
String[] select = {i + "=" + folderTitle};
Cursor cursor = database.query(MySQLiteHelper.TABLE_FOLDERS, folderID, "WHERE", select);
return cursor;

EDIT:

Here is the typical error

The method query(String, String[], String, String[], String, String, String) in the type SQLiteDatabase is not applicable for the arguments (String, String[], String, String[])

Upvotes: 0

Views: 1661

Answers (2)

Simon Dorociak
Simon Dorociak

Reputation: 33495

You need change yours to:

String[] columns = {"Column1", "Column2"}; // columns to select
String selection = "someCol = ?";
String[] args = {i}; // value added into where clause --> column = i
Cursor c = database.query(TABLE, columns, selection, args, null, null, null);

Generally columns are columns you want to fetch, selection is equivalent to where clause, args are values which will be replaced instead of ?(this is called as placeholder) in same order.

Upvotes: 1

Sean
Sean

Reputation: 5256

public Cursor findFolderId(String i){
String[] select = {i};
Cursor cursor = database.query(MySQLiteHelper.TABLE_FOLDERS, folderID, folderTitle + "=?", select);
return cursor;

Upvotes: 0

Related Questions