Android Question How to "dump" a database to a text file?

vecino

Well-Known Member
Licensed User
Longtime User
Hi, from my application, how can I execute a "dump" of a database?
sql.execnonquery("dump > dbbak.sql")
With some shell command?
Thanks.
 

Sandman

Expert
Licensed User
Longtime User
globales.DBconex.ExecNonQuery(".debug "&globales.cDBruta&"/"&"kk3.db")
I just have to ask, have you tried this:
B4X:
globales.DBconex.ExecNonQuery(".debug " & xui.DefaultFolder & "kk3.db")

Just a final test from me to make sure that the destination path isn't the problem. Also try with .backup, obviously.

(Perhaps you need to add a slash in there, I forget if DefaultFolder has an ending slash.)
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Exactly the same, it doesn't know the dot ".", and if I remove the dot then it doesn't know "dump", "backup", etc.
By the way, "globales.cDBruta" is assigned the value of "xui.DefaultFolder".

It seems that the "Sql" library is very limited and does not have these commands implemented.
I think I'm going to leave it, export tables in text mode and I'm going to end this topic, I've already spent too much time on it, and it seems that we can't do more.

Thank you very much for your advice and time spent, friends.
?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I think I'm going to leave it, export tables in text mode
If we assume that's how one needs to do it, perhaps you could make a small class or b4xlib and upload? I'm sure there are others who would like to dump the database from within the app.
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
Sometimes i am too lazy to overthinking, what i have done is create temporary database file (or you shipped empty temporary database file within your APK) contain tables you want to copy/hold data, and when you want to use those temporary database file just use ATTACH DATABASE to read/write the data, this is the fastest method i think.

Please note that the database i am talking about are SQLite for both source and destination database
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I didn't understand correctly, you mean that you connect to another DB and you can pass information from one DB to another DB.
Is that so?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I never need to “backup” the user’s data. Most of my apps with database are “sync” to remote server using OkHttpUtils2 or jRDC2 when there is internet connection.
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
Hi, I didn't understand correctly, you mean that you connect to another DB and you can pass information from one DB to another DB.
Is that so?
Yes that what i mean, by attaching another (temporary) database to current database with ATTACH DATABASE you can make copy data from one table (source) to another table (destination), you can copy all data or by selected criteria. When done you can DETACH the (temporary) database.

*Don't forget to place the temporary db location same as primary database, or you have to provide full-path if the database has different location
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Very interesting, thank you.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Take a look to:

 
Upvote 0