tags:

views:

35

answers:

1

i have this code :

    private void insertValus() {
        ContentValues initialValues = new ContentValues();


          for (int i = 0 ; i < COUNTRIES.length ; i++){

              Character tmp = (Character)COUNTRIES[i].charAt(0);

              initialValues.put(VALUE, COUNTRIES[i]);
              initialValues.put(TYPE, "country");
              initialValues.put(LETTER,tmp.toString(tmp));

          db.insert(TABLE_NAME, null, initialValues);
          }
    }

public boolean existInDataBase(String userChoice) {
        boolean returnval = true;
        //gameList[0]

        Cursor cursor = db.query(TABLE_NAME, new String[] {VALUE}
        ,VALUE+" like " + "'%"+ userChoice +"%'", null, null, null, null);

        if (cursor != null)//i always enter here even if the string is no country
            returnval = false;

        return returnval;

and what ever i insert even if the query result should b false(meanning cursor == null)

and two more question

  1. how can i see the database that i have build in the emulator??

    2.should i run him outside my app and then to append it to my app or in first compiltion at user he will suffer a little overhead in the first time he use this app?

A: 

Well, first off, when you want to check if a query returned without results, rather than check if cursor == null, you want to have an if statement like

if(! doesMoveExist.moveToFirst())

At least that's how I'm doing it, and it seems to be working fine for me.

Additionally, for your emulator, the databases are stored inside the image file, not as separate files on your hard drive.

camperdave
it does work but aint this way is just walking around and not the real thing?
yoav.str
Technically, I think it is walking the tree, but basically, what this is doing is it says, go to the start of the tree. If there's no start to the tree, do something else.Seems to work well enough for me...
camperdave