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. How to store binary data to SQL database as nvarbinary?
Forum Updated to NodeBB v4.3 + New Features

How to store binary data to SQL database as nvarbinary?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    qingyun
    wrote on 25 Oct 2013, 15:26 last edited by
    #1

    Hi,

    I need to store some files to SQL Server database, such as word, excel and pictures. I tried to read binary file data to a QByteArray, but the file contains lots of '\0' byte and this is regarded as the end of the array, so when the QByteArray object can only store a small part of the file, not all the data.
    I think I should first read file into a buffer and then insert the buffer's content to database, but i don't know how to do this use a QSqlQuery, can anybody help me, thanks!

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Oct 2013, 19:08 last edited by
      #2

      Hi,

      You can use base64 encoding for you binary data

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qingyun
        wrote on 26 Oct 2013, 01:41 last edited by
        #3

        Can you tell a lit more please, or giev me a link about this?
        I should still use QByteArray to do this, or use other method?

        [quote author="SGaist" date="1382728116"]Hi,

        You can use base64 encoding for you binary data

        Hope it helps[/quote]

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qingyun
          wrote on 26 Oct 2013, 01:47 last edited by
          #4

          I saw this function:
          ByteArray QByteArray::fromBase64(const QByteArray & base64);

          This needs another QByteArray, and the question still exsits. The input QByteArray will be truncated, and only the part before the first '\0' will be copied to the new QByteArray.

          [quote author="SGaist" date="1382728116"]Hi,

          You can use base64 encoding for you binary data

          Hope it helps[/quote]

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 14 Nov 2013, 21:16 last edited by
            #5

            IIRC, QByteArray handles \0 like any other char, you can verify the size of the array once loaded

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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