QSqlTableModel submitAll access query
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?
Code:
/* 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) {
tr("The database reported an error: %1\nAnd table not having index!").arg(model->lastError().text()));
} else {
tr("The database reported an error: %1").arg(model->lastError().text()));
}
emit ModelError(false);
return;
}
}
Re: QSqlTableModel submitAll access query
Last query of what? An SQL model? Most probably through QSqlQueryModel::query()
Re: QSqlTableModel submitAll access query
Quote:
Originally Posted by
wysota
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?
Code:
{
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 */
/* 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();
}
}
}
}
Re: QSqlTableModel submitAll access query
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.
Re: QSqlTableModel submitAll access query
Quote:
Originally Posted by
wysota
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.