Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97847

How to recreate full SQL query in Qt 6 (removed feature?!!!!)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6.0
    • 6.2.0
    • SQL Support
    • None
    • All
    • 3983babd7 (dev)

    Description

      You have some prepared SQL statement and calling "QSqlQuery::last(executed)Query()" does not return the actual "live" SQL statement (with bound values applied).

      In Qt 5 there was a way to re-create the actual SQL statement sent to server:

      QString DatabaseFactory::lastExecutedQuery(const QSqlQuery& query) {
        QString str = query.lastQuery();
        QMapIterator<QString, QVariant> it(query.boundValues());
      
        while (it.hasNext()) {
          it.next();
      
          if (it.value().type() == QVariant::Type::Char ||
              it.value().type() == QVariant::Type::String) {
            str.replace(it.key(), QSL("'%1'").arg(it.value().toString()));
          }
          else {
            str.replace(it.key(), it.value().toString());
          }
        }
      
        return str;
      }
      

      In Qt 6 this is impossible as "boundValues" is not a map anymore.

      How to do the same method with Qt 6?? There is no way to my knowledge.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            skunkos Martin Rotter
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes