I can successfully upload the sqlite file from iOS to server, however having trouble with android, getting a TiBlob: java.io.FileNotFoundException: Resources/db_name error. To open the database i use var backDatabase = Ti.Database.open('db_name'); i am adding this to the post in the HTTP Client.
file : OS_IOS ? backDatabase.getFile() : Ti.Filesystem.getFile("./db_name"),
So i guess the question is what can i use to get the file in android?
If I understood correctly, you want to download from a server a SQLite database programming with Android, is it that?
I think this is a good answer: https://stackoverflow.com/a/7162385/6133630
Do not use any library, simply take the InputStream that returns the connection and copy byte to byte in s3db file.
On Android, the database is created on the internal storage (you could
move it, or use the install procedure to put it on external storage).
The standard location on internal storage is
/data/data/com.example.yourappid/databases/dbname
Docs here
Or if you are using SDK 5.4.0+, you can actually use the file property to get the db file.
Docs here
Related
I am working on an iOS and Android app which uses a local database for saving the data. Now my client wants to add the export & import data option in the app. So that the user can export data from one device and import it on any other device to use his account as it is. How can I do that? Any references or help.
Thanks In Advance!!!
You can try to export all the data from the database to a .csv file and read from iOS or viceversa.
You can find an example of how to export data in Android here
The best way to do that is creating a way to read data and write data to a .csv file. In reading you can easily write your data like a text file and separate every entry with ','. and reading data from it is also easy , you can read file line by line and use java string tools to process the string file and fetch data from it.
Beside it can be edited or generated by Microsoft excel. So the client could easily work with it.
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.
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.
I have a SQLite database in my Android application, and I want to update it over the internet.
So I decided to use a webserver were I can store a txt file with sql statements. Then I'll download the file, and execute sql statements.
Now I have some questions:
How I can protect the txt file? I don't want anyone to get access to my file using a normal browser.
If I protect the file or the webserver, how I can authenticate to download it?
Is this implementation the best way to update a local database over the internet?
You can add authentication layer to your web server and when you need to access the file just send Authentication parameters with your request and you'll be able to access the file. Not sure if its the best implementation or not, depends on your application. How are you planning to update your database second time, is user going to request update on database?
I have an application that creates an SQLite database and saves
information to it over the course of a day. At the end of the day i
want to export this database to a web server.
Could anyone point me in the right direction for this?
Should I use httppost or put. I have researched this myself online but
there seems to be so many different ways to explore. The server side
does not exist yet either. I have access to an apache server so i am
hoping to use that.
Could anyone advise me the best/most simple way to do this?
Thanks guys,
Just wanted to let you know that i used the intent provided by the andFTP app in the end. Its very simple to use and details can be found at: http://www.lysesoft.com/support/forums/viewtopic.php?f=5&t=158
Couple of ways ...
you can ftp up the db each day
you can export the data to a csv file and post it to the server; once there you can then import it into the db on the web server
Is it for backup purposes? Or do you require a number of dbs on the web server?
Do you want this to be an automatic or manual transfer? SQLite data is just a file, so (from the SQLite site)... "If SQLite can read the disk file then it can read anything in the database. If the disk file and its directory are writable, then SQLite can change anything in the database. Database files can easily be copied onto a USB memory stick or emailed for sharing." So (provided everything your app needs is set up on the server) just move the file to the server.