PySide.QtSql: Since QVariant does not esists, how can a null value be used as argument to QSqlQuery.bindValue() ??
-
In SQL, a null string or a null integer is different from an empty string or zero.
the Qt4 documentation states:
bq. To bind a NULL value, use a null QVariant; for example, use QVariant(QVariant::String) if you are binding a string.
With PyQt:
@ query = QtSql.QSqlQuery()
query.prepare("insert into tb_A (name, age, date, town, notes) values (:na, :a, :d, :t, :no)")query.bindValue(":na", QtCore.QVariant("my name")) # string expected by SQL query.bindValue(":a" , QtCore.QVariant()) # null or integer expected by SQL query.bindValue(":d" , QtCore.QVariant()) # null or date expected by SQL query.bindValue(":t" , QtCore.QVariant("New York")) # null ou string expected by SQL query.bindValue(":no", QtCore.QVariant()) # null ou string expected by SQL
@
With PySide, QVariant is absent. Any suggestion ?
-
I never used the QtSQL module from PySide, but I used QAbstractItemModel, and there are QVariants too. I just used normal python types, without any QVariant.
Have you tried just to use a normal string or float?
Everything in Python is a kind of a variant-datatype because of duck-typing
@
query.bindValue(":na", "my name")
query.bindValue(":na", 4.0) # if you need a Float
@ -
I never used the QtSQL module from PySide, but I used QAbstractItemModel, and there are QVariants too. I just used normal python types, without any QVariant.
Have you tried just to use a normal string or float?
Everything in Python is a kind of a variant-datatype because of duck-typing
@
query.bindValue(":na", "my name")
query.bindValue(":na", 4.0) # if you need a Float
@ -
Python's None type represents null values.
-
Python's None type represents null values.