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. Receiving multiple result sets of return value in SQL server stored procedure from Qt (QSqlQuery)

Receiving multiple result sets of return value in SQL server stored procedure from Qt (QSqlQuery)

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlqueryodbcqodbcsqlserverqsqldatabase
17 Posts 3 Posters 4.9k Views
  • 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.
  • S SGaist
    12 Nov 2018, 23:00

    rInf seems to be where the results are stored.

    A Offline
    A Offline
    alizadeh91
    wrote on 13 Nov 2018, 06:00 last edited by alizadeh91
    #7

    @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).

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Nov 2018, 22:20 last edited by
      #8

      I'd look at nextResult which is likely the place that is going to load data from the query made.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 15 Nov 2018, 07:22
      1
      • S SGaist
        14 Nov 2018, 22:20

        I'd look at nextResult which is likely the place that is going to load data from the query made.

        A Offline
        A Offline
        alizadeh91
        wrote on 15 Nov 2018, 07:22 last edited by
        #9

        @SGaist Yesss! calling it solved my problem. Thanks :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 15 Nov 2018, 08:00 last edited by
          #10

          I'm not sure I'm following you on that one, can you clarify what you did ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 15 Nov 2018, 19:56
          0
          • J Offline
            J Offline
            JonB
            wrote on 15 Nov 2018, 08:19 last edited by JonB
            #11

            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.

            A 1 Reply Last reply 15 Nov 2018, 19:58
            1
            • S SGaist
              15 Nov 2018, 08:00

              I'm not sure I'm following you on that one, can you clarify what you did ?

              A Offline
              A Offline
              alizadeh91
              wrote on 15 Nov 2018, 19:56 last edited by
              #12

              @SGaist I've just called QSQLQuery::nextResult after executing and reading dataTable. Then I was able to read another result sets.

              1 Reply Last reply
              0
              • J JonB
                15 Nov 2018, 08:19

                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.

                A Offline
                A Offline
                alizadeh91
                wrote on 15 Nov 2018, 19:58 last edited by
                #13

                @JonB Yes, I was not familiar with that. Also in QSqlQuery doc, there was some disappointing states that the multiple result sets might not be supported.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 15 Nov 2018, 20:11 last edited by
                  #14

                  So in the end, did you had to modify the driver for your stored procedure ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply 15 Nov 2018, 20:20
                  0
                  • S SGaist
                    15 Nov 2018, 20:11

                    So in the end, did you had to modify the driver for your stored procedure ?

                    A Offline
                    A Offline
                    alizadeh91
                    wrote on 15 Nov 2018, 20:20 last edited by
                    #15

                    @SGaist Not at all.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 15 Nov 2018, 20:43 last edited by
                      #16

                      So just looping with QSqlQuery::next got you the result of the stored procedure as expected ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply 16 Nov 2018, 05:27
                      0
                      • S SGaist
                        15 Nov 2018, 20:43

                        So just looping with QSqlQuery::next got you the result of the stored procedure as expected ?

                        A Offline
                        A Offline
                        alizadeh91
                        wrote on 16 Nov 2018, 05:27 last edited by
                        #17

                        @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());
                                         }
                        
                        1 Reply Last reply
                        0

                        16/17

                        15 Nov 2018, 20:43

                        • Login

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