summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2009-09-14 06:45:26 (GMT)
committerBill King <bill.king@nokia.com>2009-09-14 23:10:44 (GMT)
commite6f191185d0a80ced3434a8b378b139386c43760 (patch)
tree25dbfbdd53c05fdbc91956de98b5855604648fe5 /src/sql
parentb2d7bcf1e77e8b9bc8fc1b40777907d7a8d47c09 (diff)
downloadQt-e6f191185d0a80ced3434a8b378b139386c43760.zip
Qt-e6f191185d0a80ced3434a8b378b139386c43760.tar.gz
Qt-e6f191185d0a80ced3434a8b378b139386c43760.tar.bz2
Fixes QSqlTableModel: trying to delete the wrong row.
Uses the primary key from the index in the query, not the resulting location in the modified dataset. Task-number: 222678
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/models/qsqltablemodel.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index a532449..a91dc9f 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -559,7 +559,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
if (row.op == QSqlTableModelPrivate::None) {
row.op = QSqlTableModelPrivate::Update;
row.rec = d->rec;
- row.primaryValues = d->primaryValues(indexInQuery(index).row());
+ row.primaryValues = d->primaryValues(indexInQuery(index).row());
}
row.rec.setValue(index.column(), value);
emit dataChanged(index, index);
@@ -669,7 +669,7 @@ bool QSqlTableModel::deleteRowFromTable(int row)
Q_D(QSqlTableModel);
emit beforeDelete(row);
- QSqlRecord rec = d->primaryValues(row);
+ const QSqlRecord whereValues = d->strategy == OnManualSubmit ? d->cache[row].primaryValues : d->primaryValues(row);
bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement,
d->tableName,
@@ -677,7 +677,7 @@ bool QSqlTableModel::deleteRowFromTable(int row)
prepStatement);
QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement,
d->tableName,
- rec,
+ whereValues,
prepStatement);
if (stmt.isEmpty() || where.isEmpty()) {
@@ -687,7 +687,7 @@ bool QSqlTableModel::deleteRowFromTable(int row)
}
stmt.append(QLatin1Char(' ')).append(where);
- return d->exec(stmt, prepStatement, rec);
+ return d->exec(stmt, prepStatement, whereValues);
}
/*!
@@ -1097,6 +1097,7 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
revertRow(idx);
else {
d->cache[idx].op = QSqlTableModelPrivate::Delete;
+ d->cache[idx].primaryValues = d->primaryValues(indexInQuery(createIndex(idx, 0)).row());
emit headerDataChanged(Qt::Vertical, idx, idx);
}
}