Database table transfer over TCP
-
Hello everyone!
I've tried to implement both methods, but I've ran into a slight snag.@kshegunov
Your method is straight forward! With aQDataStream
writing to aQByteArray
, I first store the column headers (asQString
) and all data values (asQVarient
). Then to a parentingQByteArray
I keep track of the Database name, Table name, number of rows, number of columns, and the data collection'sQByteArray
. It is then this parentingQByteArray
I send to the remote platform for data extraction and storage. Working with 20 days of data, I was able to collect, transmit, and store the data in just about 4 minutes (not that this matters, but it's a way for me to compare the performance difference).@mjsurette
I'm having a difficult time getting your strategy implemented. I'm able to populate aQSqlTableModel
with my desired SQL query. I'm using the TableModel because it is said that this object can easily read/write to a database table. Sadly though, how do I then take the table's data and switch to a newQSqlDatabase
object (this is defined in theQSqlTableModel
's constructor)? The way we discussed this, I would have 2 differentQSqlDatabase
objects - 1) is the original data; 2) is the exported data. Could you offer some more guidance with how I can move data from one database to another?Thanks and I look forward to hearing from you.
wrote on 26 Sept 2016, 23:31 last edited by@DoughBoy
The following SQL, with the Chinook test database open will create a new file in the same directory named 'out.sqlite' holding all of the album information for artist 51 with the original table layout.A Qt model is totally unnecessary. Just run the query and it will create your file. From there you can compress it and ship it.
ATTACH DATABASE 'out.sqlite' AS outdb; CREATE TABLE outdb.album AS SELECT * from album WHERE ArtistId = 51; DETACH DATABASE outdb;
It does use SQLite specific sql.
Note especially that the ATTACH DATABASE and DETACH DATABASE are sql to be sent to the database just like the CREATE TABLE..
BTW, I have never done this using Qt, only in batch files, but I see no reason for it not to work both ways.
Mike
21/21