Results 1 to 15 of 15

Thread: Not getting all data from database through QNetworkAccessManager.

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Not getting all data from database through QNetworkAccessManager.

    I am trying to download all rows from a mysql table into sqlite using QNetworkAccessManager but it will not retrieve full data, more worse it retrieves random number of rows(134,135,220, 1409) but never full rows which in that tables are aprox. 4000;

    Url setting:
    Qt Code:
    1. void sinc::startNetworkRequest(){
    2. QNetworkAccessManager *manager=new QNetworkAccessManager(this);
    3. QNetworkRequest cerere;
    4. QNetworkReply *rasp;
    5.  
    6. cerere.setUrl(QUrl("http://webserverurl.php?param1=01&param2=01"));
    7. rasp=manager->get(cerere);
    8. connect(rasp,SIGNAL(readyRead()),this,SLOT(insertToTable()));
    9. connect(rasp,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(slotEroare(QNetworkReply::NetworkError)));
    10. }
    To copy to clipboard, switch view to plain text mode 

    Data retrieving slot:

    Qt Code:
    1. void sinc::insertToTable(){
    2. QByteArray baRasp=rasp->readAll();
    3. QString str(baRasp);
    4. QStringList listaDet,listaElemR;
    5. listaDet=str.split(";");
    6. QSqlQuery curatare,adaug;
    7.  
    8. curatare.exec("delete from destTable");
    9. for(int i=0; i<listaDet.size()-1; i++){
    10. listaElemR=listaDet[i].split(",");
    11. adaug.exec("insert into destTable values ("
    12. "'"+listaElemR[0]+"'"
    13. ",'"+listaElemR[1]+"'"
    14. ",'"+listaElemR[2]+"'"
    15. ",'"+listaElemR[3]+"'"
    16. ",'"+listaElemR[4]+"'"
    17. ",'"+listaElemR[5]+"'"
    18. ",'"+listaElemR[6]+"'"
    19. ",'"+listaElemR[7]+"'"
    20. ",'"+listaElemR[8]+"'"
    21. ",'"+listaElemR[9]+"'"
    22. ",'"+listaElemR[10]+"'"
    23. ",'"+listaElemR[11]+"'"
    24. ",'"+listaElemR[12]+"'"
    25. ",'"+listaElemR[13]+"'"
    26. ",'"+listaElemR[14]+"'"
    27. ")");
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

    If I want to retrieve the number of rows from the webserver( through echo mysqli_num_rows(result)) I get the full number rows, so it isn't mysql's,php's or webserver's fault.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    How many times You service readyRead signal ? You should read data until signal finished is emitted.

  3. The following user says thank you to Lesiok for this useful post:

    adutzu89 (19th June 2014)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Well the only time I post it.
    So I should have 2 slots, 1 for reading the data(connected to readyRead()) and 1 for inserting the data read(connected to finished())?


    Added after 59 minutes:


    I've connected the slot to the finished() signal, and gives all rows.
    Last edited by adutzu89; 19th June 2014 at 15:22.

  5. #4
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Strangely if I do a count() in sqlite table the number of rows shown is a bit smaller then the rows got, but If I put a

    Qt Code:
    1. qDebug()<<QString::number(i)<<" "<<listaElemR[0]<<endl;
    To copy to clipboard, switch view to plain text mode 

    in the for(int i=0; i<listaDet.size()-1; i++) block it goes all the way to the last line.

    Example:
    listaDet.size()-1=4463
    select count(*) from destTable;=4453

  6. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    What is a value returned from readAll() after signal finished ?

  7. #6
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    I do not understand your question.
    If your talking "what is the value returned from readAll()", in my question I've post how I get the value.

    Qt Code:
    1. QByteArray baRasp=rasp->readAll();
    2. QString str(baRasp);
    3. QStringList listaDet;
    4. listaDet=str.split(";");
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. qDebug()<<QString::number(listaDet.size())<<endl; //this output's in the console 4464(meaning there should be 4463 in sqlite db)
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    I know this. I want to see what is in variable str - before splitting. I think that there is something more than the data from the database.

  9. #8
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Oh, ok
    Well then I will post the webserver's php code(example on how I get the data from mysql database and sending it):

    Qt Code:
    1. $queryStr="select * from dbTable";
    2. $query=mysqli_query($link,$queryStr);
    3. while($r=mysqli_fetch_assoc($query)){
    4. $v1=$r['column1'];
    5. $v2=$r['column2'];
    6. $v3=$r['column3'];
    7. $v4=$r['column4'];
    8.  
    9. $r.=$v1,$v2,$v3,$v4;";
    10. }
    11.  
    12. echo $r;
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Dear buddy, I do not care how answer is prepared only what it contains.

  11. #10
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    This is a small portion of the str's output in the console.

    Qt Code:
    1. qDebug()<<str;
    To copy to clipboard, switch view to plain text mode 

    1,rem impex srl engross-1629670,rem impex srl engross-1629670, ,0,21,romania,galati,galati,galati unic stand 12 j17/1151/91,,
    , , ,0,,ro1629670, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;2,bartel coscs-gl-2480347,bartel coscs-gl-2480347, ,0,21,romania,galati,galati,galati centru langa modern,,
    , , ,0,,r2480347, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;3,mini magic srl gl,mini magic srl gl, ,0,21,romania,galati,galati,galati centru linga patis cernat,,
    , , ,0,,, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;4,farm exprofesso srl gl-1628810,farm exprofesso srl gl-1628810, ,0,21,romania,galati,galati,galati,,
    , , ,0,,1628810, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;5,farm patis cernat srl gl-5768396,farm patis cernat srl gl-5768396, ,0,21,romania,galati,galati,galati,j17/1501/1994,str.otelarilor,bl.d11a,
    , , ,0,,r5768396, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;6,negro srl gl,negro srl gl, ,0,21,romania,galati,galati,galati,,
    , , ,0,,, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;7,vipem srl gl aprozar-1641801,vipem srl gl aprozar-1641801, ,0,21,romania,galati,galati,galati aprozar,,
    , , ,0,,r1641801, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;8,farm tink-baivaron srl gl,farm tink-baivaron srl gl, ,0,21,romania,galati,galati,galati str mihai bravu nr 4,,
    , , ,0,,ro9762523, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;9,rem impex srl gl-1629670,rem impex srl gl-1629670, ,0,21,romania,galati,galati,galati micro 39 magazin,,
    , , ,0,,ro1629670, ,0,1, ,0000-00-00 00:00:00,2013-11-23 13:34:28;

  12. #11
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Are You sure that semicolon appears only at the end of each record ? Maybe some data contains semicolon and then one record is divided into two parts.

  13. The following user says thank you to Lesiok for this useful post:

    adutzu89 (21st June 2014)

  14. #12
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    I will try and verify directly in the database.

    There is no record of when searched for ";" , but there are a lot which contain ",". I will try an change the delimiters to some which are almost never used.
    I wil return to tell you my result.

    Thank you


    Added after 18 minutes:


    Searched, changed delimiters and have the same end result.

    I believe it's a sqlite bug, maybe as I get the same thing using delimiters which weren't use at all and got the same number of rows from webserver and same result when using count() on the sqlite table(meaning 4464 in stringlist , 4453 counted in sqlite after insertion), also the number of rows inserted in sqlite are in the following range 0-4463 and I see in console that the last row inserted into the table is counted as 4463.
    Last edited by adutzu89; 21st June 2014 at 12:56.

  15. #13
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    I found why I had 4453 rows inserted in sqlite instead of 4464.........forgot to escape special characters and those rows that didn't insert cotained " ' " character.

  16. #14
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Read about QSqlQuery::prepare and ? placeholders.

  17. #15
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Not getting all data from database through QNetworkAccessManager.

    Yes, now I am inserting using prepare() and bindvalue() and all rows are inserted.

Similar Threads

  1. Replies: 2
    Last Post: 6th April 2014, 11:07
  2. Post some data onto the local server by QNetworkAccessManager(Qt5)
    By stereoMatching in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2014, 00:13
  3. Replies: 1
    Last Post: 29th September 2012, 19:49
  4. Replies: 0
    Last Post: 18th May 2011, 09:18
  5. HTTP Post from QNetworkAccessManager - no data sent
    By secureboot in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2011, 18:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.