Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2267

Parameter data type mismatch in PySide6.QtSql.QSqlQuery in Qt 6.4.3

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 6.4.3
    • PySide
    • None
    • Windows

    Description

      I wanted to bring to your attention that there has been a change in PySide6.QtSql.QSqlQuery's behavior. When running QSqlQuery.exec(), passed parameters are no longer implicitly converted to the defined data type of the parameter. For example, in a stored procedure that takes an int parameter, passing '1' as a string no longer works and the parameter needs to be passed as an integer value instead. This change in behavior was observed in Qt 6.4.3, while in the previous version (Qt 6.4.2), it was working both ways. I am not sure if this change was intended or not, but I wanted to bring it to your attention.

      run the code below in both versions:

       

      from PySide6.QtSql import QSqlDatabase, QSqlQuery
      import PySide6; print(PySide6.__version__)
      DRIVER = "ODBC Driver 17 for SQL Server"
      SERVER = "your sql server instance"
      DATABASE = "master"
      
      db = QSqlDatabase.addDatabase("QODBC")
      connString = f"Driver={DRIVER};Server={SERVER};Database={DATABASE};Trusted_Connection=Yes;"
      db.setDatabaseName(connString)
      
      if db.open():
          print('>Connected')
          queryObj = QSqlQuery(db)
          queryObj.prepare("""EXEC sp_who ?""")
          queryObj.addBindValue('1') # you no longer can pass int as str to a stored procedure
      
          if queryObj.exec():
              while queryObj.next():
                  print(queryObj.value(0))
          else:
              print(queryObj.lastError().text())
      else:
          print(db.lastError().text())

      Full output in 6.4.2

      6.4.2
      >Connected
      1

      Full output in 6.4.3

      6.4.3
      >Connected

      QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Executing SQL directly; no cursor. [Microsoft][ODBC 
      Driver 17 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value '1.' to data type int."
      [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Executing SQL directly; no cursor. [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value '1.' to data type int. QODBC: Unable to execute statement

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              sekiro Sekiro 19
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes