Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29218

PS + array binding does not work with triggers

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.4.26, 10.6.9, 10.8.4, 10.11
    • 10.5, 10.6
    • None
    • None

    Description

      Hi Georg, whassup?

      I found another bug related to executemany. (Does not affect execute with explicit values)

      If my table has any trigger, only one row is inserted. But, the trigger is called n times (n rows passed) with the same data.

      import mariadb
       
      db = mariadb.connect(host='10.4.0.8', user='Administrador', password='XXXXX', database='tmp')
      qr = db.cursor(buffered=True)
      qr.execute('drop table if exists aaa')
      qr.execute("""
      CREATE TABLE `aaa` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `some_field` varchar(10) DEFAULT '',
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB
      """)
       
      to_be_inserted = [(None, f'aaa_{i}') for i in range(10)]
      qr.executemany('insert into aaa values (?, ?) returning id', to_be_inserted)
      inserted = qr.fetchall()
      print(f'Should be', len(to_be_inserted), 'got', len(inserted), '. What whas inserted:', inserted)
       
      # ----------------------
      qr.execute('drop table if exists aaa_spy')
      qr.execute("""
      CREATE TABLE `aaa_spy` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `aaa_id` int(10) unsigned NOT NULL,
        `aaa_some_field` varchar(10) DEFAULT '',
        PRIMARY KEY (`id`)
      ) ENGINE=MyISAM
      """)
      qr.execute('drop trigger if exists aaa_after_insert')
      qr.execute("""
      CREATE TRIGGER aaa_after_insert
      AFTER INSERT
      ON aaa FOR EACH ROW
         insert into aaa_spy values (null, new.id, new.some_field)
      """)
       
      to_be_inserted = [(None, f'aaa_{i}') for i in range(10, 20)]
      qr.executemany('insert into aaa values (?, ?) returning id', to_be_inserted)
      inserted = qr.fetchall()
      print(f'Should be', len(to_be_inserted), 'got', len(inserted), '. What whas inserted:', inserted)  # Wrong!
       
      # What was inserted?
      qr.execute('select aaa_id, aaa_some_field from aaa_spy where aaa_id >= 11')
      # always the same data...
      for _id, f in qr:
          print(_id, f)
      

      This snippet returns this:

      Should be 10 got 10 . What whas inserted: [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)]
      Should be 10 got 1 . What whas inserted: [(16,)]
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      16 aaa_10
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            lucianobarcaro Luciano Barcaro
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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