Use mysqlite database converted from mysql in android app - android

For a schoolproject I have converted a php database from MySQL to MySQLi to use it in my android application.
I've looked into creating a android database using head's first book on android (2017) and according to that I need to manually create and insert every record in the database, but I already have all the data needed and one table even has 113 entries that need to be inserted.
Isn't there a way for me to import the existing database without completely creating it all over again?

Use SQLite browser , hope it helps .

Export SQL file from MySql and put it into assets folder. Read sql file from assets, use 'db.execSQL' method to create and insert all records of sql file. Some of the 'keywords' are working in SQLite of MySql so firstly remove these keywords from file.

Related

SQLite database file upload at server in SQL format

I want to upload local sqlite database file at server but in sql format. Is it possible to directly save it in mysql supported format? The file is uploaded successfully on server but its just a flat file of sqlite db. When i open it in editplus or import it in phpmyadmin, it shows error. But when I manually export the database from sqlite manager in .sql extension, it successfully gets open in readable format in editplus. Please help me with this problem. Thanks in advance !
AFAIK you are talking about two completely different things.
Its like comparing a DB dump file to a properly exported file like an xml file with schema and data information from Oracle or MySql
When you export you get a file with or without .sql extension and it means a file with set of queries like DDL or DML create,insert etc. That may be sequentially run to execute all the commands in it and provide you with the right schema and data present in that file.
Whereas a DB file that is created via app is specific to the device and is an .sqlite file which is specific to sqlite browser and that may read it and not a set of queries only that you may open in edit-plus or a text editor.
Sqlite DB file that you find on your device is dynamically generated pages to maintain the integrity of the db.
For more info you must read,
Format of sqlite database
Sorry I don't have code but the idea is,
--Edit with algo--
Assuming you have the create commands for all tables and constraints with you , as they are not going to change most of the time.
You may use this function as a Utility to create and maintain the sql
command list for you parallel to the db you have.
void createExportCommands()
{
...
- Read all tables one by one using a `Cursor`
- Based on specific tables/columns create queries
i.e. String query="insert into "+your_table+" values("+cursor.getString(0),....+");";
- Write this data into a file called export_data.sql and keep updating it in background
}
Perhaps its not the best approach but it will solve your issue.

Create Sqlite database with 8000 records

I'am developing an application which uses sqlite for autocomplete textview. The database has more than 8000 records. Creating a database can be done with a query in onCreate(). But how do i create a database with 8000+ records in it. writing insert query for 8000 records sounds worst to me.
What's the best way to create a database with 8000+ records in it. Is there any way like dumping sql file like how we do in mysql.
Instead, you should put your database with a table (having 8000 records) inside the Assets folder and write a logic to Copy existing database inside your android app.
Check links:
https://stackoverflow.com/a/6541043/379693
Ship an application with a database
What ever approach you conduct but do it in an SQLite Transaction because it will maintain a single Journal (db cache) file for inserting all the records in one go. It will really speed up things a lot.
If you have the .sql file you may import it in phpMyadmin....
Just go to PHPMyadmin URL...
create an empty database....
click on import...
Browse the sql file
click on Go...
That's it

Android - Download SQL Database and Search

I've been working on testing trying to get an SQL database off of a website then take all the records and store them into arrays. Problem is that I've tried a ton of downloading methods and I keep getting hit with an error with opening the SQL database. I can't tell if this is actually downloading, if the database is corrupt (I checked it and it looked correct) or if my queries are messed up. Bear with me because I am just learning SQL and Android development.
The file at the link you provide is not a SQLite database. It's an ASCII file that contains SQL statements for creating a database and inserting content. There's no straightforward way to execute the content of that file in an Android app.
To make this work you need to create an actual SQLite database from your SQL file. To do that, install SQLite for whatever your desktop OS is and use this command:
sqlite> .read <filename of your SQL file>
Replace the file on your website with the SQLite file that creates. That should get you past the open error.
What are you doing here is download your database from url and stored it in sdcard.
Now you should open a empty database in your app and then copy your database in your app database and then try to open it.(you are not copying the database) the default location of database is
private String DB_PATH = "/data/data/your package name/databases/";

Exporting MySQL data into SQLite database format and store in SQLite database

I have to use remote MySQL database information in my Android application.
Is there a way that I can Translate MySQL data to SQLite format and store them in the SQLite DB to access by the mobile application.
Also I need to update the SQLite DB content when a modification happen to MySql data.
That I have decided to do when application loads, to check any modification happened and to change the SQLite DB Accordingly. Is this possible.
Any sample coding/ Idea/Link is highly appreciated.
Thanks in advance
Can you use mysqldump to export the information, for later import into SQLite? mysqldump will export data you specify, and save it into a file containing a bunch of SQL statements to rebuild the data.
So for example, if you run the dump on a schema with 3 tables and a bunch of rows in each, you end up with a .sql file with commands to build those 3 tables and then enter all the rows. The SQL can be used to import into another MySQL database or most other SQL databases.
mysqldump
I would think you could create a batch script of some sort to run the dump command, then use SQLite to pick up and run the .sql file.

Android SQLite reading

I want to only read data from the SQLite database. When I am creating database and reading it it is working but I have already a database created and I want to read data from this database.
I am pushing the database to the sdcard and trying to run the application but it is not reading form the database. I want to know that if install this .apk file in device then my database will also shift to the device or not.
Common practice is to store initial data on assets/raw folders of application resources. Then during 1st run just create DB using SQL scripts like:
create table if not exist
Fill DB with initial data - and here you're.

Categories

Resources