summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2009-09-14 23:59:35 (GMT)
committerBill King <bill.king@nokia.com>2009-09-14 23:59:35 (GMT)
commitd94f6a35202d2d62671072b4ba78e75b07d630bd (patch)
tree0e2f8dd8a91267bc22e0f182a0ab829bc4032c7d
parenta1d6c4e508cb2ea9a2d33d4f197da416c3f492c8 (diff)
parente6f191185d0a80ced3434a8b378b139386c43760 (diff)
downloadQt-d94f6a35202d2d62671072b4ba78e75b07d630bd.zip
Qt-d94f6a35202d2d62671072b4ba78e75b07d630bd.tar.gz
Qt-d94f6a35202d2d62671072b4ba78e75b07d630bd.tar.bz2
Merge commit 'origin/4.5' into 4.6
-rw-r--r--src/sql/drivers/ibase/qsql_ibase.cpp3
-rw-r--r--src/sql/models/qsqltablemodel.cpp9
-rw-r--r--tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp61
3 files changed, 69 insertions, 4 deletions
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp
index b0ba8cd..bc425fc 100644
--- a/src/sql/drivers/ibase/qsql_ibase.cpp
+++ b/src/sql/drivers/ibase/qsql_ibase.cpp
@@ -1296,6 +1296,9 @@ int QIBaseResult::numRowsAffected()
case isc_info_sql_stmt_insert:
cCountType = isc_info_req_insert_count;
break;
+ default:
+ qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")";
+ return -1;
}
char acBuffer[33];
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index eeb250d..df94080 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);
}
/*!
@@ -1099,6 +1099,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);
}
}
diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
index 75b5190..073afae 100644
--- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -119,6 +119,11 @@ private slots:
void tableModifyWithBlank_data() { generic_data(); }
void tableModifyWithBlank(); // For mail task
+ void removeColumnAndRow_data() { generic_data(); }
+ void removeColumnAndRow(); // task 256032
+
+ void insertBeforeDelete_data() { generic_data(); }
+ void insertBeforeDelete();
private:
void generic_data(const QString& engine=QString());
};
@@ -989,5 +994,61 @@ void tst_QSqlTableModel::tableModifyWithBlank()
QCOMPARE(model.record(0).value(1).toString(), QLatin1String("col1ModelData"));
}
+void tst_QSqlTableModel::removeColumnAndRow()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ QSqlTableModel model(0, db);
+ model.setTable(qTableName("test"));
+ model.setEditStrategy(QSqlTableModel::OnManualSubmit);
+ QVERIFY_SQL(model, select());
+ QCOMPARE(model.rowCount(), 3);
+ QCOMPARE(model.columnCount(), 3);
+
+ QVERIFY(model.removeColumn(0));
+ QVERIFY(model.removeRow(0));
+ QVERIFY(model.submitAll());
+ QCOMPARE(model.rowCount(), 2);
+ QCOMPARE(model.columnCount(), 2);
+
+ // check with another table because the model has been modified
+ // but not the sql table
+ QSqlTableModel model2(0, db);
+ model2.setTable(qTableName("test"));
+ QVERIFY_SQL(model2, select());
+ QCOMPARE(model2.rowCount(), 2);
+ QCOMPARE(model2.columnCount(), 3);
+}
+
+void tst_QSqlTableModel::insertBeforeDelete()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ QSqlQuery q(db);
+ QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(9, 'andrew', 9)"));
+ QVERIFY_SQL( q, exec("insert into " + qTableName("test") + " values(10, 'justin', 10)"));
+
+ QSqlTableModel model(0, db);
+ model.setTable(qTableName("test"));
+ model.setEditStrategy(QSqlTableModel::OnManualSubmit);
+ QVERIFY_SQL(model, select());
+
+ qDebug() << model.rowCount();
+
+ QSqlRecord rec = model.record();
+ rec.setValue(0, 4);
+ rec.setValue(1, QString("bill"));
+ rec.setValue(2, 4);
+ QVERIFY_SQL(model, insertRecord(4, rec));
+
+ QVERIFY_SQL(model, removeRow(5));
+ QVERIFY_SQL(model, submitAll());
+ QCOMPARE(model.rowCount(), 5);
+}
+
QTEST_MAIN(tst_QSqlTableModel)
#include "tst_qsqltablemodel.moc"