mysql to sqlite in code
I need to pull a mysql database hosted on a server and put it into the android phone which uses sqlite on the click of a button.
I have searched google and th开发者_运维技巧ere are some options although im not too sure which 1 would be the easiest to implement.
Here is some info : My database contains 4 tables with around 9000 records. I need to pull all of it.
1.Use a parser from mysql to xml and then write the xml to sqlite..Is this possible or feasible considering the size of my db?
Refering to this , http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/,
private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";
private static String DB_NAME = "myDBName";
am i able to point the DB_PATH to the mysql db hosted in the sever instead of the application stored db? I have tried this code out using a db in my own app and it does copy the db to the app if it is a first run.
3.In essence, im copying a mysql to sqlite db..Thanks guys :)
you need implement any parsing. using parsing you can get data from particular URL and store it in local database.it is also way to store remote db to local db.
am i able to point the DB_PATH to the mysql db hosted in the sever instead of the application stored db? I
Definitely not. DB_PATH is a "sqlite database file", there is no database server in sqlite. So you cannot just replace it with a mysql server.
I think you need to:
- first get the sqldump of your db on your host
- Convert the mysql statements to sqlite(this should be straightforward unless you are using missing SQL92 features in Sqlite, see this) (you can do this using this)
- Execute converted sql statements on your local db
精彩评论