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?
Qt 6.11 is out! See what's new in the release blog

How to store binary data to SQL database as nvarbinary?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.6k 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 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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 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 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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