Re: [android-developers] Re: Database insertion timings

2010-04-14 Thread Alok Kulkarni
@Walter, i tried that out. Instead of sb.toString() , i put the insert
statement string over there with Compile statement format..
Its taking *27* *seconds *!!
The database schema is as follows
Table *Artist*
id Integer Primary Key
name nvarchar(200)

Table *Album*
name nvarchar(200)
label nvarchar(200)
multiple_artists integer
artist_id integer
id integer Primary Key

Table *Songs*
artist_id integer
album_id integer
id integer Primary Key
name nvarchar(200)


On Mon, Apr 12, 2010 at 9:26 PM, Dave Johnston john...@gmail.com wrote:

 On Apr 12, 7:50 am, Alok Kulkarni kulsu...@gmail.com wrote:
  Hi,
  I am inserting around 7000 to 8000 records in my database having 4 tables
  each having 3 to 4 columns.Its taking me around 22 seconds to do the
  insertion which is i think is too long.

 Can you post the schema of the database you're inserting into?

 -d

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 To unsubscribe, reply using remove me as the subject.


-- 
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: Database insertion timings

2010-04-14 Thread Walter
Could you post your code here. compileStatement is usually for batch
reusable SQL statement, It's kind of best practice to use this in this
case. no reason that it's slower than normal SQL.


On Apr 14, 1:17 am, Alok Kulkarni kulsu...@gmail.com wrote:
 @Walter, i tried that out. Instead of sb.toString() , it the insert
 statement string over there with Compile statement format..
 Its taking *27* *seconds *!!
 The database schema is as follows
 Table *Artist*
 id Integer Primary Key
 name nvarchar(200)

 Table *Album*
 name nvarchar(200)
 label nvarchar(200)
 multiple_artists integer
 artist_id integer
 id integer Primary Key

 Table *Songs*
 artist_id integer
 album_id integer
 id integer Primary Key
 name nvarchar(200)



 On Mon, Apr 12, 2010 at 9:26 PM, Dave Johnston john...@gmail.com wrote:
  On Apr 12, 7:50 am, Alok Kulkarni kulsu...@gmail.com wrote:
   Hi,
   I am inserting around 7000 to 8000 records in my database having 4 tables
   each having 3 to 4 columns.Its taking me around 22 seconds to do the
   insertion which is i think is too long.

  Can you post the schema of the database you're inserting into?

  -d

  --
  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.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

  To unsubscribe, reply using remove me as the subject.

-- 
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: Database insertion timings

2010-04-13 Thread Bob Kerns
It is often better to insert all the data and THEN create the indexes.
I couldn't tell you about Sqlite.

You may want to create the primary index, but create all the other
indexes later.

On Apr 12, 5:33 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
 No, database writing is extremely slow especially with many indecies.

 In my app, I am getting maybe 10 insers a seconds into a table with 20
 columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
 try optimizing the writes too much, not sure if it's even possible.

 On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:



  Ok, you are right if the pre and the iphone are 10x faster, it can't
  be right.

  I don't see anything wrong in your code, so only two things come to
  mind :

  - Instead of using ContentValues, try to create an insert sql
  statement and send it to via SQLiteDatabase.execSQL to see if there is
  any improvement
  - Maybe it's not the database writing that is slow but the reading
  from wherever your getting the data ?

  Yahel

  On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:

   Ok,
   @Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) 
   ,
   its taking 3 seconds..
   On an IPhone , its taking 1 or  2 seconds..
   Here is an example of what i am doing..
   private Boolean addAlbumDB(int AlbumId, String Name, String Label,
               int MultipleArtists, int ArtistId) {
           long result = -1;

           try {

               ContentValues initialValues = new ContentValues();
               initialValues.put(KEY_ID, AlbumId);
               initialValues.put(KEY_NAME, Name);
               initialValues.put(KEY_LABEL, Label);
               initialValues.put(KEY_ARTIST_ID, ArtistId);
               initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

                result = db.insert(DATABASE_TABLE, null, initialValues);

           } catch (Exception e) {
               Log.i(Exception in addAlbumDB,  + e.toString());
               return false;
           }

           if (result == -1)
               return false;
           return true;
       }

   The above function is called for around 2000 times..
   Similarly there are 2 3 more functions for other tables.
   Thanks,
   Alok.

   On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
   mike.rue...@gmail.comwrote:

On 4/12/2010 10:59 AM, Yahel wrote:

Hi Alok,

Posting some logic, or some sql would help us see if you are missing
something :)

(excessive) use of indices comes to mind :-)

Michael

Yahel

On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

Hi,
I am inserting around 7000 to 8000 records in my database having 4 
tables
each having 3 to 4 columns.Its taking me around 22 seconds to do the
insertion which is i think is too long. I am using transaction while
doing
this without which its taking around 55 seconds.
According to SQLite documentation , inserting 1 records in a 
database
takes time  around 2 to 3 seconds.
Am i missing something , or is the behaviour correct?
Thanks,
Alok

--
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.comandroid-developers%2Bunsubs
 cr...@googlegroups.com
For more options, visit this group at
   http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using remove me as the subject.- Hide quoted 
text -

  - Show quoted text -

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


Re: [android-developers] Re: Database insertion timings

2010-04-13 Thread Alok Kulkarni
I do not have any indices for my tables at all.
Each of the tables Artist, Albumn and Songs has 4,5,5 columns respectively.
Using Raw query as Yahel said improves the speed to some extent . Inserting
7000 records takes 18 seconds instead of 22 but thats not much as in total ,
i am going to insert 3 to 4 entries , which will take hell lot of
time..
Using raw queries is not much helpful as the data itself might contain
quotes and double quotes.
Thanks ,
Alok.

On Tue, Apr 13, 2010 at 11:32 AM, Bob Kerns r...@acm.org wrote:

 It is often better to insert all the data and THEN create the indexes.
 I couldn't tell you about Sqlite.

 You may want to create the primary index, but create all the other
 indexes later.

 On Apr 12, 5:33 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
  No, database writing is extremely slow especially with many indecies.
 
  In my app, I am getting maybe 10 insers a seconds into a table with 20
  columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
  try optimizing the writes too much, not sure if it's even possible.
 
  On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:
 
 
 
   Ok, you are right if the pre and the iphone are 10x faster, it can't
   be right.
 
   I don't see anything wrong in your code, so only two things come to
   mind :
 
   - Instead of using ContentValues, try to create an insert sql
   statement and send it to via SQLiteDatabase.execSQL to see if there is
   any improvement
   - Maybe it's not the database writing that is slow but the reading
   from wherever your getting the data ?
 
   Yahel
 
   On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:
 
Ok,
@Yahel:- For the insertion of same records on a Palm device(Say Palm
 Pre) ,
its taking 3 seconds..
On an IPhone , its taking 1 or  2 seconds..
Here is an example of what i am doing..
private Boolean addAlbumDB(int AlbumId, String Name, String Label,
int MultipleArtists, int ArtistId) {
long result = -1;
 
try {
 
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID, AlbumId);
initialValues.put(KEY_NAME, Name);
initialValues.put(KEY_LABEL, Label);
initialValues.put(KEY_ARTIST_ID, ArtistId);
initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);
 
 result = db.insert(DATABASE_TABLE, null, initialValues);
 
} catch (Exception e) {
Log.i(Exception in addAlbumDB,  + e.toString());
return false;
}
 
if (result == -1)
return false;
return true;
}
 
The above function is called for around 2000 times..
Similarly there are 2 3 more functions for other tables.
Thanks,
Alok.
 
On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
 mike.rue...@gmail.comwrote:
 
 On 4/12/2010 10:59 AM, Yahel wrote:
 
 Hi Alok,
 
 Posting some logic, or some sql would help us see if you are
 missing
 something :)
 
 (excessive) use of indices comes to mind :-)
 
 Michael
 
 Yahel
 
 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
 Hi,
 I am inserting around 7000 to 8000 records in my database having
 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do
 the
 insertion which is i think is too long. I am using transaction
 while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a
 database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok
 
 --
 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.comandroid-developers%2bunsubscr...@googlegroups.comandroid-developers%2Bunsubs
 cr...@googlegroups.com
 For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
 
 To unsubscribe, reply using remove me as the subject.- Hide
 quoted text -
 
   - Show quoted text -

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


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

Re: [android-developers] Re: Database insertion timings

2010-04-13 Thread Alok Kulkarni
@mobDev, Ending transaction

On Tue, Apr 13, 2010 at 12:59 PM, Alok Kulkarni kulsu...@gmail.com wrote:

 I do not have any indices for my tables at all.
 Each of the tables Artist, Albumn and Songs has 4,5,5 columns respectively.
 Using Raw query as Yahel said improves the speed to some extent . Inserting
 7000 records takes 18 seconds instead of 22 but thats not much as in total ,
 i am going to insert 3 to 4 entries , which will take hell lot of
 time..
 Using raw queries is not much helpful as the data itself might contain
 quotes and double quotes.
 Thanks ,
 Alok.


 On Tue, Apr 13, 2010 at 11:32 AM, Bob Kerns r...@acm.org wrote:

 It is often better to insert all the data and THEN create the indexes.
 I couldn't tell you about Sqlite.

 You may want to create the primary index, but create all the other
 indexes later.

 On Apr 12, 5:33 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
  No, database writing is extremely slow especially with many indecies.
 
  In my app, I am getting maybe 10 insers a seconds into a table with 20
  columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
  try optimizing the writes too much, not sure if it's even possible.
 
  On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:
 
 
 
   Ok, you are right if the pre and the iphone are 10x faster, it can't
   be right.
 
   I don't see anything wrong in your code, so only two things come to
   mind :
 
   - Instead of using ContentValues, try to create an insert sql
   statement and send it to via SQLiteDatabase.execSQL to see if there is
   any improvement
   - Maybe it's not the database writing that is slow but the reading
   from wherever your getting the data ?
 
   Yahel
 
   On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:
 
Ok,
@Yahel:- For the insertion of same records on a Palm device(Say Palm
 Pre) ,
its taking 3 seconds..
On an IPhone , its taking 1 or  2 seconds..
Here is an example of what i am doing..
private Boolean addAlbumDB(int AlbumId, String Name, String Label,
int MultipleArtists, int ArtistId) {
long result = -1;
 
try {
 
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID, AlbumId);
initialValues.put(KEY_NAME, Name);
initialValues.put(KEY_LABEL, Label);
initialValues.put(KEY_ARTIST_ID, ArtistId);
initialValues.put(KEY_MULTIPLE_ARTISTS,
 MultipleArtists);
 
 result = db.insert(DATABASE_TABLE, null,
 initialValues);
 
} catch (Exception e) {
Log.i(Exception in addAlbumDB,  + e.toString());
return false;
}
 
if (result == -1)
return false;
return true;
}
 
The above function is called for around 2000 times..
Similarly there are 2 3 more functions for other tables.
Thanks,
Alok.
 
On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
 mike.rue...@gmail.comwrote:
 
 On 4/12/2010 10:59 AM, Yahel wrote:
 
 Hi Alok,
 
 Posting some logic, or some sql would help us see if you are
 missing
 something :)
 
 (excessive) use of indices comes to mind :-)
 
 Michael
 
 Yahel
 
 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
 Hi,
 I am inserting around 7000 to 8000 records in my database having
 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do
 the
 insertion which is i think is too long. I am using transaction
 while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a
 database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok
 
 --
 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.comandroid-developers%2bunsubscr...@googlegroups.comandroid-developers%2Bunsubs
 cr...@googlegroups.com
 For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
 
 To unsubscribe, reply using remove me as the subject.- Hide
 quoted text -
 
   - Show quoted text -

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
You received this message because you are subscribed to the Google
Groups Android 

Re: [android-developers] Re: Database insertion timings

2010-04-13 Thread Alok Kulkarni
@mobDev, I have followed some links , example
http://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Android-Cursors/3/
where they were doing setTransactionSuccessful before ending transaction.
Removing that statement does not have an effect.
Even if i do say
String tempName = Artist;
String tempVal = Enrique;
int tempId = 0;
for(i = 0;i 7000;i++)
{
tempId++;
addArtistDB(tempID,tempName,tempVal1);
}
It takes 20 seconds .So there is not much time required for accessing the
data i want to put into database. The actual insertion itself is taking so
much time.
As Sqlite is native to Android , i assume it must be fast enough.
One more thing , Same amount of insertions on a Windows Mobile Device ,
using a Third Party SQLite DLL , its taking 5 to 6 seconds..
Its not that i am blaming android , but i am getting frustrated now :( :(

Thanks ,
Alok.
On Tue, Apr 13, 2010 at 1:07 PM, Alok Kulkarni kulsu...@gmail.com wrote:

 @mobDev, Ending transaction

 On Tue, Apr 13, 2010 at 12:59 PM, Alok Kulkarni kulsu...@gmail.comwrote:

 I do not have any indices for my tables at all.
 Each of the tables Artist, Albumn and Songs has 4,5,5 columns
 respectively.
 Using Raw query as Yahel said improves the speed to some extent .
 Inserting 7000 records takes 18 seconds instead of 22 but thats not much as
 in total , i am going to insert 3 to 4 entries , which will take
 hell lot of time..
 Using raw queries is not much helpful as the data itself might contain
 quotes and double quotes.
 Thanks ,
 Alok.


 On Tue, Apr 13, 2010 at 11:32 AM, Bob Kerns r...@acm.org wrote:

 It is often better to insert all the data and THEN create the indexes.
 I couldn't tell you about Sqlite.

 You may want to create the primary index, but create all the other
 indexes later.

 On Apr 12, 5:33 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
  No, database writing is extremely slow especially with many indecies.
 
  In my app, I am getting maybe 10 insers a seconds into a table with 20
  columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
  try optimizing the writes too much, not sure if it's even possible.
 
  On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:
 
 
 
   Ok, you are right if the pre and the iphone are 10x faster, it can't
   be right.
 
   I don't see anything wrong in your code, so only two things come to
   mind :
 
   - Instead of using ContentValues, try to create an insert sql
   statement and send it to via SQLiteDatabase.execSQL to see if there
 is
   any improvement
   - Maybe it's not the database writing that is slow but the reading
   from wherever your getting the data ?
 
   Yahel
 
   On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:
 
Ok,
@Yahel:- For the insertion of same records on a Palm device(Say
 Palm Pre) ,
its taking 3 seconds..
On an IPhone , its taking 1 or  2 seconds..
Here is an example of what i am doing..
private Boolean addAlbumDB(int AlbumId, String Name, String Label,
int MultipleArtists, int ArtistId) {
long result = -1;
 
try {
 
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID, AlbumId);
initialValues.put(KEY_NAME, Name);
initialValues.put(KEY_LABEL, Label);
initialValues.put(KEY_ARTIST_ID, ArtistId);
initialValues.put(KEY_MULTIPLE_ARTISTS,
 MultipleArtists);
 
 result = db.insert(DATABASE_TABLE, null,
 initialValues);
 
} catch (Exception e) {
Log.i(Exception in addAlbumDB,  + e.toString());
return false;
}
 
if (result == -1)
return false;
return true;
}
 
The above function is called for around 2000 times..
Similarly there are 2 3 more functions for other tables.
Thanks,
Alok.
 
On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
 mike.rue...@gmail.comwrote:
 
 On 4/12/2010 10:59 AM, Yahel wrote:
 
 Hi Alok,
 
 Posting some logic, or some sql would help us see if you are
 missing
 something :)
 
 (excessive) use of indices comes to mind :-)
 
 Michael
 
 Yahel
 
 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
 Hi,
 I am inserting around 7000 to 8000 records in my database
 having 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to
 do the
 insertion which is i think is too long. I am using transaction
 while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in
 a database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok
 
 --
 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] Re: Database insertion timings

2010-04-13 Thread Walter
Use SQLiteStatement.compileStatement, I do believe it should be faster
with my 10 years database programming  experience, though I didn't
test, Let  me know if you have a result.

Here is some code from my Remote RDP program for importing data to the
table:

SQLiteStatement sls = 
db.compileStatement(sb.toString());

while ((line = br.readLine()) != null) {
st.reset(line, delimiter);
for (int i = 0; i  columns; i++) {
String value = st.next();
if (value == null){
value   = ;
}
sls.bindString(i + 1, value);
}
sls.execute();
}



On Apr 13, 1:47 am, Alok Kulkarni kulsu...@gmail.com wrote:
 @mobDev, I have followed some links , 
 examplehttp://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Andro...
 where they were doing setTransactionSuccessful before ending transaction.
 Removing that statement does not have an effect.
 Even if i do say
 String tempName = Artist;
 String tempVal = Enrique;
 int tempId = 0;
 for(i = 0;i 7000;i++)
 {
 tempId++;
 addArtistDB(tempID,tempName,tempVal1);}

 It takes 20 seconds .So there is not much time required for accessing the
 data i want to put into database. The actual insertion itself is taking so
 much time.
 As Sqlite is native to Android , i assume it must be fast enough.
 One more thing , Same amount of insertions on a Windows Mobile Device ,
 using a Third Party SQLite DLL , its taking 5 to 6 seconds..
 Its not that i am blaming android , but i am getting frustrated now :( :(

 Thanks ,
 Alok.



 On Tue, Apr 13, 2010 at 1:07 PM, Alok Kulkarni kulsu...@gmail.com wrote:
  @mobDev, Ending transaction

  On Tue, Apr 13, 2010 at 12:59 PM, Alok Kulkarni kulsu...@gmail.comwrote:

  I do not have any indices for my tables at all.
  Each of the tables Artist, Albumn and Songs has 4,5,5 columns
  respectively.
  Using Raw query as Yahel said improves the speed to some extent .
  Inserting 7000 records takes 18 seconds instead of 22 but thats not much as
  in total , i am going to insert 3 to 4 entries , which will take
  hell lot of time..
  Using raw queries is not much helpful as the data itself might contain
  quotes and double quotes.
  Thanks ,
  Alok.

  On Tue, Apr 13, 2010 at 11:32 AM, Bob Kerns r...@acm.org wrote:

  It is often better to insert all the data and THEN create the indexes.
  I couldn't tell you about Sqlite.

  You may want to create the primary index, but create all the other
  indexes later.

  On Apr 12, 5:33 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
   No, database writing is extremely slow especially with many indecies.

   In my app, I am getting maybe 10 insers a seconds into a table with 20
   columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
   try optimizing the writes too much, not sure if it's even possible.

   On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:

Ok, you are right if the pre and the iphone are 10x faster, it can't
be right.

I don't see anything wrong in your code, so only two things come to
mind :

- Instead of using ContentValues, try to create an insert sql
statement and send it to via SQLiteDatabase.execSQL to see if there
  is
any improvement
- Maybe it's not the database writing that is slow but the reading
from wherever your getting the data ?

Yahel

On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:

 Ok,
 @Yahel:- For the insertion of same records on a Palm device(Say
  Palm Pre) ,
 its taking 3 seconds..
 On an IPhone , its taking 1 or  2 seconds..
 Here is an example of what i am doing..
 private Boolean addAlbumDB(int AlbumId, String Name, String Label,
             int MultipleArtists, int ArtistId) {
         long result = -1;

         try {

             ContentValues initialValues = new ContentValues();
             initialValues.put(KEY_ID, AlbumId);
             initialValues.put(KEY_NAME, Name);
             initialValues.put(KEY_LABEL, Label);
             initialValues.put(KEY_ARTIST_ID, ArtistId);
             initialValues.put(KEY_MULTIPLE_ARTISTS,
  MultipleArtists);

              result = db.insert(DATABASE_TABLE, null,
  initialValues);

         } catch (Exception e) {
             Log.i(Exception in addAlbumDB,  + e.toString());
             return false;
         }

         if (result == -1)
             return false;
         return true;
     }

 The above function is called for around 2000 times..
 Similarly there are 2 3 more functions for other tables.
 Thanks,
 Alok.

 On Mon, Apr 

[android-developers] Re: Database insertion timings

2010-04-13 Thread Dave Johnston
On Apr 12, 7:50 am, Alok Kulkarni kulsu...@gmail.com wrote:
 Hi,
 I am inserting around 7000 to 8000 records in my database having 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do the
 insertion which is i think is too long.

Can you post the schema of the database you're inserting into?

-d

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

To unsubscribe, reply using remove me as the subject.


[android-developers] Re: Database insertion timings

2010-04-12 Thread Yahel
Hi Alok,

Posting some logic, or some sql would help us see if you are missing
something :)

Yahel

On 12 avr, 08:50, Alok Kulkarni kulsu...@gmail.com wrote:
 Hi,
 I am inserting around 7000 to 8000 records in my database having 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do the
 insertion which is i think is too long. I am using transaction while doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok

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

To unsubscribe, reply using remove me as the subject.


[android-developers] Re: Database insertion timings

2010-04-12 Thread Yahel
 According to SQLite documentation , inserting 1 records in a database
 takes time  around 2 to 3 seconds.

Did you take into account that the sqlite documentation is probably
taking a standard PC (2GHz, 1GB of ram) as its default value not a
mobile device with a quarter of the resources ?

Yahel

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

To unsubscribe, reply using remove me as the subject.


Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Michael Rueger

On 4/12/2010 10:59 AM, Yahel wrote:

Hi Alok,

Posting some logic, or some sql would help us see if you are missing
something :)


(excessive) use of indices comes to mind :-)

Michael



Yahel

On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

Hi,
I am inserting around 7000 to 8000 records in my database having 4 tables
each having 3 to 4 columns.Its taking me around 22 seconds to do the
insertion which is i think is too long. I am using transaction while doing
this without which its taking around 55 seconds.
According to SQLite documentation , inserting 1 records in a database
takes time  around 2 to 3 seconds.
Am i missing something , or is the behaviour correct?
Thanks,
Alok




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

To unsubscribe, reply using remove me as the subject.


Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Alok Kulkarni
Ok,
@Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) ,
its taking 3 seconds..
On an IPhone , its taking 1 or  2 seconds..
Here is an example of what i am doing..
private Boolean addAlbumDB(int AlbumId, String Name, String Label,
int MultipleArtists, int ArtistId) {
long result = -1;

try {


ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID, AlbumId);
initialValues.put(KEY_NAME, Name);
initialValues.put(KEY_LABEL, Label);
initialValues.put(KEY_ARTIST_ID, ArtistId);
initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

 result = db.insert(DATABASE_TABLE, null, initialValues);


} catch (Exception e) {
Log.i(Exception in addAlbumDB,  + e.toString());
return false;
}

if (result == -1)
return false;
return true;
}

The above function is called for around 2000 times..
Similarly there are 2 3 more functions for other tables.
Thanks,
Alok.

On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger mike.rue...@gmail.comwrote:

 On 4/12/2010 10:59 AM, Yahel wrote:

 Hi Alok,

 Posting some logic, or some sql would help us see if you are missing
 something :)


 (excessive) use of indices comes to mind :-)

 Michael



 Yahel

 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

 Hi,
 I am inserting around 7000 to 8000 records in my database having 4 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do the
 insertion which is i think is too long. I am using transaction while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok



 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 To unsubscribe, reply using remove me as the subject.


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

Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Alok Kulkarni
I have started the transaction before the 1st insert , and ended it after
the last insert
Thanks,
Alok.

On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com wrote:

 Ok,
 @Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) ,
 its taking 3 seconds..
 On an IPhone , its taking 1 or  2 seconds..
 Here is an example of what i am doing..
 private Boolean addAlbumDB(int AlbumId, String Name, String Label,
 int MultipleArtists, int ArtistId) {
 long result = -1;

 try {


 ContentValues initialValues = new ContentValues();
 initialValues.put(KEY_ID, AlbumId);
 initialValues.put(KEY_NAME, Name);
 initialValues.put(KEY_LABEL, Label);
 initialValues.put(KEY_ARTIST_ID, ArtistId);
 initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

  result = db.insert(DATABASE_TABLE, null, initialValues);


 } catch (Exception e) {
 Log.i(Exception in addAlbumDB,  + e.toString());
 return false;
 }

 if (result == -1)
 return false;
 return true;
 }

 The above function is called for around 2000 times..
 Similarly there are 2 3 more functions for other tables.
 Thanks,
 Alok.


 On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger mike.rue...@gmail.comwrote:

 On 4/12/2010 10:59 AM, Yahel wrote:

 Hi Alok,

 Posting some logic, or some sql would help us see if you are missing
 something :)


 (excessive) use of indices comes to mind :-)

 Michael



 Yahel

 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

 Hi,
 I am inserting around 7000 to 8000 records in my database having 4
 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do the
 insertion which is i think is too long. I am using transaction while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a
 database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok



 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 To unsubscribe, reply using remove me as the subject.




-- 
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: Database insertion timings

2010-04-12 Thread MobDev
do you have some code specifically showing the sequence and the
syntax ?
AAfaik a transaction SHOULD make it faster accroding to this
documentation : 
http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transactions

On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
 I have started the transaction before the 1st insert , and ended it after
 the last insert
 Thanks,
 Alok.

 On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com wrote:
  Ok,
  @Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) ,
  its taking 3 seconds..
  On an IPhone , its taking 1 or  2 seconds..
  Here is an example of what i am doing..
  private Boolean addAlbumDB(int AlbumId, String Name, String Label,
              int MultipleArtists, int ArtistId) {
          long result = -1;

          try {

              ContentValues initialValues = new ContentValues();
              initialValues.put(KEY_ID, AlbumId);
              initialValues.put(KEY_NAME, Name);
              initialValues.put(KEY_LABEL, Label);
              initialValues.put(KEY_ARTIST_ID, ArtistId);
              initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

               result = db.insert(DATABASE_TABLE, null, initialValues);

          } catch (Exception e) {
              Log.i(Exception in addAlbumDB,  + e.toString());
              return false;
          }

          if (result == -1)
              return false;
          return true;
      }

  The above function is called for around 2000 times..
  Similarly there are 2 3 more functions for other tables.
  Thanks,
  Alok.

  On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
  mike.rue...@gmail.comwrote:

  On 4/12/2010 10:59 AM, Yahel wrote:

  Hi Alok,

  Posting some logic, or some sql would help us see if you are missing
  something :)

  (excessive) use of indices comes to mind :-)

  Michael

  Yahel

  On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

  Hi,
  I am inserting around 7000 to 8000 records in my database having 4
  tables
  each having 3 to 4 columns.Its taking me around 22 seconds to do the
  insertion which is i think is too long. I am using transaction while
  doing
  this without which its taking around 55 seconds.
  According to SQLite documentation , inserting 1 records in a
  database
  takes time  around 2 to 3 seconds.
  Am i missing something , or is the behaviour correct?
  Thanks,
  Alok

  --
  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.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

  To unsubscribe, reply using remove me as the subject.

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


Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Alok Kulkarni
This is a standard class DatabaseHelper extending SQLiteOpenHelper...


private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context, String databaseName) {
super(context, databaseName, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
// Nothing to do
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log
.w(Upgrade, Upgrading database from version 
+ oldVersion +  to  + newVersion
+ , which will destroy all old data);
db.execSQL(DROP TABLE IF EXISTS titles);
onCreate(db);
}
}

Then i have
private SQLiteDatabase db;
This db object is used to perform insert operations.
Thanks,
Alok.
// ---opens the database---

public void open() throws SQLException {
db = DBHelper.getWritableDatabase();
}

On Mon, Apr 12, 2010 at 6:20 PM, MobDev developm...@mobilaria.com wrote:

 do you have some code specifically showing the sequence and the
 syntax ?
 AAfaik a transaction SHOULD make it faster accroding to this
 documentation :
 http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transactionshttp://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#transactions

 On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
  I have started the transaction before the 1st insert , and ended it after
  the last insert
  Thanks,
  Alok.
 
  On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com
 wrote:
   Ok,
   @Yahel:- For the insertion of same records on a Palm device(Say Palm
 Pre) ,
   its taking 3 seconds..
   On an IPhone , its taking 1 or  2 seconds..
   Here is an example of what i am doing..
   private Boolean addAlbumDB(int AlbumId, String Name, String Label,
   int MultipleArtists, int ArtistId) {
   long result = -1;
 
   try {
 
   ContentValues initialValues = new ContentValues();
   initialValues.put(KEY_ID, AlbumId);
   initialValues.put(KEY_NAME, Name);
   initialValues.put(KEY_LABEL, Label);
   initialValues.put(KEY_ARTIST_ID, ArtistId);
   initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);
 
result = db.insert(DATABASE_TABLE, null, initialValues);
 
   } catch (Exception e) {
   Log.i(Exception in addAlbumDB,  + e.toString());
   return false;
   }
 
   if (result == -1)
   return false;
   return true;
   }
 
   The above function is called for around 2000 times..
   Similarly there are 2 3 more functions for other tables.
   Thanks,
   Alok.
 
   On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger mike.rue...@gmail.com
 wrote:
 
   On 4/12/2010 10:59 AM, Yahel wrote:
 
   Hi Alok,
 
   Posting some logic, or some sql would help us see if you are missing
   something :)
 
   (excessive) use of indices comes to mind :-)
 
   Michael
 
   Yahel
 
   On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
   Hi,
   I am inserting around 7000 to 8000 records in my database having 4
   tables
   each having 3 to 4 columns.Its taking me around 22 seconds to do the
   insertion which is i think is too long. I am using transaction while
   doing
   this without which its taking around 55 seconds.
   According to SQLite documentation , inserting 1 records in a
   database
   takes time  around 2 to 3 seconds.
   Am i missing something , or is the behaviour correct?
   Thanks,
   Alok
 
   --
   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.comandroid-developers%2bunsubscr...@googlegroups.com
 android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com
 
   For more options, visit this group at
  http://groups.google.com/group/android-developers?hl=en
 
   To unsubscribe, reply using remove me as the subject.

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


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

[android-developers] Re: Database insertion timings

2010-04-12 Thread MobDev
I don't see a specific transaction ???
Anyways transaction should only be used if you have multiple actions
you are doing on your database (like several insert/update
operations)...

On 12 apr, 15:43, Alok Kulkarni kulsu...@gmail.com wrote:
 This is a standard class DatabaseHelper extending SQLiteOpenHelper...

 private static class DatabaseHelper extends SQLiteOpenHelper {
         DatabaseHelper(Context context, String databaseName) {
             super(context, databaseName, null, DATABASE_VERSION);
         }

         @Override
         public void onCreate(SQLiteDatabase db) {
             // Nothing to do
         }

         @Override
         public void onUpgrade(SQLiteDatabase db, int oldVersion, int
 newVersion) {
             Log
                     .w(Upgrade, Upgrading database from version 
                             + oldVersion +  to  + newVersion
                             + , which will destroy all old data);
             db.execSQL(DROP TABLE IF EXISTS titles);
             onCreate(db);
         }
     }

 Then i have
 private SQLiteDatabase db;
 This db object is used to perform insert operations.
 Thanks,
 Alok.
     // ---opens the database---

     public void open() throws SQLException {
         db = DBHelper.getWritableDatabase();
     }

 On Mon, Apr 12, 2010 at 6:20 PM, MobDev developm...@mobilaria.com wrote:
  do you have some code specifically showing the sequence and the
  syntax ?
  AAfaik a transaction SHOULD make it faster accroding to this
  documentation :
 http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transa...http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#tran...

  On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
   I have started the transaction before the 1st insert , and ended it after
   the last insert
   Thanks,
   Alok.

   On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com
  wrote:
Ok,
@Yahel:- For the insertion of same records on a Palm device(Say Palm
  Pre) ,
its taking 3 seconds..
On an IPhone , its taking 1 or  2 seconds..
Here is an example of what i am doing..
private Boolean addAlbumDB(int AlbumId, String Name, String Label,
            int MultipleArtists, int ArtistId) {
        long result = -1;

        try {

            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_ID, AlbumId);
            initialValues.put(KEY_NAME, Name);
            initialValues.put(KEY_LABEL, Label);
            initialValues.put(KEY_ARTIST_ID, ArtistId);
            initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

             result = db.insert(DATABASE_TABLE, null, initialValues);

        } catch (Exception e) {
            Log.i(Exception in addAlbumDB,  + e.toString());
            return false;
        }

        if (result == -1)
            return false;
        return true;
    }

The above function is called for around 2000 times..
Similarly there are 2 3 more functions for other tables.
Thanks,
Alok.

On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger mike.rue...@gmail.com
  wrote:

On 4/12/2010 10:59 AM, Yahel wrote:

Hi Alok,

Posting some logic, or some sql would help us see if you are missing
something :)

(excessive) use of indices comes to mind :-)

Michael

Yahel

On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

Hi,
I am inserting around 7000 to 8000 records in my database having 4
tables
each having 3 to 4 columns.Its taking me around 22 seconds to do the
insertion which is i think is too long. I am using transaction while
doing
this without which its taking around 55 seconds.
According to SQLite documentation , inserting 1 records in a
database
takes time  around 2 to 3 seconds.
Am i missing something , or is the behaviour correct?
Thanks,
Alok

--
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.comandroid-developers%2bunsubscr...@googlegroups.com
  android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com

For more options, visit this group at
   http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using remove me as the subject.

  --
  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.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
 

Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Alok Kulkarni
Before the 1st insert call i am doing
db.beginTransaction();

for(i = 0 i 2000 ; i++)
   addAlbumDB();
for(i = 0 i 3000 ; i++)
   addArtistDB();
for(i = 0 i 2000 ; i++)
   addSongDB();
try {
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}


On Mon, Apr 12, 2010 at 7:18 PM, MobDev developm...@mobilaria.com wrote:

 I don't see a specific transaction ???
 Anyways transaction should only be used if you have multiple actions
 you are doing on your database (like several insert/update
 operations)...

 On 12 apr, 15:43, Alok Kulkarni kulsu...@gmail.com wrote:
  This is a standard class DatabaseHelper extending SQLiteOpenHelper...
 
  private static class DatabaseHelper extends SQLiteOpenHelper {
  DatabaseHelper(Context context, String databaseName) {
  super(context, databaseName, null, DATABASE_VERSION);
  }
 
  @Override
  public void onCreate(SQLiteDatabase db) {
  // Nothing to do
  }
 
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int
  newVersion) {
  Log
  .w(Upgrade, Upgrading database from version 
  + oldVersion +  to  + newVersion
  + , which will destroy all old data);
  db.execSQL(DROP TABLE IF EXISTS titles);
  onCreate(db);
  }
  }
 
  Then i have
  private SQLiteDatabase db;
  This db object is used to perform insert operations.
  Thanks,
  Alok.
  // ---opens the database---
 
  public void open() throws SQLException {
  db = DBHelper.getWritableDatabase();
  }
 
  On Mon, Apr 12, 2010 at 6:20 PM, MobDev developm...@mobilaria.com
 wrote:
   do you have some code specifically showing the sequence and the
   syntax ?
   AAfaik a transaction SHOULD make it faster accroding to this
   documentation :
  http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transa..http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#transa..
 .http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#tran..
 .
 
   On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
I have started the transaction before the 1st insert , and ended it
 after
the last insert
Thanks,
Alok.
 
On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com
   wrote:
 Ok,
 @Yahel:- For the insertion of same records on a Palm device(Say
 Palm
   Pre) ,
 its taking 3 seconds..
 On an IPhone , its taking 1 or  2 seconds..
 Here is an example of what i am doing..
 private Boolean addAlbumDB(int AlbumId, String Name, String Label,
 int MultipleArtists, int ArtistId) {
 long result = -1;
 
 try {
 
 ContentValues initialValues = new ContentValues();
 initialValues.put(KEY_ID, AlbumId);
 initialValues.put(KEY_NAME, Name);
 initialValues.put(KEY_LABEL, Label);
 initialValues.put(KEY_ARTIST_ID, ArtistId);
 initialValues.put(KEY_MULTIPLE_ARTISTS,
 MultipleArtists);
 
  result = db.insert(DATABASE_TABLE, null,
 initialValues);
 
 } catch (Exception e) {
 Log.i(Exception in addAlbumDB,  + e.toString());
 return false;
 }
 
 if (result == -1)
 return false;
 return true;
 }
 
 The above function is called for around 2000 times..
 Similarly there are 2 3 more functions for other tables.
 Thanks,
 Alok.
 
 On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
 mike.rue...@gmail.com
   wrote:
 
 On 4/12/2010 10:59 AM, Yahel wrote:
 
 Hi Alok,
 
 Posting some logic, or some sql would help us see if you are
 missing
 something :)
 
 (excessive) use of indices comes to mind :-)
 
 Michael
 
 Yahel
 
 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
 Hi,
 I am inserting around 7000 to 8000 records in my database having
 4
 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to do
 the
 insertion which is i think is too long. I am using transaction
 while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in a
 database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok
 
 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 

Re: [android-developers] Re: Database insertion timings

2010-04-12 Thread Alok Kulkarni
Each of these above functions insert records in 3 seperate tables in the
same database.
Thanks ,
Alok

On Mon, Apr 12, 2010 at 7:51 PM, Alok Kulkarni kulsu...@gmail.com wrote:

 Before the 1st insert call i am doing
 db.beginTransaction();

 for(i = 0 i 2000 ; i++)
addAlbumDB();
 for(i = 0 i 3000 ; i++)
addArtistDB();
 for(i = 0 i 2000 ; i++)
addSongDB();
 try {
 db.setTransactionSuccessful();
 } finally {
 db.endTransaction();

 }


 On Mon, Apr 12, 2010 at 7:18 PM, MobDev developm...@mobilaria.com wrote:

 I don't see a specific transaction ???
 Anyways transaction should only be used if you have multiple actions
 you are doing on your database (like several insert/update
 operations)...

 On 12 apr, 15:43, Alok Kulkarni kulsu...@gmail.com wrote:
  This is a standard class DatabaseHelper extending SQLiteOpenHelper...
 
  private static class DatabaseHelper extends SQLiteOpenHelper {
  DatabaseHelper(Context context, String databaseName) {
  super(context, databaseName, null, DATABASE_VERSION);
  }
 
  @Override
  public void onCreate(SQLiteDatabase db) {
  // Nothing to do
  }
 
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int
  newVersion) {
  Log
  .w(Upgrade, Upgrading database from version 
  + oldVersion +  to  + newVersion
  + , which will destroy all old data);
  db.execSQL(DROP TABLE IF EXISTS titles);
  onCreate(db);
  }
  }
 
  Then i have
  private SQLiteDatabase db;
  This db object is used to perform insert operations.
  Thanks,
  Alok.
  // ---opens the database---
 
  public void open() throws SQLException {
  db = DBHelper.getWritableDatabase();
  }
 
  On Mon, Apr 12, 2010 at 6:20 PM, MobDev developm...@mobilaria.com
 wrote:
   do you have some code specifically showing the sequence and the
   syntax ?
   AAfaik a transaction SHOULD make it faster accroding to this
   documentation :
  
 http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transa..http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#transa..
 .http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#tran..
 .
 
   On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
I have started the transaction before the 1st insert , and ended it
 after
the last insert
Thanks,
Alok.
 
On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com
   wrote:
 Ok,
 @Yahel:- For the insertion of same records on a Palm device(Say
 Palm
   Pre) ,
 its taking 3 seconds..
 On an IPhone , its taking 1 or  2 seconds..
 Here is an example of what i am doing..
 private Boolean addAlbumDB(int AlbumId, String Name, String Label,
 int MultipleArtists, int ArtistId) {
 long result = -1;
 
 try {
 
 ContentValues initialValues = new ContentValues();
 initialValues.put(KEY_ID, AlbumId);
 initialValues.put(KEY_NAME, Name);
 initialValues.put(KEY_LABEL, Label);
 initialValues.put(KEY_ARTIST_ID, ArtistId);
 initialValues.put(KEY_MULTIPLE_ARTISTS,
 MultipleArtists);
 
  result = db.insert(DATABASE_TABLE, null,
 initialValues);
 
 } catch (Exception e) {
 Log.i(Exception in addAlbumDB,  + e.toString());
 return false;
 }
 
 if (result == -1)
 return false;
 return true;
 }
 
 The above function is called for around 2000 times..
 Similarly there are 2 3 more functions for other tables.
 Thanks,
 Alok.
 
 On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
 mike.rue...@gmail.com
   wrote:
 
 On 4/12/2010 10:59 AM, Yahel wrote:
 
 Hi Alok,
 
 Posting some logic, or some sql would help us see if you are
 missing
 something :)
 
 (excessive) use of indices comes to mind :-)
 
 Michael
 
 Yahel
 
 On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:
 
 Hi,
 I am inserting around 7000 to 8000 records in my database
 having 4
 tables
 each having 3 to 4 columns.Its taking me around 22 seconds to
 do the
 insertion which is i think is too long. I am using transaction
 while
 doing
 this without which its taking around 55 seconds.
 According to SQLite documentation , inserting 1 records in
 a
 database
 takes time  around 2 to 3 seconds.
 Am i missing something , or is the behaviour correct?
 Thanks,
 Alok
 
 --
 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 

[android-developers] Re: Database insertion timings

2010-04-12 Thread MobDev
Actually, Im just guessing here, shouldnt you use staretTransaction
and endTransaction instead of setTransactionSuccesfull() ???
Right now you as a developer are specifically marking the transaction
as succesfull, is that what you want ?

On 12 apr, 16:22, Alok Kulkarni kulsu...@gmail.com wrote:
 Each of these above functions insert records in 3 seperate tables in the
 same database.
 Thanks ,
 Alok

 On Mon, Apr 12, 2010 at 7:51 PM, Alok Kulkarni kulsu...@gmail.com wrote:
  Before the 1st insert call i am doing
  db.beginTransaction();

  for(i = 0 i 2000 ; i++)
     addAlbumDB();
  for(i = 0 i 3000 ; i++)
     addArtistDB();
  for(i = 0 i 2000 ; i++)
     addSongDB();
  try {
              db.setTransactionSuccessful();
          } finally {
              db.endTransaction();

          }

  On Mon, Apr 12, 2010 at 7:18 PM, MobDev developm...@mobilaria.com wrote:

  I don't see a specific transaction ???
  Anyways transaction should only be used if you have multiple actions
  you are doing on your database (like several insert/update
  operations)...

  On 12 apr, 15:43, Alok Kulkarni kulsu...@gmail.com wrote:
   This is a standard class DatabaseHelper extending SQLiteOpenHelper...

   private static class DatabaseHelper extends SQLiteOpenHelper {
           DatabaseHelper(Context context, String databaseName) {
               super(context, databaseName, null, DATABASE_VERSION);
           }

           @Override
           public void onCreate(SQLiteDatabase db) {
               // Nothing to do
           }

           @Override
           public void onUpgrade(SQLiteDatabase db, int oldVersion, int
   newVersion) {
               Log
                       .w(Upgrade, Upgrading database from version 
                               + oldVersion +  to  + newVersion
                               + , which will destroy all old data);
               db.execSQL(DROP TABLE IF EXISTS titles);
               onCreate(db);
           }
       }

   Then i have
   private SQLiteDatabase db;
   This db object is used to perform insert operations.
   Thanks,
   Alok.
       // ---opens the database---

       public void open() throws SQLException {
           db = DBHelper.getWritableDatabase();
       }

   On Mon, Apr 12, 2010 at 6:20 PM, MobDev developm...@mobilaria.com
  wrote:
do you have some code specifically showing the sequence and the
syntax ?
AAfaik a transaction SHOULD make it faster accroding to this
documentation :

 http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html#transa..http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#transa..
  .http://web.utk.edu/%7Ejplyon/sqlite/SQLite_optimization_FAQ.html#tran..
  .

On 12 apr, 12:32, Alok Kulkarni kulsu...@gmail.com wrote:
 I have started the transaction before the 1st insert , and ended it
  after
 the last insert
 Thanks,
 Alok.

 On Mon, Apr 12, 2010 at 4:01 PM, Alok Kulkarni kulsu...@gmail.com
wrote:
  Ok,
  @Yahel:- For the insertion of same records on a Palm device(Say
  Palm
Pre) ,
  its taking 3 seconds..
  On an IPhone , its taking 1 or  2 seconds..
  Here is an example of what i am doing..
  private Boolean addAlbumDB(int AlbumId, String Name, String Label,
              int MultipleArtists, int ArtistId) {
          long result = -1;

          try {

              ContentValues initialValues = new ContentValues();
              initialValues.put(KEY_ID, AlbumId);
              initialValues.put(KEY_NAME, Name);
              initialValues.put(KEY_LABEL, Label);
              initialValues.put(KEY_ARTIST_ID, ArtistId);
              initialValues.put(KEY_MULTIPLE_ARTISTS,
  MultipleArtists);

               result = db.insert(DATABASE_TABLE, null,
  initialValues);

          } catch (Exception e) {
              Log.i(Exception in addAlbumDB,  + e.toString());
              return false;
          }

          if (result == -1)
              return false;
          return true;
      }

  The above function is called for around 2000 times..
  Similarly there are 2 3 more functions for other tables.
  Thanks,
  Alok.

  On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
  mike.rue...@gmail.com
wrote:

  On 4/12/2010 10:59 AM, Yahel wrote:

  Hi Alok,

  Posting some logic, or some sql would help us see if you are
  missing
  something :)

  (excessive) use of indices comes to mind :-)

  Michael

  Yahel

  On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

  Hi,
  I am inserting around 7000 to 8000 records in my database
  having 4
  tables
  each having 3 to 4 columns.Its taking me around 22 seconds to
  do the
  insertion which is i think is too long. I am using transaction
  while
  doing
  this without which its taking around 55 seconds.
  According to SQLite 

[android-developers] Re: Database insertion timings

2010-04-12 Thread Yahel
Ok, you are right if the pre and the iphone are 10x faster, it can't
be right.

I don't see anything wrong in your code, so only two things come to
mind :

- Instead of using ContentValues, try to create an insert sql
statement and send it to via SQLiteDatabase.execSQL to see if there is
any improvement
- Maybe it's not the database writing that is slow but the reading
from wherever your getting the data ?

Yahel


On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:
 Ok,
 @Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) ,
 its taking 3 seconds..
 On an IPhone , its taking 1 or  2 seconds..
 Here is an example of what i am doing..
 private Boolean addAlbumDB(int AlbumId, String Name, String Label,
             int MultipleArtists, int ArtistId) {
         long result = -1;

         try {

             ContentValues initialValues = new ContentValues();
             initialValues.put(KEY_ID, AlbumId);
             initialValues.put(KEY_NAME, Name);
             initialValues.put(KEY_LABEL, Label);
             initialValues.put(KEY_ARTIST_ID, ArtistId);
             initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

              result = db.insert(DATABASE_TABLE, null, initialValues);

         } catch (Exception e) {
             Log.i(Exception in addAlbumDB,  + e.toString());
             return false;
         }

         if (result == -1)
             return false;
         return true;
     }

 The above function is called for around 2000 times..
 Similarly there are 2 3 more functions for other tables.
 Thanks,
 Alok.

 On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger mike.rue...@gmail.comwrote:



  On 4/12/2010 10:59 AM, Yahel wrote:

  Hi Alok,

  Posting some logic, or some sql would help us see if you are missing
  something :)

  (excessive) use of indices comes to mind :-)

  Michael

  Yahel

  On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

  Hi,
  I am inserting around 7000 to 8000 records in my database having 4 tables
  each having 3 to 4 columns.Its taking me around 22 seconds to do the
  insertion which is i think is too long. I am using transaction while
  doing
  this without which its taking around 55 seconds.
  According to SQLite documentation , inserting 1 records in a database
  takes time  around 2 to 3 seconds.
  Am i missing something , or is the behaviour correct?
  Thanks,
  Alok

  --
  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.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

  To unsubscribe, reply using remove me as the subject.

-- 
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: Database insertion timings

2010-04-12 Thread Zsolt Vasvari
No, database writing is extremely slow especially with many indecies.

In my app, I am getting maybe 10 insers a seconds into a table with 20
columns and 15 indecies.  As my app is probably 99.9% reads, I didn't
try optimizing the writes too much, not sure if it's even possible.

On Apr 13, 12:33 am, Yahel kaye...@gmail.com wrote:
 Ok, you are right if the pre and the iphone are 10x faster, it can't
 be right.

 I don't see anything wrong in your code, so only two things come to
 mind :

 - Instead of using ContentValues, try to create an insert sql
 statement and send it to via SQLiteDatabase.execSQL to see if there is
 any improvement
 - Maybe it's not the database writing that is slow but the reading
 from wherever your getting the data ?

 Yahel

 On 12 avr, 12:31, Alok Kulkarni kulsu...@gmail.com wrote:



  Ok,
  @Yahel:- For the insertion of same records on a Palm device(Say Palm Pre) ,
  its taking 3 seconds..
  On an IPhone , its taking 1 or  2 seconds..
  Here is an example of what i am doing..
  private Boolean addAlbumDB(int AlbumId, String Name, String Label,
              int MultipleArtists, int ArtistId) {
          long result = -1;

          try {

              ContentValues initialValues = new ContentValues();
              initialValues.put(KEY_ID, AlbumId);
              initialValues.put(KEY_NAME, Name);
              initialValues.put(KEY_LABEL, Label);
              initialValues.put(KEY_ARTIST_ID, ArtistId);
              initialValues.put(KEY_MULTIPLE_ARTISTS, MultipleArtists);

               result = db.insert(DATABASE_TABLE, null, initialValues);

          } catch (Exception e) {
              Log.i(Exception in addAlbumDB,  + e.toString());
              return false;
          }

          if (result == -1)
              return false;
          return true;
      }

  The above function is called for around 2000 times..
  Similarly there are 2 3 more functions for other tables.
  Thanks,
  Alok.

  On Mon, Apr 12, 2010 at 2:33 PM, Michael Rueger 
  mike.rue...@gmail.comwrote:

   On 4/12/2010 10:59 AM, Yahel wrote:

   Hi Alok,

   Posting some logic, or some sql would help us see if you are missing
   something :)

   (excessive) use of indices comes to mind :-)

   Michael

   Yahel

   On 12 avr, 08:50, Alok Kulkarnikulsu...@gmail.com  wrote:

   Hi,
   I am inserting around 7000 to 8000 records in my database having 4 
   tables
   each having 3 to 4 columns.Its taking me around 22 seconds to do the
   insertion which is i think is too long. I am using transaction while
   doing
   this without which its taking around 55 seconds.
   According to SQLite documentation , inserting 1 records in a 
   database
   takes time  around 2 to 3 seconds.
   Am i missing something , or is the behaviour correct?
   Thanks,
   Alok

   --
   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.comandroid-developers%2Bunsubs
cr...@googlegroups.com
   For more options, visit this group at
  http://groups.google.com/group/android-developers?hl=en

   To unsubscribe, reply using remove me as the subject.- Hide quoted text 
   -

 - Show quoted text -

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