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

Dynamic SQL must be rejected with ERROR 1336 when using non-safe context

    XMLWordPrintable

Details

    • Not for Release Notes
    • Q3/2026 Server Maintenance

    Description

      MTR Test

      CREATE OR REPLACE TABLE t1(a INT);
      DELIMITER $$;
      CREATE OR REPLACE FUNCTION f_leaf() RETURNS INT
      BEGIN
        EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (777)'; RETURN 1;
      END
      $$
      CREATE OR REPLACE FUNCTION f_mid() RETURNS INT
      BEGIN
        DECLARE x INT;
        SET x = 100 + f_leaf(); RETURN x;
      END
      $$
      CREATE OR REPLACE PROCEDURE p()
      BEGIN
        DECLARE r INT DEFAULT f_mid();
      END
      $$
      DELIMITER ;$$
       
      CALL p();
       
      SELECT * FROM t1;
      

      CLI out

      13.1.0-dbg>CREATE OR REPLACE TABLE t1(a INT);
      Query OK, 0 rows affected (0.028 sec)
       
      13.1.0-dbg>DELIMITER $$
      13.1.0-dbg>CREATE OR REPLACE FUNCTION f_leaf() RETURNS INT
          -> BEGIN
          ->   EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (777)'; RETURN 1;
          -> END
          -> $$
      Query OK, 0 rows affected (0.004 sec)
       
      13.1.0-dbg>CREATE OR REPLACE FUNCTION f_mid() RETURNS INT
          -> BEGIN
          ->   DECLARE x INT;
          ->   SET x = 100 + f_leaf(); RETURN x;
          -> END
          -> $$
      Query OK, 0 rows affected (0.008 sec)
       
      13.1.0-dbg>CREATE OR REPLACE PROCEDURE p()
          -> BEGIN
          ->   DECLARE r INT DEFAULT f_mid();
          -> END
          -> $$
      Query OK, 0 rows affected (0.010 sec)
       
      13.1.0-dbg>DELIMITER ;
      13.1.0-dbg>
      13.1.0-dbg>
      13.1.0-dbg>call p();
      Query OK, 1 row affected (0.007 sec)
       
      13.1.0-dbg>SELECT * FROM t1;
      +------+
      | a    |
      +------+
      |  777 |
      +------+
      1 row in set (0.001 sec)
       
      13.1.0-dbg>
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              ramesh Ramesh Sivaraman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 4.7h Original Estimate - 4.7h
                  4.7h
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 1d 0.5h
                  1d 0.5h

                  Git Integration

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