[MDEV-27194] Describe for Dynamic SQL in Stored Routines Created: 2021-12-07  Updated: 2021-12-13

Status: Open
Project: MariaDB Server
Component/s: Stored routines
Fix Version/s: None

Type: Task Priority: Critical
Reporter: Anders Karlsson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Oracle supports the DBMS_SQL package which allows dynamic SQL with describing SQL statement in and out parameters to support fully dynamic SQL. There are much metadata that can be gotten from a SQL statement though, which would require a lot of functions to be implemented for this in MariaDB. My suggestion is instead to create just one statement to describe a prepared SQL statement and that the output of this is a JSON struct that contains all relevant data.

For example:

DECLARE
   sql_desc JSON;
BEGIN
   PREPARE s1 FROM 'SELECT c1 col1, c2 col2 FROM tab1 t1 WHERE col1 > ?';
   DESCRIBE s1 INTO JSON sql_desc;
...
END;

Where the JSON in sql_desc describes the returned data:

{"fields": [{"name": "c1", "org_name": "col1", "table": "t1", "org_table": "tab1", "length": 11, "type": "INTEGER"},
{"name": "c2", "org_name": "col2", "table": "t1", "org_table": "tab1", "length": 10, "type": "VARCHAR"}],
"params": {"count": 1}}



 Comments   
Comment by Sergei Golubchik [ 2021-12-13 ]

we'll likely also want FORMAT=JSON for consistency. and table (not json) output

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