QSql, how to insert blob
Solved
General and Desktop
-
wrote on 31 May 2021, 06:42 last edited by
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?
-
wrote on 31 May 2021, 06:56 last edited by
Solved:
- Allocate the memory for the character buffer, read into buffer
- Using length return from readRawData iterate through the buffer and append to an instance of QByteArray.
- Using addBinaryValue pass the byte array with second parameter set to QSql::Binary.
This works.
-
Blob = QByteArray
-
wrote on 31 May 2021, 06:56 last edited by
Solved:
- Allocate the memory for the character buffer, read into buffer
- Using length return from readRawData iterate through the buffer and append to an instance of QByteArray.
- Using addBinaryValue pass the byte array with second parameter set to QSql::Binary.
This works.
1/3