Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building of an sqlite database outside an android project?

Tags:

android

I'd like to create a project which generates a sqlite database, which will eventually be used by an android application. I'd like to create this project as a standard java application, so I can hook it up to a build script etc. What's a good way to go about doing this, so that the sqlite database I output is conformant with the way android sqlite classes expect to have it in?

I could create this util project as an android project, and then I have access to all the sqlite classes, but the output sqlite file would live on an emulator instance, right? And I'd have to fire up an emulator etc whenever I wanted to run the util, ugh.

Thanks

like image 401
user291701 Avatar asked Jun 16 '12 19:06

user291701


People also ask

Is it practical to use an SQLite database for Android studio?

Whenever an application needs to store large amount of data then using sqlite is more preferable than other repository system like SharedPreferences or saving data in files. Android has built in SQLite database implementation.

What is the purpose of an SQLite database to an Android application?

SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.


2 Answers

As others have suggested, I wouldn't build a project for it, I'd find one of the existing utilities out there and create the DB that way. I use SQLite Expert.

Despite what Seva said, there are some things you have to do to make it usable by android. It's readable in any state, but if you want the framework to be able ot make use of it like intended (to populate listviews and other widgets), it has to have certain things.

1) The database must contain a table called "android_metadata"
2) This table must have the column "locale"
3) There should be a single record in the table with a value of "en_US"
4) The primary key for every table needs to be called "_id" (this is so Android will know where to bind the id field of your tables)

Then you put the DB in your assets folder and copy it to your apps data directory on startup.

A good link for this process is here.

like image 86
Barak Avatar answered Oct 22 '22 16:10

Barak


Why do you want create a separate Java project to create a SQLite database? There are graphical shells over SQLite out there. I personally like SQLiteStudio.

There's nothing special about the way Android accesses them - SQLite is SQLite, the database format is the same on every platform. Create a new database file, create some tables in it, insert some data, then place it into an Android project and play with it.

like image 41
Seva Alekseyev Avatar answered Oct 22 '22 16:10

Seva Alekseyev