Skip to content

Commit d05323b

Browse files
committed
Implements sys package for the following ticket:
- MDEV-19635: System package SYS.DBMS_SQL This patch adds support for dynamic SQL to parse any data manipulation language (DML) or data definition language (DDL) statement using PL/SQL. Added the following functions: - OPEN_CURSOR - Open a new cursor - EXECUTE - Execute a given cursor Added the following procedures: - PARSE - Parse the given statement in the given cursor - CLOSE_CURSOR - Close the cursor when no longer needed for a session As of the moment, '1', corresponding to Oracle's NATIVE DBMS_SQL constant, as PARSE's procedure's (language_flag) 3rd argument, is the only one accepted.
1 parent 2daafa7 commit d05323b

21 files changed

+1759
-8
lines changed

mysql-test/suite/compat/oracle/r/sp-package-i_s.result

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,62 @@ SELECT routine_name, routine_type, routine_definition
2020
FROM information_schema.routines
2121
WHERE routine_type LIKE 'PACKAGE%'
2222
ORDER BY routine_type;
23+
routine_name dbms_random
24+
routine_type PACKAGE
25+
routine_definition AS
26+
PROCEDURE initialize (input INT)
27+
SQL SECURITY INVOKER
28+
COMMENT '\n Description\n Initializes the seed\n Raises\n '
29+
;
30+
PROCEDURE terminate
31+
SQL SECURITY INVOKER
32+
COMMENT '\n Description\n Terminates package\n Raises\n '
33+
;
34+
FUNCTION value RETURN DECIMAL(65,38)
35+
SQL SECURITY INVOKER
36+
COMMENT '\n Description\n Gets a random number greater than or equal to 0 and less than 1,\n with 38 digits to the right of the decimal point (38-digit\n precision)\n Raises\n '
37+
;
38+
FUNCTION random RETURN INT
39+
SQL SECURITY INVOKER
40+
COMMENT '\n Description\n Generates a random number\n Raises\n '
41+
;
42+
END
43+
routine_name dbms_sql
44+
routine_type PACKAGE
45+
routine_definition AS
46+
FUNCTION open_cursor RETURN INT
47+
SQL SECURITY INVOKER
48+
COMMENT '\n Description\n This function opens a new cursor.\n Raises\n '
49+
;
50+
PROCEDURE parse (cursor_id INT, input VARCHAR2(65511), language_flag INT)
51+
SQL SECURITY INVOKER
52+
COMMENT '\n Description\n This procedure parses the given statement in the given cursor. All statements are parsed immediately. In addition, DDL statements are run immediately when parsed.\n Raises\n '
53+
;
54+
FUNCTION execute (cursor_id INT) RETURN INT
55+
SQL SECURITY INVOKER
56+
COMMENT '\n Description\n This function executes a given cursor. This function accepts the ID number of the cursor and returns the number of rows processed.\n Raises\n '
57+
;
58+
PROCEDURE close_cursor (cursor_id INT)
59+
SQL SECURITY INVOKER
60+
COMMENT '\n Description\n When you no longer need a cursor for a session, close the cursor by calling the CLOSE_CURSOR Procedure.\n Raises\n '
61+
;
62+
END
63+
routine_name dbms_utility
64+
routine_type PACKAGE
65+
routine_definition AS
66+
FUNCTION format_error_backtrace RETURN VARCHAR(65532)
67+
SQL SECURITY INVOKER
68+
COMMENT '\n Description\n This procedure displays the call stack at the point where an exception was raised, even if the procedure is called from an exception handler in an outer scope.\n Raises\n '
69+
;
70+
FUNCTION format_error_stack RETURN VARCHAR(65532)
71+
SQL SECURITY INVOKER
72+
COMMENT '\n Description\n This function formats the current error stack. It can be used in exception handlers to look at the full error stack\n Raises\n '
73+
;
74+
FUNCTION get_time RETURN INT
75+
SQL SECURITY INVOKER
76+
COMMENT '\n Description\n This function returns a measure of current time in hundredths of a second\n Raises\n '
77+
;
78+
END
2379
routine_name pkg1
2480
routine_type PACKAGE
2581
routine_definition AS
@@ -234,6 +290,77 @@ BEGIN
234290
RETURN 1;
235291
END;
236292
END
293+
routine_name UTL_I18N
294+
routine_type PACKAGE BODY
295+
routine_definition AS
296+
FUNCTION transliterate(val VARCHAR2(255) CHARACTER SET ANY_CS, name VARCHAR2(255)) RETURN VARCHAR2(255) CHARACTER SET ANY_CS
297+
SQL SECURITY INVOKER
298+
COMMENT '\n Description\n This function performs script transliteration.\n Parameters\n val (VARCHAR2):\n Specifies the data to be converted.\n name (VARCHAR2):\n Specifies the transliteration name string.\n Returns\n The converted string.\n '
299+
AS
300+
BEGIN
301+
RETURN transliterate(val, name);
302+
END;
303+
FUNCTION raw_to_char(jc RAW, charset_or_collation VARCHAR(255)) RETURN VARCHAR2
304+
SQL SECURITY INVOKER
305+
COMMENT '\n Description\n This function converts RAW data from a valid character set to a\n VARCHAR2 string in the database character set.\n Parameters\n jc (RAW):\n Specifies the RAW data to be converted to a VARCHAR2 string\n charset_or_collation (VARCHAR):\n Specifies the character set that the RAW data was derived from.\n Returns\n the VARCHAR2 string equivalent in the database character set of\n the RAW data.\n '
306+
IS
307+
BEGIN
308+
DECLARE
309+
dst_charset VARCHAR(65532);
310+
sourced_jc VARCHAR(65532);
311+
targeted_sourced_jc VARCHAR(65532);
312+
unhexed_hexed_data BLOB;
313+
BEGIN
314+
SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME = 'character_set_results' into dst_charset;
315+
CASE charset_or_collation
316+
WHEN 'utf8' THEN
317+
CASE dst_charset
318+
WHEN 'utf8mb3' THEN
319+
BEGIN
320+
SET sourced_jc = CONVERT(jc USING utf8);
321+
SET targeted_sourced_jc = CONVERT(sourced_jc USING utf8mb3);
322+
END;
323+
ELSE
324+
RETURN NULL;
325+
END CASE;
326+
WHEN 'utf8mb3' THEN
327+
CASE dst_charset
328+
WHEN 'utf8mb4' THEN
329+
BEGIN
330+
SET sourced_jc = CONVERT(jc USING utf8mb3);
331+
SET targeted_sourced_jc = CONVERT(sourced_jc USING utf8mb4);
332+
END;
333+
ELSE
334+
RETURN NULL;
335+
END CASE;
336+
ELSE
337+
RETURN NULL;
338+
END CASE;
339+
SET unhexed_hexed_data = UNHEX(HEX(targeted_sourced_jc));
340+
CASE dst_charset
341+
WHEN 'utf8mb3' THEN
342+
RETURN CONVERT(unhexed_hexed_data USING utf8mb3);
343+
WHEN 'utf8mb4' THEN
344+
RETURN CONVERT(unhexed_hexed_data USING utf8mb4);
345+
END CASE;
346+
RETURN NULL;
347+
END;
348+
END;
349+
FUNCTION string_to_raw(jc VARCHAR2, charset_or_collation VARCHAR(255)) RETURN RAW
350+
SQL SECURITY INVOKER
351+
COMMENT '\n Description\n This function converts a VARCHAR2 string to another valid\n character set and returns the result as RAW data.\n Parameters\n jc (VARCHAR2):\n Specifies the VARCHAR2 or NVARCHAR2 string to convert.\n charset_or_collation (VARCHAR):\n Specifies the destination character set.\n Returns\n RAW data representation of the input string in the new character set\n '
352+
AS
353+
BEGIN
354+
CASE charset_or_collation
355+
WHEN 'utf8' THEN
356+
RETURN CAST(CONVERT(jc USING utf8mb4) AS BINARY);
357+
WHEN 'ucs2' THEN
358+
RETURN CAST(CONVERT(jc USING ucs2) AS BINARY);
359+
ELSE
360+
RETURN NULL;
361+
END CASE;
362+
END;
363+
END
237364
DROP PACKAGE pkg1;
238365
SET sql_mode=ORACLE;
239366
CREATE OR REPLACE PACKAGE pkg1 AS
@@ -254,6 +381,62 @@ SELECT routine_name, routine_type, routine_definition
254381
FROM information_schema.routines
255382
WHERE routine_type LIKE 'PACKAGE%'
256383
ORDER BY routine_type;
384+
routine_name dbms_random
385+
routine_type PACKAGE
386+
routine_definition AS
387+
PROCEDURE initialize (input INT)
388+
SQL SECURITY INVOKER
389+
COMMENT '\n Description\n Initializes the seed\n Raises\n '
390+
;
391+
PROCEDURE terminate
392+
SQL SECURITY INVOKER
393+
COMMENT '\n Description\n Terminates package\n Raises\n '
394+
;
395+
FUNCTION value RETURN DECIMAL(65,38)
396+
SQL SECURITY INVOKER
397+
COMMENT '\n Description\n Gets a random number greater than or equal to 0 and less than 1,\n with 38 digits to the right of the decimal point (38-digit\n precision)\n Raises\n '
398+
;
399+
FUNCTION random RETURN INT
400+
SQL SECURITY INVOKER
401+
COMMENT '\n Description\n Generates a random number\n Raises\n '
402+
;
403+
END
404+
routine_name dbms_sql
405+
routine_type PACKAGE
406+
routine_definition AS
407+
FUNCTION open_cursor RETURN INT
408+
SQL SECURITY INVOKER
409+
COMMENT '\n Description\n This function opens a new cursor.\n Raises\n '
410+
;
411+
PROCEDURE parse (cursor_id INT, input VARCHAR2(65511), language_flag INT)
412+
SQL SECURITY INVOKER
413+
COMMENT '\n Description\n This procedure parses the given statement in the given cursor. All statements are parsed immediately. In addition, DDL statements are run immediately when parsed.\n Raises\n '
414+
;
415+
FUNCTION execute (cursor_id INT) RETURN INT
416+
SQL SECURITY INVOKER
417+
COMMENT '\n Description\n This function executes a given cursor. This function accepts the ID number of the cursor and returns the number of rows processed.\n Raises\n '
418+
;
419+
PROCEDURE close_cursor (cursor_id INT)
420+
SQL SECURITY INVOKER
421+
COMMENT '\n Description\n When you no longer need a cursor for a session, close the cursor by calling the CLOSE_CURSOR Procedure.\n Raises\n '
422+
;
423+
END
424+
routine_name dbms_utility
425+
routine_type PACKAGE
426+
routine_definition AS
427+
FUNCTION format_error_backtrace RETURN VARCHAR(65532)
428+
SQL SECURITY INVOKER
429+
COMMENT '\n Description\n This procedure displays the call stack at the point where an exception was raised, even if the procedure is called from an exception handler in an outer scope.\n Raises\n '
430+
;
431+
FUNCTION format_error_stack RETURN VARCHAR(65532)
432+
SQL SECURITY INVOKER
433+
COMMENT '\n Description\n This function formats the current error stack. It can be used in exception handlers to look at the full error stack\n Raises\n '
434+
;
435+
FUNCTION get_time RETURN INT
436+
SQL SECURITY INVOKER
437+
COMMENT '\n Description\n This function returns a measure of current time in hundredths of a second\n Raises\n '
438+
;
439+
END
257440
routine_name pkg1
258441
routine_type PACKAGE
259442
routine_definition AS
@@ -471,6 +654,77 @@ BEGIN
471654
SET @a=10;
472655
SET @a=f1();
473656
END
657+
routine_name UTL_I18N
658+
routine_type PACKAGE BODY
659+
routine_definition AS
660+
FUNCTION transliterate(val VARCHAR2(255) CHARACTER SET ANY_CS, name VARCHAR2(255)) RETURN VARCHAR2(255) CHARACTER SET ANY_CS
661+
SQL SECURITY INVOKER
662+
COMMENT '\n Description\n This function performs script transliteration.\n Parameters\n val (VARCHAR2):\n Specifies the data to be converted.\n name (VARCHAR2):\n Specifies the transliteration name string.\n Returns\n The converted string.\n '
663+
AS
664+
BEGIN
665+
RETURN transliterate(val, name);
666+
END;
667+
FUNCTION raw_to_char(jc RAW, charset_or_collation VARCHAR(255)) RETURN VARCHAR2
668+
SQL SECURITY INVOKER
669+
COMMENT '\n Description\n This function converts RAW data from a valid character set to a\n VARCHAR2 string in the database character set.\n Parameters\n jc (RAW):\n Specifies the RAW data to be converted to a VARCHAR2 string\n charset_or_collation (VARCHAR):\n Specifies the character set that the RAW data was derived from.\n Returns\n the VARCHAR2 string equivalent in the database character set of\n the RAW data.\n '
670+
IS
671+
BEGIN
672+
DECLARE
673+
dst_charset VARCHAR(65532);
674+
sourced_jc VARCHAR(65532);
675+
targeted_sourced_jc VARCHAR(65532);
676+
unhexed_hexed_data BLOB;
677+
BEGIN
678+
SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME = 'character_set_results' into dst_charset;
679+
CASE charset_or_collation
680+
WHEN 'utf8' THEN
681+
CASE dst_charset
682+
WHEN 'utf8mb3' THEN
683+
BEGIN
684+
SET sourced_jc = CONVERT(jc USING utf8);
685+
SET targeted_sourced_jc = CONVERT(sourced_jc USING utf8mb3);
686+
END;
687+
ELSE
688+
RETURN NULL;
689+
END CASE;
690+
WHEN 'utf8mb3' THEN
691+
CASE dst_charset
692+
WHEN 'utf8mb4' THEN
693+
BEGIN
694+
SET sourced_jc = CONVERT(jc USING utf8mb3);
695+
SET targeted_sourced_jc = CONVERT(sourced_jc USING utf8mb4);
696+
END;
697+
ELSE
698+
RETURN NULL;
699+
END CASE;
700+
ELSE
701+
RETURN NULL;
702+
END CASE;
703+
SET unhexed_hexed_data = UNHEX(HEX(targeted_sourced_jc));
704+
CASE dst_charset
705+
WHEN 'utf8mb3' THEN
706+
RETURN CONVERT(unhexed_hexed_data USING utf8mb3);
707+
WHEN 'utf8mb4' THEN
708+
RETURN CONVERT(unhexed_hexed_data USING utf8mb4);
709+
END CASE;
710+
RETURN NULL;
711+
END;
712+
END;
713+
FUNCTION string_to_raw(jc VARCHAR2, charset_or_collation VARCHAR(255)) RETURN RAW
714+
SQL SECURITY INVOKER
715+
COMMENT '\n Description\n This function converts a VARCHAR2 string to another valid\n character set and returns the result as RAW data.\n Parameters\n jc (VARCHAR2):\n Specifies the VARCHAR2 or NVARCHAR2 string to convert.\n charset_or_collation (VARCHAR):\n Specifies the destination character set.\n Returns\n RAW data representation of the input string in the new character set\n '
716+
AS
717+
BEGIN
718+
CASE charset_or_collation
719+
WHEN 'utf8' THEN
720+
RETURN CAST(CONVERT(jc USING utf8mb4) AS BINARY);
721+
WHEN 'ucs2' THEN
722+
RETURN CAST(CONVERT(jc USING ucs2) AS BINARY);
723+
ELSE
724+
RETURN NULL;
725+
END CASE;
726+
END;
727+
END
474728
DROP PACKAGE pkg1;
475729
#
476730
# End of 10.5 tests

mysql-test/suite/compat/oracle/r/sp-package-mysqldump.result

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,50 @@ DROP PACKAGE pkg1;
189189
DROP PACKAGE pkg2;
190190
DROP PROCEDURE p1;
191191
SHOW PACKAGE STATUS;
192+
Db sys
193+
Name dbms_random
194+
Type PACKAGE
195+
Definer root@localhost
196+
Modified 0000-00-00 00:00:00
197+
Created 0000-00-00 00:00:00
198+
Security_type INVOKER
199+
Comment Collection of random routines
200+
character_set_client utf8mb3
201+
collation_connection utf8mb3_general_ci
202+
Database Collation utf8mb3_general_ci
203+
Db sys
204+
Name dbms_sql
205+
Type PACKAGE
206+
Definer root@localhost
207+
Modified 0000-00-00 00:00:00
208+
Created 0000-00-00 00:00:00
209+
Security_type INVOKER
210+
Comment Collection of sql routines
211+
character_set_client utf8mb3
212+
collation_connection utf8mb3_general_ci
213+
Database Collation utf8mb3_general_ci
214+
Db sys
215+
Name dbms_utility
216+
Type PACKAGE
217+
Definer root@localhost
218+
Modified 0000-00-00 00:00:00
219+
Created 0000-00-00 00:00:00
220+
Security_type INVOKER
221+
Comment Collection of utility routines
222+
character_set_client utf8mb3
223+
collation_connection utf8mb3_general_ci
224+
Database Collation utf8mb3_general_ci
225+
Db sys
226+
Name UTL_I18N
227+
Type PACKAGE
228+
Definer root@localhost
229+
Modified 0000-00-00 00:00:00
230+
Created 0000-00-00 00:00:00
231+
Security_type INVOKER
232+
Comment Collection of routines to manipulate RAW data
233+
character_set_client utf8mb3
234+
collation_connection utf8mb3_general_ci
235+
Database Collation utf8mb3_general_ci
192236
Db test
193237
Name pkg1
194238
Type PACKAGE
@@ -212,6 +256,50 @@ character_set_client latin1
212256
collation_connection latin1_swedish_ci
213257
Database Collation utf8mb4_uca1400_ai_ci
214258
SHOW PACKAGE BODY STATUS;
259+
Db sys
260+
Name dbms_random
261+
Type PACKAGE BODY
262+
Definer root@localhost
263+
Modified 0000-00-00 00:00:00
264+
Created 0000-00-00 00:00:00
265+
Security_type INVOKER
266+
Comment
267+
character_set_client utf8mb3
268+
collation_connection utf8mb3_general_ci
269+
Database Collation utf8mb3_general_ci
270+
Db sys
271+
Name dbms_sql
272+
Type PACKAGE BODY
273+
Definer root@localhost
274+
Modified 0000-00-00 00:00:00
275+
Created 0000-00-00 00:00:00
276+
Security_type INVOKER
277+
Comment
278+
character_set_client utf8mb3
279+
collation_connection utf8mb3_general_ci
280+
Database Collation utf8mb3_general_ci
281+
Db sys
282+
Name dbms_utility
283+
Type PACKAGE BODY
284+
Definer root@localhost
285+
Modified 0000-00-00 00:00:00
286+
Created 0000-00-00 00:00:00
287+
Security_type INVOKER
288+
Comment
289+
character_set_client utf8mb3
290+
collation_connection utf8mb3_general_ci
291+
Database Collation utf8mb3_general_ci
292+
Db sys
293+
Name UTL_I18N
294+
Type PACKAGE BODY
295+
Definer root@localhost
296+
Modified 0000-00-00 00:00:00
297+
Created 0000-00-00 00:00:00
298+
Security_type INVOKER
299+
Comment
300+
character_set_client utf8mb3
301+
collation_connection utf8mb3_general_ci
302+
Database Collation utf8mb3_general_ci
215303
Db test
216304
Name pkg1
217305
Type PACKAGE BODY

0 commit comments

Comments
 (0)