copy specific table from one location to another

mozaharul

Active Member
Licensed User
Hi,

I've same database in "My document" as well on SD card. Is it possible to copy a specific table from the "My document" to SD card database ?
If possible, then how ?


regards,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
These are SQL databases? How large are the tables?

You can create two set of connection objects, command objects and reader objects.
One set for each database.
Then read the data row by row and add it to the target database.

You can also read the complete table with cmd.ExecuteTable and then save it with Connection.createSQLTable.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Another option might be to use SQLite's ATTACH DATABASE:
SQLite Query Language: ATTACH DATABASE

Not sure it will work in this specific situation, but the nice thing is that all can be done with one SQL statement, so it will be faster as you don't have to move data to the data reader and then back to another SQLite table.
Something like this:

INSERT INTO TABLE1 SELECT * FROM TABLE2


RBS
 

mozaharul

Active Member
Licensed User
Hi,
Yes, SQLite database with around 20 tables. The initial size is small but will increase by time, as it is the part of a surveillance database which is updated quarterly in a year.

"You can create two set of connection objects, command objects and reader objects.
One set for each database.
Then read the data row by row and add it to the target database."


I have done it in the same way with insertion (for new rows) and update (for existing rows) option and its working fine. The purpose is to backup only the tables being changed depending upon a flag. I was looking is there any other smart way.

"You can also read the complete table with cmd.ExecuteTable and then save it with Connection.createSQLTable."



For The 2nd option I tried like:

If btnclose.Text = "Backup" Then
cmd.CommandText = "select * from rf_disease"
cmd.ExecuteTable("table5",0)
' con1.Open("data source =\SD card\kdss_db" )
con1.Open("data source =C:\Documents AND Settings\mozaharul\Desktop\test")
cmd1.CommandText = "drop table rf_disease"
cmd1.ExecuteNonQuery
con1.CreateSQLTable("table5","rf_disease")
Msgbox("Data saved in the SD card")
con1.Close
End If

It works fine but the problem is that, for all numeric field, the data type is changed to real one. How to preserve the data type of the target table intact ?


regards,
 
Last edited:
Top