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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6.2.0
    • Fix Version/s: None
    • Component/s: SQL Support
    • Labels:
      None
    • Platform/s:
      All

      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

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

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes