Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide.QtSql: Since QVariant does not esists, how can a null value be used as argument to QSqlQuery.bindValue() ??
QtWS25 Last Chance

PySide.QtSql: Since QVariant does not esists, how can a null value be used as argument to QSqlQuery.bindValue() ??

Scheduled Pinned Locked Moved Language Bindings
7 Posts 4 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abdido
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qtforet
      wrote on last edited by
      #2

      Great question--have you asked it at SO?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtforet
        wrote on last edited by
        #3

        Great question--have you asked it at SO?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          c.lohr
          wrote on last edited by
          #4

          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
          @

          1 Reply Last reply
          0
          • C Offline
            C Offline
            c.lohr
            wrote on last edited by
            #5

            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
            @

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Python's None type represents null values.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                Python's None type represents null values.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved