On Mon, Oct 19, 2009 at 1:37 AM, Yayo <eduy...@gmail.com> wrote:
>
> The count(1) counts the appearances of the first column y all rows, it

That's not how I interpret the Sqlite documentation, which says that
"count(X)" returns "a count of the number of times that X is not NULL
in a group". Since "X" is a constant in your case, it should simply
return a count of the number of rows, which makes it equivalent to
count(*) in this case. Not sure if that's what you actually want
though, since you could have done that without a compound query.

> 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.

Which query are you referring to that works perfectly? You kinda have
two of them, since your doing a "select foo from (select bar)" type of
query. Did you try the entire compound query in the command line
sqlite3 command?
Also, what does cursor.getCount() return? If it returns 0, then
move(1) is expected to return false, since you have no rows in your
cursor. If it returns >0, then that might indicate a bug in
Cursor.move(). Try using moveToFirst() or moveToNext() instead.


> On Oct 18, 8:07 pm, Marco Nelissen <marc...@android.com> wrote:
>> On Sun, Oct 18, 2009 at 7:50 AM, Yayo <eduy...@gmail.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to