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

combining insert...returning and continue handler produces undocumented behavior

    XMLWordPrintable

Details

    Description

      when combining an error handler for 1048 and an insert...returning in a procedure, a strange behavior appears when the insert fails.
      In the example below, the `credits` field of the `grafeia_fin_trans` table cannot be null.
      So when total-factor is less than 0 the insert fails, as it is supposed to do.
      Everything works well when the 'returning id, grafeio' is commented.
      If it is uncommented then I get the screen I paste under the declaration of the procedure.

      CREATE PROCEDURE test.add_grafeia_transaction(gr_id int, trans_type int)
      BEGIN
      DECLARE insert_failed int default TRUE;
      DECLARE gr_total decimal;
      begin
      DECLARE continue HANDLER FOR 1048
        BEGIN
          set insert_failed = false;
        END;	
      	INSERT INTO `grafeia_fin_trans`(`grafeio`, `trans_type`,  `credits`, `json_param`) 
      select grafeio, id, res, null from
      (
      	select b.*, if(total-factor < 0, null, total-factor) res, total from (select sum(credits) total from grafeia_fin_trans where grafeio=gr_id) a,
      (select gr_id grafeio, id, factor, null from grafeia_fin_trans_types where id = trans_type) b) x
       returning id, grafeio
      ;
      end;
      if FALSE = insert_failed then 
      	select 0 id;
      else
      	select 1 id;
      end if;
      END
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            fraganestis_a Anestis Fraganestis
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.