The count(1) counts the appearances of the first column y all rows, it
may be slower depending on the DB implementation (I think using Oracle
the * may be faster). Wether if I use * or 1 there doesn't mind. That
query works perfectly and returns the correct number of words. The
second one is the one that's pissing me off.

On Oct 18, 8:07 pm, Marco Nelissen <[email protected]> wrote:
> On Sun, Oct 18, 2009 at 7:50 AM, Yayo <[email protected]> wrote:
>
> > Hi all,
>
> > I've got this piece of code where I count words in a dictionary and
> > then I try to query them:
>
> >                String params[] = { Integer.toString(minlength),
> >                                Integer.toString(maxlength) };
> >                SQLiteStatement statement = database
> >                                .compileStatement("select count (1) from (" 
> > + SELECT_BY_LENGTH
>
> Don't you want "count(*)" there?
>
>
>
> >                                                + ")");
> >                statement.bindLong(1, minlength);
> >                statement.bindLong(2, maxlength);
> >                // statement.execute();
> >                int count = (int) statement.simpleQueryForLong();
> >                statement.close();
> >                Cursor cursor;
> >                cursor = database.rawQuery(SELECT_BY_LENGTH, params);
> >                if (cursor.move(1)) {
>
> > The SELECT_BY_LENGTH is defined this way:
> >        private static final String SELECT_BY_LENGTH = "select word._id,
> > word.word from word where length(word.word) between ? and ? ";
>
> > And the count works perfectly but the cursor.move(1) always returns
> > false. I've tried to get the column count and responds with the
> > correct count and the column names map too. I mean that the method
> > getColumnIndex works too but I can't get any data from the cursor. All
> > such methods fail. Am I doin' something wrong??
>
> If move(1) fails that means you were on the last row already, or in
> this case that no rows were retrieved. I expect Cursor.getCount() will
> return 0.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to