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

QSqlRelationalTableModel doesn't correctly work with relation in other database schema

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 4.6.1
    • 4.6.0
    • SQL Support
    • None
    • e127806a53e445df165ef1021e9c3d9029fbcac2

    Description

      QSqlRelationalTableModel doesn't correctly work with relation in other database schema.
      It is a bug in QString QSqlRelationalTableModel::selectStatement() const.
      I use QSqlRelationalTableModel and want to set relation to the field.
      But relational table is in the other database schema such this "docob.user" and I set relation like:
      model->setRelation(index, QSqlRelation("docob.user");

      In your implementation of QSqlRelationalTableModel::selectStatement() if there are more than 1 field names it generates select statement where douplicates have namespaces such this: " AS user_name " but in my case it will be "AS docob.user_name". Database gives me an error on this statement.

      I suggest to qoutate such namespaces such this:

      QString QSqlRelationalTableModel::selectStatement() const
      {
      .....................
                 // If there are duplicate field names they must be aliased
                  if (fieldNames.value(fieldList[i]) > 1) {
                      QString relTableName = relation.tableName();
                      if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName))
                          relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName);
                      QString displayColumn = relation.displayColumn();
                      if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName))
                          displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);
      		fList.append(QString::fromLatin1(" AS \"%1_%2_%3\"").arg(rec.fieldName(i)).arg(relation.tableName()).arg(relation.displayColumn()));
                  } 
      ..................
      } //code from 4.6 version
      

      Attachments

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

        Activity

          People

            bilking Bill King
            cdsmika Tseluyko Dmitriy
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes