Hello Mark,
Post by Mark BrandPost by Petric Franki ran into an issue using transactions together with QSqlTableModel.
Whenever i do a "QSqlDatabase::rollback ()" the QSqlTableModel internal
buffer is not updated to reflect this. So it still shows the data before
the rollback.
I'm not sure whether your "internal buffer" refers to caching of query
results or edited rows.
The latter one. Submit policy actually is kept default which is, if i remember
correctly, going after rows.
Post by Mark BrandQSqlTableModel doesn't cache the query results.
It's base class QSqlQueryModel just provides a model interface to
QSqlQuery which wraps QSqlResult. QSqlResult has a driver-specific
implementation that may or may not cache locally. QSqlTableModel does
cache edited rows however.
This is the culprit. I have several views on it. If i start a transaction, do
an edit (without submit) and a rollback the other views still show the edited
value before rollback.
Calling revert(All) exits the program an "vector indes out of range". A call
to select exhibits the same behavior (as it does - as far as know - also call
revert(All) internally).
Post by Mark BrandPost by Petric FrankIs there a signal or other method to detect a rollback ?
This allows me to re-load the tables and views.
There is no general automatic mechanism to refresh queries when the
database changes. Your application will have to do this. Probably you
will want to call QSqlTableModel::select() to refresh when necessary.
This resets the model and view and reverts all unsubmitted edits. You
might be able to use QSqlDriver notifications to detect database changes
if the driver you are using supports them.
The last knowledge i have (from Qt 4.4 era) is that the mysql driver does not
support it.
Post by Mark BrandPost by Petric FrankNB.: If i do a revert or select call on QSqlDatabase having un-submitted
data after the rollback i get a 'Vector index out of range' trap from
inside the qt-lib. This might be a coding error of me. But if anyone has
a similar experience and could give me a helping hand ...
I am actually on the way of tracking down this issue.
I currently use Qt 4.8.4 and gcc 4.5.4 on Linux (x86_64).
The database server is MariaDB 5.5.23
The scenario you describe is not completely clear to me. If you can
reproduce and isolate the problem, it would probably be best to file a
bug report, preferably with a simple demo.
Will do. Somewhere inside the QSortFilterProxyModel/dataChanged it accesses a
column too far (table has 15 columns, the vector index used is 15 - one too
much).
At the moment i have a workaround. Calling submit(All) before rollback allows
me to do a select call after the rollback without aborting the program.
Post by Mark BrandPost by Petric FrankAre there any hints ?
I recommend using Qt 5 if possible. There are significant behavior
changes in QSqlTableModel that might be of benefit, and you can avoid
the extra work of porting your application to Qt 5 later.
Its on my task list. Due the program should also run on windows platforms i
need to have one ready. At the moment i have problems establishing an
installation on Windows (32/64 Bit) using the MinGW compiler. Currently there
is no downloadable Qt5 installation pack at digia for MinGW - only one for the
VS compiler.
<dream on>If it comes bundled with the Mysql/MariaDB client lib released by
MariaDB under LGPL i woud be happy. No more need to install the source on
windows only to compile the plugin</dream off>
regards
Petric