Jani Bela
Jani Bela

Reputation: 1670

Android SQL database can't find the correct row

Hy guys, I am new to android but very enthusiastic to create my first app :) So probably this will be not my last question about databases :)

I created a Database with a tutorial, I can add item to it, delete etc. I would like to find items in it and takes the results to a cretad listview. So far:

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, todoItems));
          ListView lv = getListView();
          lv.setTextFilterEnabled(true);

        hornot info = new hornot(this);
        info.open();


        Cursor c = info.getSearched("108");

        if (c.moveToFirst())
        {
        do{
                    todoItems.add(c.getString(0) + " " + c.getString(1) + " " + c.getString(2));
            }while (c.moveToNext());
        }
            if (todoItems.size() > 0)
            {
        lv.setAdapter(new ArrayAdapter<String>(sqlsearch.this,android.R.layout.simple_list_item_1, todoItems));
            }



            info.close(); 

        }

In my database the getSearched() function looks like this:

public Cursor getSearched(String qq) {
        String[] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS};
            return ourDatabase.query(DATABASE_TABLE, columns, qq , null, null, null, null);


    }

As you see, I would like to select the row that contains qq in it. But I want to select the rows where the KEY_ROWID equals 108. At the moment I get the full table into a listview not only the wanted rows. What is wrong with this code?

Thanks in advance

Upvotes: 1

Views: 242

Answers (1)

user
user

Reputation: 87064

I don't know if i understood what you want but if you want to get the record with the KEY_ROWID 108, use the third parameter of the query method(that is the WHERE selection clause of the query):

public Cursor getSearched(String qq) {
        String[] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS};
            return ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + " = " + qq , null, null, null, null);
}

Upvotes: 1

Related Questions