[PyQt] QSqlTableModel.submitAll() problems with milliseconds and
PostgreSQL time field
Chris Mayo
mayo at clara.co.uk
Sun Aug 23 22:04:08 BST 2009
If I create a PostgreSQL database 'test' and execute the following:
CREATE TABLE timetest ( t time );
INSERT INTO timetest VALUES ('0:0:0');
run the following Python:
from PyQt4.QtCore import *
from PyQt4.QtSql import *
db = QSqlDatabase.addDatabase("QPSQL")
db.setHostName("localhost")
db.setDatabaseName("test")
db.setUserName("postgres")
db.open()
timetestModel = QSqlTableModel()
timetestModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
timetestModel.setTable("timetest")
timetestModel.select()
print \
timetestModel.record(0).field("t").value().toTime().toString("HH:mm:ss.zzz")
a = QTime(0,12,34,500)
timetestModel.setData(timetestModel.index(0,
timetestModel.fieldIndex("t")), a)
print \
timetestModel.record(0).field("t").value().toTime().toString("HH:mm:ss.zzz")
if not timetestModel.submitAll():
raise Exception, timetestModel.lastError().text()
print \
timetestModel.record(0).field("t").value().toTime().toString("HH:mm:ss.zzz")
The output is:
00:00:00.000
00:12:34.500
00:12:34.000
The database doesn't get the 500 milliseconds.
Even worse if I execute on the database:
UPDATE timetest SET t = '0:11:22.33';
and then run the Python above I get:
00:11:22.330
00:12:34.500
00:11:22.330
the value from the model doesn't make it into the database at all if the
time field already has milliseconds.
Any thoughts?
Chris
Linux amd64, Qt 4.5.2, PyQt4 4.5.4, Sip 4.8.2, PostgreSQL 8.3.7
More information about the PyQt
mailing list