[PyKDE] [PyQt3] problem using a custom QSqlCursor on a QDataTable

Hans-Peter Jansen hpj at urpla.net
Sat Oct 7 12:13:27 BST 2006


Hi Phil,

here's is a nasty problem with using a custom QSqlCursor on a 
QDataTable, I didn't found a workaround yet (other than avoiding this 
all together, which isn't a feasible option here):

Whenever the update() and delRecords() methods on the parent class are 
called, they show recursive behavior, just like (wrongly) calling 
self.update(invalidate) in the custom QSqlCursor class.

Another aspect on this problem is, that QDataTable insists on a 3 arg 
signature when calling sqlCursor().update(), but the base class must be 
called with the 2 arg variant.

Btw: Qt 3.3.6 itself doesn't provide any arguments, as seen in
sql/qdatatable.cpp [around line 1144]:

    case QSql::Yes: {
#ifndef QT_NO_CURSOR
        QApplication::setOverrideCursor( Qt::waitCursor );
#endif
        emit beforeUpdate( d->editBuffer );
        b = sqlCursor()->update();
#ifndef QT_NO_CURSOR
        QApplication::restoreOverrideCursor();
#endif

You find a small self containing script exploring this problem attached.
You may want to adjust the db variables on top of the script beforehand.

Creating the mysql database is done with:
mysql < t.sql
provided, that you have valid access parameter in your .my.cnf client 
section. Beware, this sql script will silently drop a database named t, 
if one exists.

Running qdatatableproblem.py should show you a small table, where 
inserting works as expected, but updating and deleting does not (here 
at least). Some diagnostics are printed on the console.

Any hints fixing this problem are highly appreciated.

TIA,
    Pete

Python version: 2.4
sip version: 4.4.5
Qt version: 3.3.6
PyQt version: 3.16
-------------- next part --------------

drop database if exists t;
create database if not exists t;

use t;

drop table if exists t;

create table t (
    id int unsigned not null primary key auto_increment,
    val varchar(100),
    ts timestamp
);

insert into t (val) values 
    ("try inserting"), 
    ("updating"), 
    ("and deleting"), 
    ("some records"),
    ("via context menu");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qdatatableproblem.py
Type: application/x-python
Size: 3143 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061007/1c98a251/qdatatableproblem.bin


More information about the PyQt mailing list