QJsonArray populated but not written to database?
-
I have a table structure in MariaDB which one of the fields is using the JSON field type. I've used this before without any problem.
I am reading binary data from a large file and writing it in 512 byte chunks to the database first converting to a QJsonArray.
I can see in the debugger that the array is populated before writing and does contain 512 items.
I am using stored procedures to avoid any syntax issues using prepared stored procedures. My procedure addBlock, which I call with 3 parameters:
QSqlQuery queryBlock; queryBlock.prepare("CALL addBlock(?,?,?);"); queryBlock.addBindValue(crstrFilename); queryBlock.addBindValue(muint16Block); queryBlock.addBindValue(aryData); Trainer::queryDB(queryBlock);crstrFilename is a const QString containing a fullpath and name of a file.
muint16Block is an quint16 which is incremented on every call.
aryData is an instance of QJsonArray which is populated and contains 512 items.
queryDB is my function that performs the DB query and manages any errors, of which they're are none.As a result of calling this procedure I can see many records during the operation inserted and the block increments for each, but the JSON data appears to be empty.
Why?
-
I have a table structure in MariaDB which one of the fields is using the JSON field type. I've used this before without any problem.
I am reading binary data from a large file and writing it in 512 byte chunks to the database first converting to a QJsonArray.
I can see in the debugger that the array is populated before writing and does contain 512 items.
I am using stored procedures to avoid any syntax issues using prepared stored procedures. My procedure addBlock, which I call with 3 parameters:
QSqlQuery queryBlock; queryBlock.prepare("CALL addBlock(?,?,?);"); queryBlock.addBindValue(crstrFilename); queryBlock.addBindValue(muint16Block); queryBlock.addBindValue(aryData); Trainer::queryDB(queryBlock);crstrFilename is a const QString containing a fullpath and name of a file.
muint16Block is an quint16 which is incremented on every call.
aryData is an instance of QJsonArray which is populated and contains 512 items.
queryDB is my function that performs the DB query and manages any errors, of which they're are none.As a result of calling this procedure I can see many records during the operation inserted and the block increments for each, but the JSON data appears to be empty.
Why?
@SPlatten said in QJsonArray populated but not written to database?:
queryBlock.addBindValue(aryData);
QJsonArrayis not a valid type forQSqlQuery::addBindValue().
I would suggest you to convert it to QString, this should work:QJsonDocument doc; doc.setArray(aryData); queryBlock.addBindValue(doc.toJson(QJsonDocument::Compact)); -
@SPlatten said in QJsonArray populated but not written to database?:
queryBlock.addBindValue(aryData);
QJsonArrayis not a valid type forQSqlQuery::addBindValue().
I would suggest you to convert it to QString, this should work:QJsonDocument doc; doc.setArray(aryData); queryBlock.addBindValue(doc.toJson(QJsonDocument::Compact));@KroMignon , thank you and thats exactly what I did elsewhere, just forgot.