Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-34319: DECLARE TYPE .. TABLE OF .. INDEX BY in stored routines #3797

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iqbal-rsec
Copy link

  • The Jira issue number for this PR is: MDEV-34319

Description

This patch adds support for associative arrays in stored procedures for sql_mode=ORACLE.
The syntax follows Oracle's PL/SQL syntax for associative arrays - TYPE assoc_array_t IS TABLE OF VARCHAR2(100) INDEX BY INTEGER; or
TYPE assoc_array_t IS TABLE OF record_t INDEX BY VARCHAR2(100); where record_t is a record type.

The following functions were added for associative arrays:

  • COUNT - Retrieve the number of elements within the arra
  • EXISTS - Check whether given key exists in the array
  • FIRST - Retrieve the first key in the array
  • LAST - Retrieve the last key in the array
  • PRIOR - Retrieve the key before the given key
  • NEXT - Retrieve the key after the given key
  • DELETE - Remove the element with the given key or remove all elements if no key is given

The arrays/elements can be initialized with the following methods:

  • Constructor i.e. array:= assoc_array_t('key1'=>1, 'key2'=>2, 'key3'=>3)
  • Assignment i.e. array(key):= record_t(1, 2)
  • SELECT INTO i.e. SELECT x INTO array(key)

TODOs:

  • Nested tables are not supported yet. i.e. TYPE assoc_array_t IS TABLE OF other_assoc_array_t INDEX BY INTEGER;
  • Associative arrays comparisons are not supported yet.

Release Notes

N/A, but new kb page should be created for associative arrays.

How can this PR be tested?

mysql-test/mtr sp-assoc-array

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

in stored routines

This patch adds support for associative arrays in stored procedures
for sql_mode=ORACLE.
The syntax follows Oracle's PL/SQL syntax for associative arrays -
TYPE assoc_array_t IS TABLE OF VARCHAR2(100) INDEX BY INTEGER;
or
TYPE assoc_array_t IS TABLE OF record_t INDEX BY VARCHAR2(100);
where record_t is a record type.

The following functions were added for associative arrays:
- COUNT - Retrieve the number of elements within the arra
- EXISTS - Check whether given key exists in the array
- FIRST - Retrieve the first key in the array
- LAST - Retrieve the last key in the array
- PRIOR - Retrieve the key before the given key
- NEXT - Retrieve the key after the given key
- DELETE - Remove the element with the given key or remove all elements
if no key is given

The arrays/elements can be initialized with the following methods:
- Constructor
i.e. array:= assoc_array_t('key1'=>1, 'key2'=>2, 'key3'=>3)
- Assignment
i.e. array(key):= record_t(1, 2)
- SELECT INTO
i.e. SELECT x INTO array(key)

TODOs:
- Nested tables are not supported yet.
i.e. TYPE assoc_array_t IS TABLE OF other_assoc_array_t INDEX BY INTEGER;
- Associative arrays comparisons are not supported yet.
@cvicentiu cvicentiu added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.
Development

Successfully merging this pull request may close these issues.

3 participants