ObiWanKenobe
25th October 2011, 21:14
Hi everybody,
I have a problem with the QSqlRelationalTableModel.
I have the following code:
patientModel = new QSqlRelationalTableModel(this, myDb);
patientModel->setTable("PATIENTEN");
patientModel->setRelation(patientModel->fieldIndex("ANGELEGTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ")); /*created by*/
patientModel->setRelation(patientModel->fieldIndex("GEAENDERTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*changed by*/
patientModel->setRelation(patientModel->fieldIndex("BEHANDLER"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*doctor*/
patientModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (PatId > 0)
patientModel->setFilter(QString ("PATIENTEN.PK_ID = %1").arg(m_PatId));
patientModel->select();
When I call patientModel->select()then, QSqlRelationalTableModel produces the following Sql statement:
SELECT
PATIENTEN."PK_ID", PATIENTEN."VORNAME", PATIENTEN."NACHNAME", ...
relTblAl_10.KRZ AS BENUTZER_KRZ_3,
relTblAl_12.KRZ AS BENUTZER_KRZ_2,
relTblAl_16.KRZ, ...
FROM
PATIENTEN, BENUTZER relTblAl_10, BENUTZER relTblAl_12, BENUTZER relTblAl_16
WHERE
(PATIENTEN."BEHANDLER" = relTblAl_10.PK_ID AND
PATIENTEN."GEAENDERTVON" = relTblAl_12.PK_ID AND
PATIENTEN."ANGELEGTVON" = relTblAl_16.PK_ID) AND
(PATIENTEN.PK_ID = 2678)
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.
I have a problem with the QSqlRelationalTableModel.
I have the following code:
patientModel = new QSqlRelationalTableModel(this, myDb);
patientModel->setTable("PATIENTEN");
patientModel->setRelation(patientModel->fieldIndex("ANGELEGTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ")); /*created by*/
patientModel->setRelation(patientModel->fieldIndex("GEAENDERTVON"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*changed by*/
patientModel->setRelation(patientModel->fieldIndex("BEHANDLER"), QSqlRelation("BENUTZER", "PK_ID", "KRZ"));/*doctor*/
patientModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (PatId > 0)
patientModel->setFilter(QString ("PATIENTEN.PK_ID = %1").arg(m_PatId));
patientModel->select();
When I call patientModel->select()then, QSqlRelationalTableModel produces the following Sql statement:
SELECT
PATIENTEN."PK_ID", PATIENTEN."VORNAME", PATIENTEN."NACHNAME", ...
relTblAl_10.KRZ AS BENUTZER_KRZ_3,
relTblAl_12.KRZ AS BENUTZER_KRZ_2,
relTblAl_16.KRZ, ...
FROM
PATIENTEN, BENUTZER relTblAl_10, BENUTZER relTblAl_12, BENUTZER relTblAl_16
WHERE
(PATIENTEN."BEHANDLER" = relTblAl_10.PK_ID AND
PATIENTEN."GEAENDERTVON" = relTblAl_12.PK_ID AND
PATIENTEN."ANGELEGTVON" = relTblAl_16.PK_ID) AND
(PATIENTEN.PK_ID = 2678)
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.