Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Prob with store and retrieve binary data to/from remote sqlserver's image field

  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Friends ,
    I need to store and retrieve binary data from remote sql server's image field. now i can store binary value into remote server by simply reading the source file sontent into byte array and store that byte array content into a Qstring while usnig insert statement.


    /************code***********/

    wBData is a byte array in which i read source file content
    QString s1(wBData);
    net.get("http://192.168.0.220/clancor?sql=insert+into+blob+(sno,photo)+values+(4 ,'"+ s1 +"')&root=blobinsert"

    /*************************/

    while retrieving sql server gives image field as a Binary base Encoded format i tried to docode.but decoded value does not creates original file i saved into the database


    /********code**************/

    QByteArray wBData1;
    net.get("http://192.168.0.220/clancor?sql=select+photo+from+blob+where+sno+=+4+F OR+XML+RAW,+BINARY+BASE64&root=blobinsert&contentt ype=text/xml")

    wBData1.append(xml.attributes().value("photo").toS tring());

    QByteArray by(QByteArray::fromBase64(wBData1));
    fil.write(by); // write into a file

    /*************************/
    i wondered if any body notify where im doing wrong?

    Thanks

    Askar
    Last edited by Askar; 25th September 2009 at 07:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    What is "net" and how does it work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Wysota,

    net is QNetworkAccessManager object;


    /******************************/

    QNetworkAccessManager net = new QNetworkAccessManager();

    /******************************/

    thanks,

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    And where do you retrieve data from it? Remember it works in an asynchronous fashion.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Wysota,
    Im retrieving binary data from remote sql server (priviously stored binary data for a image file). and tried to reconvert it into a image file again.
    and what do u mean by works in an asynchronous fashion?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Where in your code...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    /********code**************/
    QNetworkAccessManager net = new QNetworkAccessManager();
    QByteArray wBData1;
    net.get("http://192.168.0.220/clancor?sql=select+photo+from+blob+where+sno+=+4+F OR+XML+RAW,+BINARY+BASE64&root=blobinsert&contentt ype=text/xml")

    wBData1.append(xml.attributes().value("photo").toS tring());

    QByteArray by(QByteArray::fromBase64(wBData1));
    fil.write(by); // write into a file

    /*************************/

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    I still fail to see where you retrieve data from the "net" object. If you think QNetworkAccessManager would somehow magically guess that you wanted it to place the contents of the retrieved file in "wBData1" variable then you're wrong. And again, QNetworkAccessManager works in an asynchronous fashion. See it's docs for examples of usage.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Wysota,
    By using net object im passing sql query to sql server, to retrive records from database tables,

    /***********************/
    QEventLoop loop;
    QNetworkReply *reply;
    reply=net.get("http://192.168.0.220/clancor?sql=select+photo+from+blob+where+sno+=+4+F OR+XML+RAW,+BINARY+BASE64&root=blobinsert&contentt ype=text/xml")
    connect(reply, SIGNAL(finished()),&loop,SLOT(quit()));
    loop.exec(); //entering event loop until reply object's finished() signal gets activated

    QXmlStreamReader xml(reply->readAll()); //storing retrieved xml file content xmlstreamreader object


    /**********************/

    By using xml parsing functions i am reading the actual record (binary base64) values retrieved from the table by using the following line.
    /******************************/
    wBData1.append(xml.attributes().value("photo").toString());
    /*****************************/
    this line reads data from xml object into Byte array variable WBData1

    ------------------by this way only im retrieving data from net object------------------

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Now we're getting somewhere... So what happens after you put the data into the byte array? Where are your sql statements here and what is wrong exactly?

    I'm now pretty annoyed with having to drag every information out of you almost by force. Either you provide information and code for others to see what is going on in your code or I'm done answering to this thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Sorry Mr.Wysota
    Its my mistake, i should post my thread with clear codes and explanations. sorry once again.

    the retrieved value from xml file is in binary base64 encoded, so i created another one byte array (byte) to store the base64 decoded binary data, for that i used the following syntax...

    Qt Code:
    1. QByteArray byte(QByteArray::fromBase64(wBData1));
    To copy to clipboard, switch view to plain text mode 

    then im storing the contents of the variable byto into a already opened file, code given below

    Qt Code:
    1. fil.write(byte);
    2. fil.close();
    To copy to clipboard, switch view to plain text mode 

    fil is file object already opened,

    after doing all these things i could not get the original file (for eg image) what im stored before into the server.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    How does your xml parser look like? If the code you pasted is complete, it means that you don't have a parser and you "forgot" to read QXmlStreamReader documentation which you should now do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    sorry
    i didnt pasted here the code for xml parsing .
    now i gave the complete code for retrieving data from remote sql server & parsing the retrieved xml file.

    Qt Code:
    1. QNetworkReply *reply;
    2. QFile fil("testsnd");
    3. if(!fil.open(QIODevice::WriteOnly))
    4. {
    5. qDebug() << "cannot open file for writing"<<qPrintable(fil.errorString()) <<endl;
    6. return 0;
    7. }
    8. reply=net.get("http://192.168.0.220/clancor?sql=select+photo+from+blob+where+sno+=+4+F OR+XML+RAW,+BINARY+BASE64&root=blobinsert&contentt ype=text/xml")
    9. connect(reply, SIGNAL(finished()),&loop,SLOT(quit()));
    10. loop.exec(); //entering event loop until reply object's finished() signal gets activated
    11.  
    12. QXmlStreamReader xml(reply->readAll()); //storing retrieved xml file content xmlstreamreader object
    13. while (!xml.atEnd())
    14. {
    15. xml.readNext();
    16. if (xml.tokenType() == QXmlStreamReader::StartElement)
    17.  
    18. if (xml.name() == "row")
    19. {
    20. wBData1.append(xml.attributes().value("photo").toString());
    21. }
    22. }
    23. QByteArray byte(QByteArray::fromBase64(wBData1));
    24. fil.write(byte);
    25. fil.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by Askar; 30th September 2009 at 14:54.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Quote Originally Posted by Askar View Post
    now i gave the complete code for retrieving data from remote sql server & parsing the retrieved xml file.
    You could have done that 12 posts ago...

    Are you sure "photo" is an attribute and not an element?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    ya sure............

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    What does this return?
    Qt Code:
    1. qDebug("%d", wBData1.size());
    2. qDebug("%d", byte.size());
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    wBData1.size() returns-----------12
    byte.size() returns------------------7

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Somehow I doubt you can fit an image with all its headers in 7 bytes...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    dear Wysota,

    while inserting binary value into the remote server database table with the following code

    Qt Code:
    1. QString str;
    2. QFile fileIn ("Sunset.jpg");
    3. QByteArray wBData;
    4. net = new QNetworkAccessManager();
    5. if (fileIn.open (QIODevice::ReadOnly))
    6. {
    7. wBData.append(fileIn.readAll());
    8.  
    9. }
    10. qDebug()<<wBData.size(); //returns 59129
    11. str.append(wBData)
    12. net.get("http://192.168.0.220/clancor?sql=insert+into+blob+(sno,photo)+values+(4 ,'"+ str +"')&root=blobinsert"
    To copy to clipboard, switch view to plain text mode 

    qDebug returns value 59129

    but while retrieving same binary data value from remote server qdebug returns

    wBData1.size() returns-----------12
    byte.size() returns------------------7

    which is entered in the previous thread

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    What's the whole xml you get from the server? Also how do you know the image is stored correctly? You are not encoding the data here anywhere...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 19th September 2009, 07:07
  2. Replies: 0
    Last Post: 14th September 2009, 11:57
  3. Replies: 2
    Last Post: 14th September 2009, 08:31

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.