PDA

View Full Version : QSqlTableModel submitAll access query



patrik08
26th April 2007, 21:59
i have subclass a QTableView to display row limit ... and is model model->setEditStrategy(QSqlTableModel::OnManualSubmit);

How i can access last query to update the 2° database back-up to?





/* save all DirtySQL true value and reset DirtySQL to false */
void Mysql_Table::BigCommit()
{
if (model->submitAll()) {
model->database().commit();
DirtySQL = false;
emit ModelError(true);
return;
} else {
model->database().rollback();

if (!haveindex) {
QMessageBox::warning(0, tr("Table %1 ").arg(table),
tr("The database reported an error: %1\nAnd table not having index!").arg(model->lastError().text()));
} else {
QMessageBox::warning(0, tr("Table %1 ").arg(table),
tr("The database reported an error: %1").arg(model->lastError().text()));
}
emit ModelError(false);
return;
}
}

wysota
26th April 2007, 22:45
Last query of what? An SQL model? Most probably through QSqlQueryModel::query()

patrik08
26th April 2007, 23:05
Last query of what? An SQL model? Most probably through QSqlQueryModel::query()


No the UPDATE Query by submit all..

i found only ONE Way... connect the model an grab all data to construct a sqlquery..
is here no other way?




connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(WakeUpTable(QModelIndex,QModelIndex)));

void Mysql_Table::WakeUpTable(const QModelIndex & a , const QModelIndex & b )
{
if (a.isValid() && b.isValid()) {

if (model->isDirty(a) && model->isDirty(b)) {
/* user mods data set new wath? */
const QString fieldnametouch = FieldNameList.at(a.column());
const QString indexfieldname = INDEXFIELD; /* discovery on SHOW COLUMNS FROM table + make qstringlist FieldNameList */

DirtySQL = true;
if (INDEXFIELD.size() > 0) {
/* QModelIndex index field */
QModelIndex base = a.sibling(a.row(),indexcolumn);
/* Prepare Dirty sqlupdate */
const QString pending = QString("UPDATE %1 SET %2='%3' WHERE %4='%5' LIMIT 1")
.arg(table)
.arg(fieldnametouch)
.arg(a.data().toString())
.arg(INDEXFIELD)
.arg(base.data(Qt::DisplayRole).toString());
/* append on a list wakeup on submit ... */
DirtyPendingQuery.append(pending);
qDebug() << "### Pendingsql one line " << pending;
qDebug() << "### WakeUpTable " << table << " fieldname active " << fieldnametouch << " - "
<< a.data().toString() << " - " << a.row()
<< "x" << a.column() << " on " << base.data(Qt::DisplayRole).toString();
}
}
}

}

wysota
27th April 2007, 00:33
If you submit ALL, then obviously ALL rows are submitted, so the query is easy to guess. I don't really see what you're trying to do... If you want only dirty rows to be submited then simply subclass the model, store somewhere a list of dirty rows and update them manually.

patrik08
27th April 2007, 08:04
If you submit ALL, then obviously ALL rows are submitted, so the query is easy to guess. I don't really see what you're trying to do... If you want only dirty rows to be submited then simply subclass the model, store somewhere a list of dirty rows and update them manually.

I have two DB MYSQL connection, one db1 on Lan to fast select data 150'000 user adress 2GB data, other db2 on server outside an this db2 receive only update query.. from outside.

Model work only on db1, i can not connect model on two db connection. Also i must put on cache each query and at end sumbit all on db2.

Moreover it has also sense, to have a query log from user, to grab or discovery mistake update by so mach data.