Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-320

Cursor.execute_many raises DataError when data types in rows differ

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Won't Fix
    • 1.1.13
    • N/A
    • DBAPI 2.0
    • None
    • WIN10, mariadb Server 10.6.11
    • 3.9.13

    Description

      Summary

      Both float and int values can be inserted in a mariadb column defined as DECIMAL. However, a mariadb.DataError is raised, when adding multiple rows with Cursor.executemany where some rows contain int and some contain float values for the same column. (Exception message is Invalid parameter type at row X, column Y

      Steps to reproduce

      • Setup server and database for testing
      • Set environment variable TEST_DB_PASSWORD
      • Add following test code (derived for test_conpy61 in testing/test/integration/test_cursor.py)

            def test_conpyX(self):
                with create_connection() as con:
                    cursor = con.cursor()
                    cursor.execute("CREATE TEMPORARY TABLE ind1 "
                                   "(a decimal(8,4))")
         
                    vals = [(1,), (2.3,)]
                    cursor.executemany("INSERT INTO ind1 VALUES (?)", vals)
                    del cursor
        

      • In testing, run: python3 -m unittest test.integration.test_cursor -vv -k conpyX

      Expectation

      Test runs without errors.

      Actual result

      Exception

          cursor.executemany("INSERT INTO ind1 VALUES (?)", vals)
      mariadb.DataError: Invalid parameter type at row 2, column 1
      

      Workaround

      Convert all values to float before inserting

      Attachments

        Activity

          People

            georg Georg Richter
            gmech G.Mech
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.