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

Describe for Dynamic SQL in Stored Routines

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • None
    • Stored routines
    • 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}}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            karlsson Anders Karlsson
            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.