Results 1 to 4 of 4

Thread: QSqlRelationalTableModel produces useless Sql statement

  1. #1
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 2 Times in 2 Posts

    Default QSqlRelationalTableModel produces useless Sql statement

    Hi everybody,

    I have a problem with the QSqlRelationalTableModel.
    I have the following code:

    Qt Code:
    1. patientModel = new QSqlRelationalTableModel(this, myDb);
    2. patientModel->setTable("PATIENTEN");
    3. patientModel->setRelation(patientModel->fieldIndex("ANGELEGTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ")); /*created by*/
    4. patientModel->setRelation(patientModel->fieldIndex("GEAENDERTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*changed by*/
    5. patientModel->setRelation(patientModel->fieldIndex("BEHANDLER"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*doctor*/
    6. patientModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    7. if (PatId > 0)
    8. patientModel->setFilter(QString ("PATIENTEN.PK_ID = %1").arg(m_PatId));
    9. patientModel->select();
    To copy to clipboard, switch view to plain text mode 

    When I call patientModel->select()then, QSqlRelationalTableModel produces the following Sql statement:

    Qt Code:
    1. SELECT
    2. PATIENTEN."PK_ID", PATIENTEN."VORNAME", PATIENTEN."NACHNAME", ...
    3. relTblAl_10.KRZ AS BENUTZER_KRZ_3,
    4. relTblAl_12.KRZ AS BENUTZER_KRZ_2,
    5. relTblAl_16.KRZ, ...
    6. FROM
    7. PATIENTEN, BENUTZER relTblAl_10, BENUTZER relTblAl_12, BENUTZER relTblAl_16
    8. WHERE
    9. (PATIENTEN."BEHANDLER" = relTblAl_10.PK_ID AND
    10. PATIENTEN."GEAENDERTVON" = relTblAl_12.PK_ID AND
    11. PATIENTEN."ANGELEGTVON" = relTblAl_16.PK_ID) AND
    12. (PATIENTEN.PK_ID = 2678)
    To copy to clipboard, switch view to plain text mode 

    It seems correct, but it doesn't work most of the time, because "GEAENDERTVON" (e.g. "changed by") is most of the time NULL and the result set is empty.
    The correct way would be a LEFT OUTER JOIN.

    Is this a bug or am I missing something?

    Thanks in advance.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QSqlRelationalTableModel produces useless Sql statement

    This is not a bug and You don't missing something. QSqlRelationalTableModel is as is.

  3. #3
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 2 Times in 2 Posts

    Default Re: QSqlRelationalTableModel produces useless Sql statement

    Quote Originally Posted by Lesiok View Post
    This is not a bug and You don't missing something. QSqlRelationalTableModel is as is.
    Thanks for your reply, Lesiok.

    If you ask me, it's a bug. Or at least there's a lack of implementation.
    What is QSqlRelationalTableModel good for, if it can not handle NULL foreign keys.

    Wouldn' you agree?
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QSqlRelationalTableModel produces useless Sql statement

    This is a lack of implementation. So we have our SqlRelationalModel.

Similar Threads

  1. QWizard produces SIGILL
    By lauwe in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2011, 19:46
  2. QPainter::drawPixmap always produces black on windows?
    By spbots in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 16:42
  3. Useless but curious compiler warning question
    By Raccoon29 in forum General Programming
    Replies: 4
    Last Post: 30th July 2008, 20:46
  4. Designer produces invalid code?
    By Tiansen in forum Qt Programming
    Replies: 7
    Last Post: 4th March 2008, 11:43
  5. QTextEdit produces incorrect html
    By ccf_h in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2006, 15:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.