View Full Version : [pyqt] Can't insert Nulls Using QSqlQuery.execBatch

3rd October 2011, 22:07

Using PyQt, I am having a problem inserting Nulls into a MySql table using the execBatch() method of QSqlQuery. From the documentation, a null QVariant (i.e. QVariant(QVariant.Double)) represents a Null when inserting. When doing a regular query.exec_ it does actually insert Nulls, however when I do a query.execBatch(), zeros get inserted, not Nulls.

query.prepare(INSERT INTO `table` VALUES (?, ?))

var1=[1.0, QVariant(QVariant.Double)]
var2=[QVariant(QVariant.Double), 32.6]


With the above code, I would expect this to be inserted (Nulls should appear where QVariant objects in the lists are):

1.0 Null
Null 32.6
Instead what actually gets inserted is:

1.0 0
0 32.6
If I were to insert this line by line using just regular exec_ it would work, but I would rather use execBatch as I have many rows to insert at once (above is just an example). I have tried making every item in the lists a QVariant, whether Null or not, but I still get zeros, and I cannot pass in anything other than a QVariant to addBindValue (which I why I wrap the list in one when I call the method).

Any help would be greatly appreciated.
Thank you.