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

QSqlResultPrivate::positionalToNamedBinding() and QSqlResultPrivate::namedToPositionalBinding() don't handle double quote into sql's

    XMLWordPrintable

Details

    Description

      QSqlResultPrivate::positionalToNamedBinding() and QSqlResultPrivate::namedToPositionalBinding() don't handle double quote into sql's

      Ex.:

      QSqlQuery l_qry;

      l_qry.prepare("SELECT :a + :b as \".:My sum:.\"");
      l_qry.bind(":a", 2);
      l_qry.bind(":b", 2);
      // internaly the ':My' and ':.' have pending bind
      l_qry.exec();

      qDebug() << l_qry.record().fieldName(0); // Prints: ".? Sum?"

      Path to solve:
      — a/src/sql/kernel/qsqlresult.cpp
      +++ b/src/sql/kernel/qsqlresult.cpp
      @@ -154,15 +154,18 @@ QString QSqlResultPrivate::positionalToNamedBinding()
      QString result;
      result.reserve(n * 5 / 4);
      bool inQuote = false;
      + bool inDoubleQuote = false;
      int count = 0;

      for (int i = 0; i < n; ++i) {
      QChar ch = sql.at;

      • if (ch == QLatin1Char('?') && !inQuote)
        Unknown macro: {+ if (ch == QLatin1Char('?') && !inQuote && !inDoubleQuote) { result += qFieldSerial(count++); } else { - if (ch == QLatin1Char('\'')) + if (!inDoubleQuote && ch == QLatin1Char('\'')) inQuote = !inQuote; + if (!inQuote && ch == QLatin1Char('\"')) + inDoubleQuote = !inDoubleQuote; result += ch; } }

        @@ -177,23 +180,27 @@ QString QSqlResultPrivate::namedToPositionalBinding()
        QString result;
        result.reserve;
        bool inQuote = false;
        + bool inDoubleQuote = false;
        int count = 0;
        int i = 0;

      while (i < n) {
      QChar ch = sql.at;

      • if (ch == QLatin1Char(':') && !inQuote
        + if (ch == QLatin1Char(':') && !inQuote && !inDoubleQuote
        && (i == 0 || sql.at(i - 1) != QLatin1Char(':'))
        && (i + 1 < n && qIsAlnum(sql.at(i + 1)))) { int pos = i + 2; while (pos < n && qIsAlnum(sql.at(pos))) ++pos; - indexes[sql.mid(i, pos - i)] = count++; + indexes.insertMulti(sql.mid(i, pos - i), count); + count++; result += QLatin1Char('?'); i = pos; }

        else

        { - if (ch == QLatin1Char('\'')) + if (!inDoubleQuote && ch == QLatin1Char('\'')) inQuote = !inQuote; + if (!inQuote && ch == QLatin1Char('\"')) + inDoubleQuote = !inDoubleQuote; result += ch; ++i; }

      Attachments

        For Gerrit Dashboard: QTBUG-27159
        # Subject Branch Project Status CR V

        Activity

          People

            israelins85 Israel Lins Albuquerque
            israelins85 Israel Lins Albuquerque
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes