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. QSql, how to insert blob
Forum Updated to NodeBB v4.3 + New Features

QSql, how to insert blob

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 457 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I am using MariaDB 10.5, I have written a stored procedure which accepts a BLOB, the table that it will be inserted into has a BLOB field.

    The question is how do I correctly pass a BLOB to the stored procedure? I'm using Qt 5.9.2 with QSqlQuery.

    So far I've tried passing a pointer to an allocated area of memory of the same size as the binary data read from the file, but I don't think this is correct, how can the stored procedure know how much data is being passed from just a pointer?

    I then found online NOT Qt specific where the data is read into an Input Stream object, and the input stream object passed as the parameter which makes more sense.

    Can anyone help with this?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #3

      Solved:

      1. Allocate the memory for the character buffer, read into buffer
      2. Using length return from readRawData iterate through the buffer and append to an instance of QByteArray.
      3. Using addBinaryValue pass the byte array with second parameter set to QSql::Binary.

      This works.

      Kind Regards,
      Sy

      1 Reply Last reply
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Blob = QByteArray

        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
        3
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          Solved:

          1. Allocate the memory for the character buffer, read into buffer
          2. Using length return from readRawData iterate through the buffer and append to an instance of QByteArray.
          3. Using addBinaryValue pass the byte array with second parameter set to QSql::Binary.

          This works.

          Kind Regards,
          Sy

          1 Reply Last reply
          1

          • Login

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