[PyKDE] Manipulating a QSqlRecord in a primeInsert handler

Jorge Godoy godoy at ieee.org
Wed Apr 27 15:14:39 BST 2005


Hi, 


I'm trying to use a QDataBrowser to browse and manipulate some records.  The
problem is that I'm not being able to set a new ID before inserting the record
and it is overwriting the only record available all the time.

My table structure -- this is a PostgreSQL database -- is:

symbol -> varchar(9)
name   -> varchar(30)
id     -> serial


My "primeInsert()" handler is:


    def dbGetNewUnitsID(self, record):
        query = QSqlQuery("SELECT NEXTVAL('units_id_seq')")
        query.execQuery()
        query.first()
        record.setValue('id', query.value(0))


It gets invoked correctly, it even executes the query, but it doesn't insert
the record as part of the transaction after getting the new ID.

Is there something else I should be doing?  Is it the correct way to handle
this kind of thing to create a new button to get the correct ID and then use
the 'Insert' button to make the insertion on the database?


Thanks in advance,

-- 
Jorge Godoy      <godoy at ieee.org>





More information about the PyQt mailing list