Creating sqlite database outside android project?

I would like to create a project that generates a sqlite database that will eventually be used by an Android application. I would like to create this project as a standard Java application, so I can connect it to the build script, etc. What a good way to do this so that the sqlite database that I output matches the sqlite classes for Android will have it?

I could create this util project as an android project, and then I have access to all sqlite classes, but the sqlite output file will live on the emulator instance, right? And I would have to run the emulator, etc., When I wanted to run the utility, pah.

thanks

+6
source share
4 answers

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

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

+1
source

Like others, I would not want to create a project for it, I would find one of the existing utilities and create a DB in this way. I am using SQLite Expert .

Despite what Seva said, there are some things you must do to make it usable by android. It reads in any state, but if you want the framework to be able to use it as intended (to populate lists and other widgets), it must have certain things.

1) The database should contain a table called "android_metadata"
2) There should be a "locale" column in this table
3) The table must have one entry with the value "en_US"
4) The primary key for each table needs to be called "_id" (this means that Android will know where to bind the id field of your tables)

Then you put the database in your resources folder and copy it to the data directory of your applications at startup.

A good link for this process is here .

+3
source

can create you different as a libray project and can attach it to your project ... The libaray project can be an android or a simple java project according to your needs ...

0
source

Note. Use the version of sqlite that comes with the SDK - it has been slightly modified. If you use the ready-made sqlite3 command-line tool, the databases it creates are not compatible with Android.

0
source

Source: https://habr.com/ru/post/918255/


All Articles