Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSql, how to insert blob



  • 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?



  • 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.


  • Lifetime Qt Champion

    Blob = QByteArray



  • 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.


Log in to reply