[MDEV-21425] When using Dynamic Query, There is some Problem. Created: 2020-01-06  Updated: 2020-01-23  Resolved: 2020-01-23

Status: Closed
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.3.13, 10.3
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Songuyoung Assignee: Alexander Barkov
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

I want to use several Dynamic Queries in one Variable.

IF we set several dynamic queries in one variable, MariaDB can't execute the Dynamic queries.

However If we use 'IF (1=1)' Then we can use dynamic queries in one variable.

Is this intentional behavior or bug?

IF it is not bug, I want to know there is any problem using like this.

(ex)

## PROCEDURE  CREATE
DROP PROCEDURE IF EXISTS ACCT.MYSQL_MULTI_TEST;
CREATE PROCEDURE ACCT.`MYSQL_MULTI_TEST`(
    $SQL             VARCHAR(8000) 
)
BEGIN
   DECLARE count INT DEFAULT 0;
 
   SET @SQL = $SQL;
   SET @COUNT = 1;
  PREPARE STMT_CONTENT FROM @SQL;
  EXECUTE STMT_CONTENT;    
  DEALLOCATE PREPARE STMT_CONTENT;	
 
END;

##  PROCEDURE  CALL ( error) 
 
CALL  MYSQL_MULTI_TEST(' 
  DELETE FROM MYSQL_MULTI_DELETE_1;  
  DELETE FROM MYSQL_MULTI_DELETE_2;
  DELETE FROM MYSQL_MULTI_DELETE_3; 
 '); 
 

 ## PROCEDURE  CALL ( ok )
 
 CALL  MYSQL_MULTI_TEST('
    IF( 1 = 1 )  THEN 
        DELETE FROM MYSQL_MULTI_DELETE_1;
        DELETE FROM MYSQL_MULTI_DELETE_2;
        DELETE FROM MYSQL_MULTI_DELETE_3;
    END IF;      
 '); 



 Comments   
Comment by Elena Stepanova [ 2020-01-13 ]

bar, what do you think, is it a bug or not?

Comment by Jacob Williams [ 2020-01-22 ]

Isn't this just a limitation on multiple statements in an execute body? If you use a `BEGIN NOT ATOMIC ... END;` instead of the `IF` clause it should work as well.

Comment by Sergei Golubchik [ 2020-01-23 ]

Yes, exactly, you can only PREPARE one statement. IF ... END IF or BEGIN NOT ATOMIC ... END is one compound statement, see https://mariadb.com/kb/en/programmatic-compound-statements/

But three statements separated by semicolons are just that — three statements.

Generated at Thu Feb 08 09:07:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.