[android-developers] Re: SQLite functions - how to use them?

2009-04-01 Thread Mark Murphy

sirius wrote:
> Hi,
> I read in the documentation for SQLite that there should be some core
> functions and aggregate functions available, but I can't seem to use
> them in my code.. Can anyone help?
> 
> Here's the documentation i read:
>  http://www.sqlite.org/lang_aggfunc.html
>  http://www.sqlite.org/lang_corefunc.html

Those are functions available to SQL statements executed by SQLite.

> There is for example the function count() but how do I use it?

For example:

SELECT count(*) FROM sometable WHERE column1='somevalue';

The above SQL statement will return a count of the number of rows in
sometable that have a value of 'somevalue' for column1.

> I have tried to use it as stated below, but none of the functions in
> the documentation is available that way (i.e when I type "db." the
> list that shows in Eclipse documentation doesn't include any of the
> functions from the SQLite doc except from execSQL):

SQL is not Java. You can execute SQL statements against SQLite via the
Java rawQuery() method available on SQLiteDatabase.

You are attempting to call SQLite functions as if they were methods on
the SQLiteDatabase object, which generally will not work.

> PS. I haven't worked with databases before, so please keep that in
> mind when you answer me. DS.

I would recommend you learn SQL outside of Android at the outset. If you
specifically want to focus on SQLite, _The Definitive Guide to SQLite_
(Apress) is a good book.

Once you are comfortable with the notion of executing queries to get
results back, possibly including the functions you linked to, then it
will be easier for you to see how to access databases from inside Android.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, $35/Year

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



[android-developers] Re: SQLite functions - how to use them?

2009-04-01 Thread ndefo arnauld
see the documentation on this link.It cans help you
http://www.devx.com/wireless/Article/40842/0/page/1

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



[android-developers] Re: SQLite functions - how to use them?

2009-04-01 Thread nEx.Software

I have found that, if you will be doing a lot of data access, compiled
statements will cut the time to complete most operations in half. This
is particularly true of inserts. Used in conjunction with
beginTransaction()/endTransaction(), using compiled statements can
make your data access quite swift. In addition to being faster, I find
it easier to construct compiled statements as I can just use plain SQL
syntax. Of course, getting familiar with the functions themselves is
an important first step.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: SQLite functions - how to use them?

2009-04-01 Thread Glen Humphrey

I've used this and it works for me.

c.getCount();

On Apr 1, 12:34 pm, "nEx.Software"  wrote:
> I have found that, if you will be doing a lot of data access, compiled
> statements will cut the time to complete most operations in half. This
> is particularly true of inserts. Used in conjunction with
> beginTransaction()/endTransaction(), using compiled statements can
> make your data access quite swift. In addition to being faster, I find
> it easier to construct compiled statements as I can just use plain SQL
> syntax. Of course, getting familiar with the functions themselves is
> an important first step.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: SQLite functions - how to use them?

2009-04-01 Thread Marco Nelissen

While that works, it will create a Cursor with 'N' rows and then
counts the number of rows. If you instead retrieved "count(*)" as a
column, you'd have a Cursor with 1 row, with a field that contains the
count. The latter is more efficient.


On Wed, Apr 1, 2009 at 5:03 PM, Glen Humphrey
 wrote:
>
> I've used this and it works for me.
>
> c.getCount();
>
> On Apr 1, 12:34 pm, "nEx.Software"  wrote:
>> I have found that, if you will be doing a lot of data access, compiled
>> statements will cut the time to complete most operations in half. This
>> is particularly true of inserts. Used in conjunction with
>> beginTransaction()/endTransaction(), using compiled statements can
>> make your data access quite swift. In addition to being faster, I find
>> it easier to construct compiled statements as I can just use plain SQL
>> syntax. Of course, getting familiar with the functions themselves is
>> an important first step.
> >
>

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



[android-developers] Re: SQLite functions - how to use them?

2009-04-03 Thread sirius

Thanks all of you! That was really helpful!

Took me some time though to find out how to run the SQL statements
from inside of Java, but this is how I did it:

SQLiteStatement r = db.compileStatement("SELECT count(*) FROM " +
TABLE_NAME);
long result = r.simpleQueryForLong();
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---