Receiving multiple result sets of return value in SQL server stored procedure from Qt (QSqlQuery)
-
rInf
seems to be where the results are stored. -
@SGaist Yes, It seems following code is saving the results:
retcode=SQLNumResultCols(d->hStmt, &columns); qDebug() << "cols: " << columns; if (columns) { setSelect(true); for (int i = 0; i < columns; ++i) { d->rInf.append(qMakeFieldInfo(d, i)); } d->fieldCache.resize(columns); } else { setSelect(false); } setActive(true);
It creates some FieldInfo and appends them into QSqlRecord. But It just save some data like column names not the data (rows).
Also note that when SQLMoreResults and SQLFetch is called from my newly added code, all the table data are cleared in the buffer! but the problem with return values is fixed too!, so there no table data anymore in QSqlQuery object. So confused!
What I'm seeking now is how to store the table data (that I'm now getting from buffer in new added code) into QSqlQuery, so that the developer can get it by calling QSqlQuery::value, QSqlQuery::first and other methods. It doesn't seems to be very hard, but I'm not very familiar with how those data are stored (seems they are saving in some shared memory).
-
I'd look at
nextResult
which is likely the place that is going to load data from the query made. -
I'm not sure I'm following you on that one, can you clarify what you did ?
-
Sorry, I'm a bit late to the party. But http://doc.qt.io/qt-5/qsqlquery.html#nextResult is indeed, and always been, the way you move across multiple result sets (assuming your database supports them). Even in my non-Qt work with MS SQL Server this was how it worked there too.
-
So in the end, did you had to modify the driver for your stored procedure ?
-
So just looping with
QSqlQuery::next
got you the result of the stored procedure as expected ? -
@SGaist I did it this way for reading return params:
Query.nextResult(); // after reading table values //Get Return Parameter for (int i=0; i<CountReturnParam; i++) { qDebug() << QString("Returnparam %1 = %2") .arg(i).arg(Query.boundValue(i).toString()); }