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

Avoiding sp_cursorfetch with QSqlxxxx



  • I have an app that uses a QSqlDatabase connecting to an MS SQL Server through ODBC.
    I noticed, that all classes available for data retrieval (like QSqlQuery, QSqlQueryModel, QSqlTableModel) use sp_cursorfetch.

    Isn't there a way to just retrieve the whole table at once, or at least specify the batch size?
    I'm trying to do some processing on each row of the data, and I end up making too many calls to the database
    ie.

    • if I use QSqlQuery.next(), I get a call to the database every time I call next()
    • if I use QSqlQueryModel I have to use something like: while canFetchMore() fetchMore in order to get the data (which is again numerous calls to the database)


  • Are you sure QSqlQuery.next() get a call to the database? I think next() retrieve the next row from a prevent exec()



  • Yes, I am very sure....
    I get a call for every next() call.
    The output from SQL Server profiler is like this:

    1) exec sp_cursoropen ....

    2) exec sp_cursorfetch 180150003,1,0,1

    3) exec sp_cursor 180150003,40,1

    4) Repeat 2) and 3) for each record returned by the query


Log in to reply