Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 14th, 2010, 08:51 AM   #1 (permalink)
New Member
 
Join Date: Jan 2010
Posts: 7
 
Device(s): HTC Hero
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQLite records pre defined

hi,

I've been reading a bunch of tutorials explaining how to create your SQLite database if it isn't already there, and adding records to it etc. What im looking for is how to have records already in the database when it is installed?

if anyone could point me in the direction of a tutorial or some resource that explains how to achieve this , it would be much appriciated!!

thanks

creatiive is offline  
Reply With Quote
Sponsors
Old January 14th, 2010, 09:26 AM   #2 (permalink)
Junior Member
 
Join Date: Dec 2009
Posts: 17
 
Device(s): Google Nexus One
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The easiest way to do this is when you're creating your database.

If the database isn't there you need to run your script to create the database and then run a script to do your INSERT statements on the database that you just created adding the records.
sn00zer is offline  
Reply With Quote
Old January 14th, 2010, 09:29 AM   #3 (permalink)
New Member
 
Join Date: Jan 2010
Posts: 7
 
Device(s): HTC Hero
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but i only ever want the INSERTs to run once - i dont want to have to have that re-execute every time the app is opened, even if they dont actually do any inserting because they keys are already in there, it would still take processing (and i have a lot of records).#


is it possible to only run the INSERTs if the database gets created, and not if its already there?
creatiive is offline  
Last edited by creatiive; January 14th, 2010 at 09:30 AM.
Reply With Quote
Old January 14th, 2010, 09:30 AM   #4 (permalink)
Junior Member
 
Join Date: Dec 2009
Posts: 17
 
Device(s): Google Nexus One
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't want to create the database every time the app is opened. The first time you open the app . . it will create the database . . and add the records.

The next time the app is opened . . the database will be there so it won't have to go through that step again.
sn00zer is offline  
Reply With Quote
Old January 14th, 2010, 09:48 AM   #5 (permalink)
Member
 
eclipsed4utoo's Avatar
 
Join Date: Nov 2009
Location: Florence, SC
Posts: 435
 
Device(s): Motorola Droid
Thanks: 9
Thanked 27 Times in 11 Posts
Default

Quote:
Originally Posted by creatiive View Post
but i only ever want the INSERTs to run once - i dont want to have to have that re-execute every time the app is opened, even if they dont actually do any inserting because they keys are already in there, it would still take processing (and i have a lot of records).#


is it possible to only run the INSERTs if the database gets created, and not if its already there?
in your same logic where you determine if you need create the database because it doesn't exist, that is when you would do the insert. therefore, you would only be inserting the records when you have to create the database.
__________________
If you like MotoTorch LED, you could Donate With Paypal toward its continued development.

You can also buy the Donation version of MotoTorch LED from the Android Market.

Use Barcode Scanner or Shop Savvy to scan my avatar.
eclipsed4utoo is offline  
Reply With Quote
Old February 11th, 2010, 01:59 AM   #6 (permalink)
New Member
 
SFLeBrun's Avatar
 
Join Date: Feb 2010
Location: USA
Posts: 9
 
Device(s): Motorola Cliq
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use SQLiteOpenHelper to create and initially insert data.

Are you using a SQLiteOpenHelper derived class to open/create your database?

The SQLiteOpenHelper has an abstract method, onCreate(), which is called if the database needs to be created. You can execute your INSERT statements in this method after you create the database. This method is only called the first time an application needs to create a database. Next time the application runs, the database file already exists and SQLiteOpenHelper skips the call to onCreate().
SFLeBrun is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup user defined dictionary? narf Incredible - All Things Root 4 May 31st, 2011 12:33 PM
how populate a List View from database table records[sqlite] lse123 Application Requests 0 December 20th, 2010 11:58 AM
Captivate Owners Defined Jack45 Samsung Captivate 7 December 10th, 2010 01:57 PM
Can I create SQlite Database at user defined path? ajitandroid26 Developer 101 1 September 2nd, 2010 11:40 PM
Slang terminology defined! 2g2x Application Announcements 0 March 13th, 2010 08:22 AM



All times are GMT -5. The time now is 11:41 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo