Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. send sqlite database file trought tcp
Forum Updated to NodeBB v4.3 + New Features

send sqlite database file trought tcp

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 496 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gfxx
    wrote on 25 Oct 2022, 05:56 last edited by
    #1

    I know is difficult but need to copy entire sqlite db trought tcp .... not understand reading online post the best approch ... for sure I understand that using BEGIN IMMEDIATE can pause db connection so can freely copy db on Qfile and send it ..... problem seems packet .... so there are a way to not corrupt sqlite file during tranfer via tcp?

    regards

    bkt

    J 1 Reply Last reply 25 Oct 2022, 06:06
    0
    • G gfxx
      25 Oct 2022, 05:56

      I know is difficult but need to copy entire sqlite db trought tcp .... not understand reading online post the best approch ... for sure I understand that using BEGIN IMMEDIATE can pause db connection so can freely copy db on Qfile and send it ..... problem seems packet .... so there are a way to not corrupt sqlite file during tranfer via tcp?

      regards

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Oct 2022, 06:06 last edited by
      #2

      @gfxx said in send sqlite database file trought tcp:

      so there are a way to not corrupt sqlite file during tranfer via tcp?

      Close all db connections, read the db file and send its content over TCP/IP connection.
      "problem seems packet" - don't know what this means.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • G Offline
        G Offline
        gfxx
        wrote on 23 Dec 2022, 03:14 last edited by
        #3

        In the past Seems my problem was solved .... but now I reuse the same call in other app an the result of qtcp transfer file become the same junk file trasmission ... for better understand it start in these manner:

        "\x00\x00\x00\x00\x00\x14\xA0\x04\x00\x14\xA0\x00SQLite format 3\x00\x10\x00\x01\x01\x00@  \x00\x00G[\x00\x00\x01J\x00\x00\x00\x05\x00\x00\x01""2\x00\x00\x02\xD1\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00G[\x00.G\xA8\x05\x00\x00\x00\x01\x0F\xFA\x00\x00\x00\x00""c\x0F\xFA\x0F\xEE\x0F\xEE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
        

        and that sequence of \x00 continue but everytime there are some redable string that contain database column description or table description .... plus database file in origin was 1.3Mb but at end of transmission obtain only 50kb (probabily last packet).

        In the past I use this code for send:

            Database.removeDatabase("/home/de/.DB/mydb.sqlite3");
        
            if(tcpSocket->state() == QAbstractSocket::ConnectedState){
                QFile file("/home/de/.DB/mydb.sqlite3");
                if (!file.open(QIODevice::ReadOnly)){
                    qDebug() << "file not open .....";
                }
                else{
                        if(tcpSocket->state() == QAbstractSocket::ConnectedState){
                        QByteArray block;
                        while(1){
                            block.clear();
                            block = file.read(32768*8);
                            if(block.size() == 0) break;
                            tcpSocket->write(block);
                            tcpSocket->waitForBytesWritten();
                            block.clear();
                        }
                         file.close();
                    }
        

        code for receive:

        qint64 fileSize = client->bytesAvailable();
        else if (fileSize > 200 && !fileBR)
                {
                    QFile filew("/home/gr/.DB/receivedb.sqlite3");
                    filew.resize(0);
                    if(!filew.open(QIODevice::Append))
                    {
                        qDebug() << "....file not open  ....";
                    }
                    else{
                        QByteArray read;
                        //qDebug() << "Read    : " << read;
                        while(client->bytesAvailable()){
                            read = client->read(client->bytesAvailable());
                            filew.write(read);
                            qDebug() << "Read this data   : " << read;
                        }
                     filew.close();
        
        

        but these time I obtain these junk file instead the original copy ..... i try with buffer with same result .... problem seems to become from sender ....

        bkt

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 23 Dec 2022, 08:08 last edited by
          #4

          Your tcp socket handling is a mess - esp. on the receiver side since client->bytesAvailable() can be 0 even tough not all bytes were received. Use proper signal/slots, open the file and hold it as member and send the file size in the first 8 bytes so you know when you received all data.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          G 2 Replies Last reply 23 Dec 2022, 18:57
          4
          • C Christian Ehrlicher
            23 Dec 2022, 08:08

            Your tcp socket handling is a mess - esp. on the receiver side since client->bytesAvailable() can be 0 even tough not all bytes were received. Use proper signal/slots, open the file and hold it as member and send the file size in the first 8 bytes so you know when you received all data.

            G Offline
            G Offline
            gfxx
            wrote on 23 Dec 2022, 18:57 last edited by
            #5

            @Christian-Ehrlicher said in send sqlite database file trought tcp:

            Your tcp socket handling is a mess - esp. on the receiver side since client->bytesAvailable() can be 0 even tough not all bytes were received. Use proper signal/slots, open the file and hold it as member and send the file size in the first 8 bytes so you know when you received all data.

            ok .... so means if LAN was really good can work, but if "normal" impossible to obtain good result ... right? ....

            any how really thans ...

            I'm teaching myself, so that any suggestion is valuable .... and I'm not touchy .... a question why byteavaible can be "0" (as it seems to be in fact) ... ie what mechanism produces this? .... you can also send me links where it is explained .... in my head the sockets work with datagrams of predefined size and with a minimum of control .... but I understand that it's just my fantasy .. ..

            bkt

            C 1 Reply Last reply 24 Dec 2022, 06:47
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 23 Dec 2022, 19:30 last edited by
              #6

              A tcp stream is a ... stream.
              So you have to define your own protocol to send data over your stream and be able to decrypt it on the receiver side. Or you use e.g. QDataStream which implements a protocol you can use. There are a lot of questions and answers about this in the forum -> forum search

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • G gfxx
                23 Dec 2022, 18:57

                @Christian-Ehrlicher said in send sqlite database file trought tcp:

                Your tcp socket handling is a mess - esp. on the receiver side since client->bytesAvailable() can be 0 even tough not all bytes were received. Use proper signal/slots, open the file and hold it as member and send the file size in the first 8 bytes so you know when you received all data.

                ok .... so means if LAN was really good can work, but if "normal" impossible to obtain good result ... right? ....

                any how really thans ...

                I'm teaching myself, so that any suggestion is valuable .... and I'm not touchy .... a question why byteavaible can be "0" (as it seems to be in fact) ... ie what mechanism produces this? .... you can also send me links where it is explained .... in my head the sockets work with datagrams of predefined size and with a minimum of control .... but I understand that it's just my fantasy .. ..

                C Offline
                C Offline
                ChrisW67
                wrote on 24 Dec 2022, 06:47 last edited by ChrisW67
                #7

                @gfxx said in send sqlite database file trought tcp:

                a question why byteavaible can be "0" (as it seems to be in fact) ... ie what mechanism produces this? ....

                Sender sends 20000 bytes. This will go across the network in a series of packets of up to a network path specific maximum size. Let's say 1460 bytes, a typical maximum segment size in TCP.
                Receiver receives some of these bytes.
                The bytesAvailable() call returns 1460 and you read them before looping back.
                If you are lucky then more of the 20000 bytes has arrived in the short time it took to read and save the first chunk, and you can read, save, and loop again.
                If you are not lucky then no more of the 20000 bytes has arrived and your bytesAvailable() call returns zero.

                G 1 Reply Last reply 24 Dec 2022, 07:48
                3
                • C ChrisW67
                  24 Dec 2022, 06:47

                  @gfxx said in send sqlite database file trought tcp:

                  a question why byteavaible can be "0" (as it seems to be in fact) ... ie what mechanism produces this? ....

                  Sender sends 20000 bytes. This will go across the network in a series of packets of up to a network path specific maximum size. Let's say 1460 bytes, a typical maximum segment size in TCP.
                  Receiver receives some of these bytes.
                  The bytesAvailable() call returns 1460 and you read them before looping back.
                  If you are lucky then more of the 20000 bytes has arrived in the short time it took to read and save the first chunk, and you can read, save, and loop again.
                  If you are not lucky then no more of the 20000 bytes has arrived and your bytesAvailable() call returns zero.

                  G Offline
                  G Offline
                  gfxx
                  wrote on 24 Dec 2022, 07:48 last edited by
                  #8

                  @ChrisW67 said in send sqlite database file trought tcp:

                  Sender sends 20000 bytes. This will go across the network in a series of packets of up to a network path specific maximum size. Let's say 1460 bytes, a typical maximum segment size in TCP.
                  Receiver receives some of these bytes.
                  The bytesAvailable() call returns 1460 and you read them before looping back.
                  If you are lucky then more of the 20000 bytes has arrived in the short time it took to read and save the first chunk, and you can read, save, and loop again.
                  If you are not lucky then no more of the 20000 bytes has arrived and your bytesAvailable() call returns zero.

                  real thanks ... good explain.

                  bkt

                  1 Reply Last reply
                  0
                  • C Christian Ehrlicher
                    23 Dec 2022, 08:08

                    Your tcp socket handling is a mess - esp. on the receiver side since client->bytesAvailable() can be 0 even tough not all bytes were received. Use proper signal/slots, open the file and hold it as member and send the file size in the first 8 bytes so you know when you received all data.

                    G Offline
                    G Offline
                    gfxx
                    wrote on 26 Dec 2022, 17:31 last edited by
                    #9

                    @Christian-Ehrlicher

                    completely missing ....

                    	if (client->bytesAvailable() <=0)    
                    		return;
                    

                    think too tired......

                    bkt

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved