SQLite database file upload at server in SQL format - android

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.

Related

how to export database in android application

I have created a database android application it works correctly on emulator , but when Iam transferring it to my device it says that the table is not exist ,I have used 'openOrCreateDatabase() ' method , the database doesnt come with apk file ,when I run the ap, my database is read only, means I already have a lot of data in it and only need to see them
Things in your apk file such as assets are read only so you can't use it as a live database. If you have data already in sqlite database, you will have to copy the data into the live database. If on the other hand you have it in some other format such as csv, you will have to create a reader which will add it into your live database.

xml or sqlite file?

i need hints for SQLite; I receive in SOAP or REST format a large XML (betwen 200 and 5000 entries depending on the user, with around 30 columns) that i parse to a local SQLite db.
This operation takes too much time for the users (from 10 seconds up to 2 minutes), so i wanted to know :
Is it possible under a window server (Delphi XE2 home made server) to create the SQLite database file and send the whole file to the mobile; Then on mobile side, replace the database file with the new one (data are not modified on client side, i can replace file with no regrets ^^ ) ?
On a rooted mobile, i just can't find the SQLite database file (searched for it with esFileExplorer, /data, /dbdata, /sdcard/data... nowhere) so i just don't know where i will have to put that file in the end...
Yes, its possible.
You can download the database having latest data & replace it with current database. Find an example here of "How to use existing data base", link for sample project is also there.
EDIT:
You need to modify it according to your needs.
You can delete your existing database by using context.deleteDatabase(DATABASE_NAME);

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/";

Export remote XML DB files and store in SQLite DB to use by android app

I have access to a set of remote XML files stored in a server (XML files of a MySql database tables).
I have to import and create my own SQLite BD to use them with the android mobile app. When remote XML files update(When MySql database information change), the SQLite DB also Should change accordingly.
Can any one guide me how to accomplish this task this.
Sample coding/ reference/ Idea highly appreciated.
1.Download and Parse the XML files
2.Store them in SQLite database
3.Write a background scheduled service which executes the code for corresponding the above 1 and 2.
Or
Use the Cloud to Device message from your server to the android app to update your SQLite database(but I thought the above 1 and 2 points may need here also.It is all about your logic how you develop the application).
You can try my xsl template
http://code.google.com/p/mysql2sqlite-xslt/.

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