From 3f619478f796eddbba6e39502fe941b285dd97b1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 20:00:34 +0200 Subject: Adding upstream version 1:10.11.6. Signed-off-by: Daniel Baumann --- mysql-test/suite/compat/README.txt | 7 + .../compat/maxdb/rpl_mariadb_timestamp.result | 65 + .../suite/compat/maxdb/rpl_mariadb_timestamp.test | 33 + .../suite/compat/maxdb/type_timestamp.result | 53 + mysql-test/suite/compat/maxdb/type_timestamp.test | 29 + mysql-test/suite/compat/mssql/parser.result | 87 + mysql-test/suite/compat/mssql/parser.test | 68 + .../suite/compat/oracle/r/anonymous_derived.result | 86 + .../compat/oracle/r/binlog_ptr_mysqlbinlog.result | 100 + .../suite/compat/oracle/r/binlog_stm_ps.result | 98 + .../suite/compat/oracle/r/binlog_stm_sp.result | 510 +++ .../compat/oracle/r/binlog_stm_sp_package.result | 268 ++ .../compat/oracle/r/column_compression.result | 1333 ++++++++ .../oracle/r/custom_aggregate_functions.result | 136 + .../compat/oracle/r/empty_string_literal.result | 181 ++ mysql-test/suite/compat/oracle/r/events.result | 27 + mysql-test/suite/compat/oracle/r/exception.result | 409 +++ .../suite/compat/oracle/r/func_add_months.result | 91 + mysql-test/suite/compat/oracle/r/func_case.result | 7 + .../suite/compat/oracle/r/func_concat.result | 393 +++ .../suite/compat/oracle/r/func_decode.result | 177 + .../suite/compat/oracle/r/func_length.result | 21 + mysql-test/suite/compat/oracle/r/func_misc.result | 319 ++ mysql-test/suite/compat/oracle/r/func_pad.result | 71 + .../suite/compat/oracle/r/func_replace.result | 32 + .../suite/compat/oracle/r/func_substr.result | 87 + mysql-test/suite/compat/oracle/r/func_time.result | 31 + .../suite/compat/oracle/r/func_to_char.result | 448 +++ mysql-test/suite/compat/oracle/r/func_trim.result | 170 + mysql-test/suite/compat/oracle/r/gis-debug.result | 24 + mysql-test/suite/compat/oracle/r/gis.result | 69 + .../oracle/r/information_schema_parameters.result | 854 +++++ mysql-test/suite/compat/oracle/r/keywords.result | 26 + mysql-test/suite/compat/oracle/r/minus.result | 48 + mysql-test/suite/compat/oracle/r/misc.result | 35 + .../suite/compat/oracle/r/mysqldump_restore.result | 38 + mysql-test/suite/compat/oracle/r/parser.result | 870 +++++ mysql-test/suite/compat/oracle/r/plugin.result | 48 + mysql-test/suite/compat/oracle/r/ps.result | 264 ++ .../suite/compat/oracle/r/rpl_mariadb_date.result | 86 + .../suite/compat/oracle/r/rpl_sp_package.result | 195 ++ .../oracle/r/rpl_sp_package_variables.result | 38 + mysql-test/suite/compat/oracle/r/sequence.result | 77 + .../oracle/r/sp-anchor-row-type-table.result | 131 + .../suite/compat/oracle/r/sp-anonymous.result | 220 ++ mysql-test/suite/compat/oracle/r/sp-code.result | 1516 +++++++++ .../suite/compat/oracle/r/sp-cursor-decl.result | 290 ++ .../suite/compat/oracle/r/sp-cursor-rowtype.result | 1506 +++++++++ mysql-test/suite/compat/oracle/r/sp-cursor.result | 1022 ++++++ mysql-test/suite/compat/oracle/r/sp-expr.result | 158 + .../suite/compat/oracle/r/sp-goto-debug.result | 236 ++ mysql-test/suite/compat/oracle/r/sp-goto.result | 913 ++++++ mysql-test/suite/compat/oracle/r/sp-inout.result | 2571 +++++++++++++++ .../suite/compat/oracle/r/sp-memory-leak.result | 27 + .../suite/compat/oracle/r/sp-package-code.result | 245 ++ .../oracle/r/sp-package-concurrent-dml-db.result | 43 + .../r/sp-package-concurrent-dml-package.result | 96 + .../r/sp-package-concurrent-dml-trigger.result | 44 + .../oracle/r/sp-package-concurrent-dml-view.result | 42 + .../suite/compat/oracle/r/sp-package-i_s.result | 75 + .../suite/compat/oracle/r/sp-package-innodb.result | 77 + .../suite/compat/oracle/r/sp-package-mdl.result | 80 + .../compat/oracle/r/sp-package-mysqldump.result | 261 ++ .../compat/oracle/r/sp-package-security.result | 322 ++ mysql-test/suite/compat/oracle/r/sp-package.result | 3375 ++++++++++++++++++++ mysql-test/suite/compat/oracle/r/sp-param.result | 423 +++ mysql-test/suite/compat/oracle/r/sp-row.result | 3129 ++++++++++++++++++ .../suite/compat/oracle/r/sp-security.result | 288 ++ mysql-test/suite/compat/oracle/r/sp.result | 2577 +++++++++++++++ .../suite/compat/oracle/r/statement-expr.result | 69 + .../compat/oracle/r/table_value_constr.result | 2509 +++++++++++++++ mysql-test/suite/compat/oracle/r/trigger.result | 100 + mysql-test/suite/compat/oracle/r/truncate.result | 10 + mysql-test/suite/compat/oracle/r/type_blob.result | 26 + mysql-test/suite/compat/oracle/r/type_clob.result | 15 + mysql-test/suite/compat/oracle/r/type_date.result | 155 + .../suite/compat/oracle/r/type_number.result | 15 + mysql-test/suite/compat/oracle/r/type_raw.result | 15 + .../suite/compat/oracle/r/type_varchar.result | 9 + .../suite/compat/oracle/r/type_varchar2.result | 23 + .../suite/compat/oracle/r/update_innodb.result | 26 + mysql-test/suite/compat/oracle/r/variables.result | 39 + mysql-test/suite/compat/oracle/r/vcol.result | 23 + mysql-test/suite/compat/oracle/r/versioning.result | 24 + mysql-test/suite/compat/oracle/r/win.result | 17 + .../suite/compat/oracle/t/anonymous_derived.test | 56 + .../oracle/t/binlog_ptr_mysqlbinlog-master.opt | 1 + .../compat/oracle/t/binlog_ptr_mysqlbinlog.test | 117 + .../suite/compat/oracle/t/binlog_stm_ps.test | 57 + .../suite/compat/oracle/t/binlog_stm_sp.test | 219 ++ .../compat/oracle/t/binlog_stm_sp_package.test | 158 + .../suite/compat/oracle/t/column_compression.test | 85 + .../oracle/t/custom_aggregate_functions.test | 170 + .../compat/oracle/t/empty_string_literal.test | 8 + mysql-test/suite/compat/oracle/t/events.test | 37 + mysql-test/suite/compat/oracle/t/exception.test | 457 +++ .../suite/compat/oracle/t/func_add_months.test | 38 + mysql-test/suite/compat/oracle/t/func_case.test | 9 + mysql-test/suite/compat/oracle/t/func_concat.test | 184 ++ mysql-test/suite/compat/oracle/t/func_decode.test | 98 + mysql-test/suite/compat/oracle/t/func_length.test | 18 + mysql-test/suite/compat/oracle/t/func_misc.test | 346 ++ mysql-test/suite/compat/oracle/t/func_pad.test | 31 + mysql-test/suite/compat/oracle/t/func_replace.test | 22 + mysql-test/suite/compat/oracle/t/func_substr.test | 47 + mysql-test/suite/compat/oracle/t/func_time.test | 25 + mysql-test/suite/compat/oracle/t/func_to_char.test | 236 ++ mysql-test/suite/compat/oracle/t/func_trim.test | 77 + mysql-test/suite/compat/oracle/t/gis-debug.test | 31 + mysql-test/suite/compat/oracle/t/gis.test | 76 + .../oracle/t/information_schema_parameters.test | 127 + mysql-test/suite/compat/oracle/t/keywords.test | 29 + mysql-test/suite/compat/oracle/t/minus.test | 44 + mysql-test/suite/compat/oracle/t/misc.test | 38 + .../suite/compat/oracle/t/mysqldump_restore.test | 30 + mysql-test/suite/compat/oracle/t/parser.test | 727 +++++ mysql-test/suite/compat/oracle/t/plugin.test | 3 + mysql-test/suite/compat/oracle/t/ps.test | 290 ++ .../suite/compat/oracle/t/rpl_mariadb_date.test | 38 + .../suite/compat/oracle/t/rpl_sp_package.test | 134 + .../compat/oracle/t/rpl_sp_package_variables.test | 36 + mysql-test/suite/compat/oracle/t/sequence.test | 48 + .../compat/oracle/t/sp-anchor-row-type-table.test | 124 + mysql-test/suite/compat/oracle/t/sp-anonymous.test | 244 ++ .../suite/compat/oracle/t/sp-cache-invalidate.inc | 11 + mysql-test/suite/compat/oracle/t/sp-code.test | 1088 +++++++ .../suite/compat/oracle/t/sp-cursor-decl.test | 295 ++ .../suite/compat/oracle/t/sp-cursor-rowtype.test | 1597 +++++++++ mysql-test/suite/compat/oracle/t/sp-cursor.test | 1044 ++++++ mysql-test/suite/compat/oracle/t/sp-expr.test | 165 + .../suite/compat/oracle/t/sp-goto-debug.test | 178 ++ mysql-test/suite/compat/oracle/t/sp-goto.test | 968 ++++++ mysql-test/suite/compat/oracle/t/sp-inout.test | 2501 +++++++++++++++ .../suite/compat/oracle/t/sp-memory-leak.test | 35 + .../suite/compat/oracle/t/sp-package-code.test | 182 ++ .../oracle/t/sp-package-concurrent-dml-db.test | 6 + .../t/sp-package-concurrent-dml-package.test | 10 + .../t/sp-package-concurrent-dml-trigger.test | 6 + .../oracle/t/sp-package-concurrent-dml-view.test | 6 + .../compat/oracle/t/sp-package-concurrent-dml.inc | 107 + .../suite/compat/oracle/t/sp-package-i_s.test | 69 + .../suite/compat/oracle/t/sp-package-innodb.test | 66 + .../suite/compat/oracle/t/sp-package-mdl.test | 110 + .../compat/oracle/t/sp-package-mysqldump.test | 94 + .../suite/compat/oracle/t/sp-package-security.test | 332 ++ mysql-test/suite/compat/oracle/t/sp-package.test | 3092 ++++++++++++++++++ mysql-test/suite/compat/oracle/t/sp-param.inc | 9 + mysql-test/suite/compat/oracle/t/sp-param.test | 363 +++ mysql-test/suite/compat/oracle/t/sp-row-vs-var.inc | 6 + mysql-test/suite/compat/oracle/t/sp-row.test | 2418 ++++++++++++++ mysql-test/suite/compat/oracle/t/sp-security.test | 345 ++ mysql-test/suite/compat/oracle/t/sp.test | 2430 ++++++++++++++ .../suite/compat/oracle/t/statement-expr.test | 86 + .../suite/compat/oracle/t/table_value_constr.test | 1287 ++++++++ mysql-test/suite/compat/oracle/t/trigger.test | 106 + mysql-test/suite/compat/oracle/t/truncate.test | 16 + mysql-test/suite/compat/oracle/t/type_blob.test | 17 + mysql-test/suite/compat/oracle/t/type_clob.test | 10 + mysql-test/suite/compat/oracle/t/type_date.test | 101 + mysql-test/suite/compat/oracle/t/type_number.test | 9 + mysql-test/suite/compat/oracle/t/type_raw.test | 10 + mysql-test/suite/compat/oracle/t/type_varchar.test | 9 + .../suite/compat/oracle/t/type_varchar2.test | 19 + .../suite/compat/oracle/t/update_innodb.test | 31 + mysql-test/suite/compat/oracle/t/variables.test | 38 + mysql-test/suite/compat/oracle/t/vcol.test | 16 + mysql-test/suite/compat/oracle/t/versioning.test | 23 + mysql-test/suite/compat/oracle/t/win.test | 22 + 168 files changed, 54599 insertions(+) create mode 100644 mysql-test/suite/compat/README.txt create mode 100644 mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.result create mode 100644 mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.test create mode 100644 mysql-test/suite/compat/maxdb/type_timestamp.result create mode 100644 mysql-test/suite/compat/maxdb/type_timestamp.test create mode 100644 mysql-test/suite/compat/mssql/parser.result create mode 100644 mysql-test/suite/compat/mssql/parser.test create mode 100644 mysql-test/suite/compat/oracle/r/anonymous_derived.result create mode 100644 mysql-test/suite/compat/oracle/r/binlog_ptr_mysqlbinlog.result create mode 100644 mysql-test/suite/compat/oracle/r/binlog_stm_ps.result create mode 100644 mysql-test/suite/compat/oracle/r/binlog_stm_sp.result create mode 100644 mysql-test/suite/compat/oracle/r/binlog_stm_sp_package.result create mode 100644 mysql-test/suite/compat/oracle/r/column_compression.result create mode 100644 mysql-test/suite/compat/oracle/r/custom_aggregate_functions.result create mode 100644 mysql-test/suite/compat/oracle/r/empty_string_literal.result create mode 100644 mysql-test/suite/compat/oracle/r/events.result create mode 100644 mysql-test/suite/compat/oracle/r/exception.result create mode 100644 mysql-test/suite/compat/oracle/r/func_add_months.result create mode 100644 mysql-test/suite/compat/oracle/r/func_case.result create mode 100644 mysql-test/suite/compat/oracle/r/func_concat.result create mode 100644 mysql-test/suite/compat/oracle/r/func_decode.result create mode 100644 mysql-test/suite/compat/oracle/r/func_length.result create mode 100644 mysql-test/suite/compat/oracle/r/func_misc.result create mode 100644 mysql-test/suite/compat/oracle/r/func_pad.result create mode 100644 mysql-test/suite/compat/oracle/r/func_replace.result create mode 100644 mysql-test/suite/compat/oracle/r/func_substr.result create mode 100644 mysql-test/suite/compat/oracle/r/func_time.result create mode 100644 mysql-test/suite/compat/oracle/r/func_to_char.result create mode 100644 mysql-test/suite/compat/oracle/r/func_trim.result create mode 100644 mysql-test/suite/compat/oracle/r/gis-debug.result create mode 100644 mysql-test/suite/compat/oracle/r/gis.result create mode 100644 mysql-test/suite/compat/oracle/r/information_schema_parameters.result create mode 100644 mysql-test/suite/compat/oracle/r/keywords.result create mode 100644 mysql-test/suite/compat/oracle/r/minus.result create mode 100644 mysql-test/suite/compat/oracle/r/misc.result create mode 100644 mysql-test/suite/compat/oracle/r/mysqldump_restore.result create mode 100644 mysql-test/suite/compat/oracle/r/parser.result create mode 100644 mysql-test/suite/compat/oracle/r/plugin.result create mode 100644 mysql-test/suite/compat/oracle/r/ps.result create mode 100644 mysql-test/suite/compat/oracle/r/rpl_mariadb_date.result create mode 100644 mysql-test/suite/compat/oracle/r/rpl_sp_package.result create mode 100644 mysql-test/suite/compat/oracle/r/rpl_sp_package_variables.result create mode 100644 mysql-test/suite/compat/oracle/r/sequence.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-anchor-row-type-table.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-anonymous.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-code.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-cursor-decl.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-cursor.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-expr.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-goto-debug.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-goto.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-inout.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-memory-leak.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-code.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-db.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-package.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-trigger.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-view.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-i_s.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-innodb.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-mdl.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-mysqldump.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package-security.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-package.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-param.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-row.result create mode 100644 mysql-test/suite/compat/oracle/r/sp-security.result create mode 100644 mysql-test/suite/compat/oracle/r/sp.result create mode 100644 mysql-test/suite/compat/oracle/r/statement-expr.result create mode 100644 mysql-test/suite/compat/oracle/r/table_value_constr.result create mode 100644 mysql-test/suite/compat/oracle/r/trigger.result create mode 100644 mysql-test/suite/compat/oracle/r/truncate.result create mode 100644 mysql-test/suite/compat/oracle/r/type_blob.result create mode 100644 mysql-test/suite/compat/oracle/r/type_clob.result create mode 100644 mysql-test/suite/compat/oracle/r/type_date.result create mode 100644 mysql-test/suite/compat/oracle/r/type_number.result create mode 100644 mysql-test/suite/compat/oracle/r/type_raw.result create mode 100644 mysql-test/suite/compat/oracle/r/type_varchar.result create mode 100644 mysql-test/suite/compat/oracle/r/type_varchar2.result create mode 100644 mysql-test/suite/compat/oracle/r/update_innodb.result create mode 100644 mysql-test/suite/compat/oracle/r/variables.result create mode 100644 mysql-test/suite/compat/oracle/r/vcol.result create mode 100644 mysql-test/suite/compat/oracle/r/versioning.result create mode 100644 mysql-test/suite/compat/oracle/r/win.result create mode 100644 mysql-test/suite/compat/oracle/t/anonymous_derived.test create mode 100644 mysql-test/suite/compat/oracle/t/binlog_ptr_mysqlbinlog-master.opt create mode 100644 mysql-test/suite/compat/oracle/t/binlog_ptr_mysqlbinlog.test create mode 100644 mysql-test/suite/compat/oracle/t/binlog_stm_ps.test create mode 100644 mysql-test/suite/compat/oracle/t/binlog_stm_sp.test create mode 100644 mysql-test/suite/compat/oracle/t/binlog_stm_sp_package.test create mode 100644 mysql-test/suite/compat/oracle/t/column_compression.test create mode 100644 mysql-test/suite/compat/oracle/t/custom_aggregate_functions.test create mode 100644 mysql-test/suite/compat/oracle/t/empty_string_literal.test create mode 100644 mysql-test/suite/compat/oracle/t/events.test create mode 100644 mysql-test/suite/compat/oracle/t/exception.test create mode 100644 mysql-test/suite/compat/oracle/t/func_add_months.test create mode 100644 mysql-test/suite/compat/oracle/t/func_case.test create mode 100644 mysql-test/suite/compat/oracle/t/func_concat.test create mode 100644 mysql-test/suite/compat/oracle/t/func_decode.test create mode 100644 mysql-test/suite/compat/oracle/t/func_length.test create mode 100644 mysql-test/suite/compat/oracle/t/func_misc.test create mode 100644 mysql-test/suite/compat/oracle/t/func_pad.test create mode 100644 mysql-test/suite/compat/oracle/t/func_replace.test create mode 100644 mysql-test/suite/compat/oracle/t/func_substr.test create mode 100644 mysql-test/suite/compat/oracle/t/func_time.test create mode 100644 mysql-test/suite/compat/oracle/t/func_to_char.test create mode 100644 mysql-test/suite/compat/oracle/t/func_trim.test create mode 100644 mysql-test/suite/compat/oracle/t/gis-debug.test create mode 100644 mysql-test/suite/compat/oracle/t/gis.test create mode 100644 mysql-test/suite/compat/oracle/t/information_schema_parameters.test create mode 100644 mysql-test/suite/compat/oracle/t/keywords.test create mode 100644 mysql-test/suite/compat/oracle/t/minus.test create mode 100644 mysql-test/suite/compat/oracle/t/misc.test create mode 100644 mysql-test/suite/compat/oracle/t/mysqldump_restore.test create mode 100644 mysql-test/suite/compat/oracle/t/parser.test create mode 100644 mysql-test/suite/compat/oracle/t/plugin.test create mode 100644 mysql-test/suite/compat/oracle/t/ps.test create mode 100644 mysql-test/suite/compat/oracle/t/rpl_mariadb_date.test create mode 100644 mysql-test/suite/compat/oracle/t/rpl_sp_package.test create mode 100644 mysql-test/suite/compat/oracle/t/rpl_sp_package_variables.test create mode 100644 mysql-test/suite/compat/oracle/t/sequence.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-anchor-row-type-table.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-anonymous.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-cache-invalidate.inc create mode 100644 mysql-test/suite/compat/oracle/t/sp-code.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-cursor-decl.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-cursor.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-expr.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-goto-debug.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-goto.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-inout.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-memory-leak.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-code.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-db.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-package.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-trigger.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-view.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml.inc create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-i_s.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-innodb.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-mdl.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-mysqldump.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package-security.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-package.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-param.inc create mode 100644 mysql-test/suite/compat/oracle/t/sp-param.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-row-vs-var.inc create mode 100644 mysql-test/suite/compat/oracle/t/sp-row.test create mode 100644 mysql-test/suite/compat/oracle/t/sp-security.test create mode 100644 mysql-test/suite/compat/oracle/t/sp.test create mode 100644 mysql-test/suite/compat/oracle/t/statement-expr.test create mode 100644 mysql-test/suite/compat/oracle/t/table_value_constr.test create mode 100644 mysql-test/suite/compat/oracle/t/trigger.test create mode 100644 mysql-test/suite/compat/oracle/t/truncate.test create mode 100644 mysql-test/suite/compat/oracle/t/type_blob.test create mode 100644 mysql-test/suite/compat/oracle/t/type_clob.test create mode 100644 mysql-test/suite/compat/oracle/t/type_date.test create mode 100644 mysql-test/suite/compat/oracle/t/type_number.test create mode 100644 mysql-test/suite/compat/oracle/t/type_raw.test create mode 100644 mysql-test/suite/compat/oracle/t/type_varchar.test create mode 100644 mysql-test/suite/compat/oracle/t/type_varchar2.test create mode 100644 mysql-test/suite/compat/oracle/t/update_innodb.test create mode 100644 mysql-test/suite/compat/oracle/t/variables.test create mode 100644 mysql-test/suite/compat/oracle/t/vcol.test create mode 100644 mysql-test/suite/compat/oracle/t/versioning.test create mode 100644 mysql-test/suite/compat/oracle/t/win.test (limited to 'mysql-test/suite/compat') diff --git a/mysql-test/suite/compat/README.txt b/mysql-test/suite/compat/README.txt new file mode 100644 index 00000000..b1a2033f --- /dev/null +++ b/mysql-test/suite/compat/README.txt @@ -0,0 +1,7 @@ +To run a test suite under this directory, you should use the format: + +mysql-test-run --suite=compat/oracle + +or to run one test: + +mysql-test-run compat/oracle.test_name diff --git a/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.result b/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.result new file mode 100644 index 00000000..727c7949 --- /dev/null +++ b/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.result @@ -0,0 +1,65 @@ +include/master-slave.inc +[connection master] +# +# MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode +# +SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:00:00'); +SET sql_mode=DEFAULT; +CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT NOW()); +INSERT INTO t1 VALUES (NULL); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30'); +SET sql_mode=MAXDB; +CREATE TABLE t2 SELECT * FROM t1; +SET timestamp=DEFAULT; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT NOW()) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES (NULL) +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES ('2001-01-01 10:20:30') +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE "t2" ( + "a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp() +) +master-bin.000001 # Annotate_rows # # CREATE TABLE t2 SELECT * FROM t1 +master-bin.000001 # Table_map # # table_id: # (test.t2) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +connection slave; +SELECT * FROM t1; +a +2001-01-01 10:00:00 +2001-01-01 10:20:30 +SET sql_mode=DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` timestamp NOT NULL DEFAULT current_timestamp() +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` timestamp NOT NULL DEFAULT current_timestamp() +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SET sql_mode=MAXDB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp() +) +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE "t2" ( + "a" mariadb_schema.timestamp NOT NULL DEFAULT current_timestamp() +) +connection master; +DROP TABLE t1, t2; +include/rpl_end.inc diff --git a/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.test b/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.test new file mode 100644 index 00000000..f4a82661 --- /dev/null +++ b/mysql-test/suite/compat/maxdb/rpl_mariadb_timestamp.test @@ -0,0 +1,33 @@ +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +--echo # +--echo # MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode +--echo # + +SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:00:00'); +SET sql_mode=DEFAULT; +CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT NOW()); +INSERT INTO t1 VALUES (NULL); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30'); +SET sql_mode=MAXDB; +CREATE TABLE t2 SELECT * FROM t1; +SET timestamp=DEFAULT; + +--let $binlog_file = LAST +source include/show_binlog_events.inc; + +--sync_slave_with_master +SELECT * FROM t1; +SET sql_mode=DEFAULT; +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t2; + +SET sql_mode=MAXDB; +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t2; + +--connection master +DROP TABLE t1, t2; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/compat/maxdb/type_timestamp.result b/mysql-test/suite/compat/maxdb/type_timestamp.result new file mode 100644 index 00000000..f6612ab1 --- /dev/null +++ b/mysql-test/suite/compat/maxdb/type_timestamp.result @@ -0,0 +1,53 @@ +# +# MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode +# +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +def_timestamp TIMESTAMP, +mdb_timestamp mariadb_schema.TIMESTAMP, +ora_timestamp oracle_schema.TIMESTAMP, +max_timestamp maxdb_schema.TIMESTAMP +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `def_timestamp` timestamp NULL DEFAULT NULL, + `mdb_timestamp` timestamp NULL DEFAULT NULL, + `ora_timestamp` timestamp NULL DEFAULT NULL, + `max_timestamp` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SET sql_mode=MAXDB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "def_timestamp" mariadb_schema.timestamp NULL DEFAULT NULL, + "mdb_timestamp" mariadb_schema.timestamp NULL DEFAULT NULL, + "ora_timestamp" mariadb_schema.timestamp NULL DEFAULT NULL, + "max_timestamp" datetime DEFAULT NULL +) +DROP TABLE t1; +SET sql_mode=MAXDB; +CREATE TABLE t1 ( +def_timestamp TIMESTAMP, +mdb_timestamp mariadb_schema.TIMESTAMP, +ora_timestamp oracle_schema.TIMESTAMP, +max_timestamp maxdb_schema.TIMESTAMP +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "def_timestamp" datetime DEFAULT NULL, + "mdb_timestamp" mariadb_schema.timestamp NULL DEFAULT NULL, + "ora_timestamp" mariadb_schema.timestamp NULL DEFAULT NULL, + "max_timestamp" datetime DEFAULT NULL +) +SET sql_mode=DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `def_timestamp` datetime DEFAULT NULL, + `mdb_timestamp` timestamp NULL DEFAULT NULL, + `ora_timestamp` timestamp NULL DEFAULT NULL, + `max_timestamp` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; diff --git a/mysql-test/suite/compat/maxdb/type_timestamp.test b/mysql-test/suite/compat/maxdb/type_timestamp.test new file mode 100644 index 00000000..cd60ffc0 --- /dev/null +++ b/mysql-test/suite/compat/maxdb/type_timestamp.test @@ -0,0 +1,29 @@ +--echo # +--echo # MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode +--echo # + + +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + def_timestamp TIMESTAMP, + mdb_timestamp mariadb_schema.TIMESTAMP, + ora_timestamp oracle_schema.TIMESTAMP, + max_timestamp maxdb_schema.TIMESTAMP +); +SHOW CREATE TABLE t1; +SET sql_mode=MAXDB; +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +SET sql_mode=MAXDB; +CREATE TABLE t1 ( + def_timestamp TIMESTAMP, + mdb_timestamp mariadb_schema.TIMESTAMP, + ora_timestamp oracle_schema.TIMESTAMP, + max_timestamp maxdb_schema.TIMESTAMP +); +SHOW CREATE TABLE t1; +SET sql_mode=DEFAULT; +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/mssql/parser.result b/mysql-test/suite/compat/mssql/parser.result new file mode 100644 index 00000000..817439a8 --- /dev/null +++ b/mysql-test/suite/compat/mssql/parser.result @@ -0,0 +1,87 @@ +SET sql_mode=MSSQL; +# +# Start of 10.4 tests +# +# +# MDEV-19142 sql_mode=MSSQL: Bracket identifiers +# +SELECT 'test' AS [[]; +[ +test +SELECT 'test' AS []]]; +] +test +SELECT 'test' AS [[a]]]; +[a] +test +SELECT 'test' AS [\n]; +\n +test +CREATE TABLE [t 1] ([a b] INT); +SHOW CREATE TABLE [t 1]; +Table Create Table +t 1 CREATE TABLE "t 1" ( + "a b" int(11) DEFAULT NULL +) +INSERT INTO [t 1] VALUES (10); +SELECT [a b] FROM [t 1]; +a b +10 +SELECT [a b] [a b alias] FROM [t 1] [t 1 alias]; +a b alias +10 +SELECT [a b] FROM [test].[t 1]; +a b +10 +SELECT [a b], COUNT(*) FROM [t 1] GROUP BY [a b]; +a b COUNT(*) +10 1 +SELECT [a b], COUNT(*) FROM [t 1] GROUP BY [a b] HAVING [a b]>0; +a b COUNT(*) +10 1 +DROP TABLE [t 1]; +CREATE TABLE [t[1]]] (a INT); +SHOW CREATE TABLE [t[1]]]; +Table Create Table +t[1] CREATE TABLE "t[1]" ( + "a" int(11) DEFAULT NULL +) +DROP TABLE [t[1]]]; +CREATE TABLE [t 1] ([a b] INT); +CREATE VIEW [v 1] AS SELECT [a b] FROM [t 1]; +SHOW CREATE VIEW [v 1]; +View Create View character_set_client collation_connection +v 1 CREATE VIEW "v 1" AS select "t 1"."a b" AS "a b" from "t 1" latin1 latin1_swedish_ci +SELECT * FROM [v 1]; +a b +DROP VIEW [v 1]; +DROP TABLE [t 1]; +CREATE PROCEDURE [p 1]() +BEGIN +SELECT 'test' [a b]; +END; +$$ +SHOW CREATE PROCEDURE [p 1]; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +p 1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,MSSQL,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS CREATE DEFINER="root"@"localhost" PROCEDURE "p 1"() +BEGIN +SELECT 'test' [a b]; +END latin1 latin1_swedish_ci latin1_swedish_ci +CALL [p 1]; +a b +test +DROP PROCEDURE [p 1]; +CREATE TABLE [t1] ([a] INT); +INSERT INTO t1 VALUES (10); +PREPARE [stmt] FROM 'SELECT [a] FROM [test].[t1]'; +EXECUTE [stmt]; +a +10 +DEALLOCATE PREPARE [stmt]; +EXECUTE IMMEDIATE 'SELECT [a] FROM [test].[t1]'; +a +10 +DROP TABLE [t1]; +# +# End of 10.4 tests +# diff --git a/mysql-test/suite/compat/mssql/parser.test b/mysql-test/suite/compat/mssql/parser.test new file mode 100644 index 00000000..59c6735c --- /dev/null +++ b/mysql-test/suite/compat/mssql/parser.test @@ -0,0 +1,68 @@ +SET sql_mode=MSSQL; + +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-19142 sql_mode=MSSQL: Bracket identifiers +--echo # + +# Brackets inside bracket identifiers: +# - When we want a left bracket inside a bracket identifier, +# we just add a single left bracket: [ +# - When we want a right bracket inside a bracket identifier, +# we add two right brackets: ]] + + +SELECT 'test' AS [[]; +SELECT 'test' AS []]]; +SELECT 'test' AS [[a]]]; + +# Backslash has no special meaning +SELECT 'test' AS [\n]; + + +CREATE TABLE [t 1] ([a b] INT); +SHOW CREATE TABLE [t 1]; +INSERT INTO [t 1] VALUES (10); +SELECT [a b] FROM [t 1]; +SELECT [a b] [a b alias] FROM [t 1] [t 1 alias]; +SELECT [a b] FROM [test].[t 1]; +SELECT [a b], COUNT(*) FROM [t 1] GROUP BY [a b]; +SELECT [a b], COUNT(*) FROM [t 1] GROUP BY [a b] HAVING [a b]>0; +DROP TABLE [t 1]; + +CREATE TABLE [t[1]]] (a INT); +SHOW CREATE TABLE [t[1]]]; +DROP TABLE [t[1]]]; + +CREATE TABLE [t 1] ([a b] INT); +CREATE VIEW [v 1] AS SELECT [a b] FROM [t 1]; +SHOW CREATE VIEW [v 1]; +SELECT * FROM [v 1]; +DROP VIEW [v 1]; +DROP TABLE [t 1]; + +DELIMITER $$; +CREATE PROCEDURE [p 1]() +BEGIN + SELECT 'test' [a b]; +END; +$$ +DELIMITER ;$$ +SHOW CREATE PROCEDURE [p 1]; +CALL [p 1]; +DROP PROCEDURE [p 1]; + +CREATE TABLE [t1] ([a] INT); +INSERT INTO t1 VALUES (10); +PREPARE [stmt] FROM 'SELECT [a] FROM [test].[t1]'; +EXECUTE [stmt]; +DEALLOCATE PREPARE [stmt]; +EXECUTE IMMEDIATE 'SELECT [a] FROM [test].[t1]'; +DROP TABLE [t1]; + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/suite/compat/oracle/r/anonymous_derived.result b/mysql-test/suite/compat/oracle/r/anonymous_derived.result new file mode 100644 index 00000000..6b482d7b --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/anonymous_derived.result @@ -0,0 +1,86 @@ +# +# MDEV-19162: anonymous derived tables part +# +set @save_sql_mode=@@sql_mode; +set session sql_mode=ORACLE; +SELECT * FROM (SELECT 1 FROM DUAL), (SELECT 2 FROM DUAL); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def __2 1 1 3 1 1 N 32769 0 63 +def __3 2 2 3 1 1 N 32769 0 63 +1 2 +1 2 +create table t1 (a int); +insert into t1 values (2),(3); +create table t2 (a int); +insert into t2 values (2),(3); +select t1.a from t1, (select * from t2 where t2.a<= 2); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 t1 a a 3 11 1 Y 32768 0 63 +a +2 +3 +select t1.a, b from t1, (select a as b from t2 where t2.a<= 2); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 t1 a a 3 11 1 Y 32768 0 63 +def test __2 __2 b b 3 11 1 Y 32768 0 63 +a b +2 2 +3 2 +select t1.a, b from t1, (select max(a) as b from t2); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 t1 a a 3 11 1 Y 32768 0 63 +def t2 __2 b b 3 11 1 Y 32768 0 63 +a b +2 3 +3 3 +explain extended +select t1.a, b from t1, (select max(a) as b from t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) +2 DERIVED t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","__2"."b" AS "b" from "test"."t1" join (/* select#2 */ select max("test"."t2"."a") AS "b" from "test"."t2") "__2" +select * from (select tt.* from (select * from t1) as tt) where tt.a > 0; +ERROR 42S22: Unknown column 'tt.a' in 'where clause' +select * from (select tt.* from (select * from t1) as tt) where a > 0; +a +2 +3 +create view v1 as select t1.a, b from t1, (select max(a) as b from t2); +select * from v1; +a b +2 3 +3 3 +create procedure p1 +as +begin +select t1.a, b from t1, (select max(a) as b from t2); +end/ +call p1; +a b +2 3 +3 3 +SET sql_mode=default; +select * from v1; +a b +2 3 +3 3 +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`__3`.`b` AS `b` from (`t1` join (select max(`t2`.`a`) AS `b` from `t2`) `__3`) latin1 latin1_swedish_ci +call p1; +a b +2 3 +3 3 +show create procedure p1; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +p1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +as +begin +select t1.a, b from t1, (select max(a) as b from t2); +end latin1 latin1_swedish_ci latin1_swedish_ci +drop view v1; +drop procedure p1; +drop table t1,t2; +set session sql_mode=@save_sql_mode; diff --git a/mysql-test/suite/compat/oracle/r/binlog_ptr_mysqlbinlog.result b/mysql-test/suite/compat/oracle/r/binlog_ptr_mysqlbinlog.result new file mode 100644 index 00000000..0656a685 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/binlog_ptr_mysqlbinlog.result @@ -0,0 +1,100 @@ +SET @@SQL_MODE = 'ORACLE'; +########################################################################## +# Test verifies Gtid_log_event/Xid_log_event specific print # +########################################################################## +CREATE TABLE tm (f INT) ENGINE=MYISAM; +INSERT INTO tm VALUES (10); +CREATE TABLE t(f INT) ENGINE=INNODB; +INSERT INTO t VALUES (10); +CREATE OR REPLACE PROCEDURE simpleproc (param1 OUT INT) AS +BEGIN +SELECT COUNT(*) INTO param1 FROM t; +END; +/ +CREATE FUNCTION f1 RETURN INT +AS +BEGIN +RETURN 10; +END; +/ +FLUSH LOGS; +########################################################################## +# Delete data from master so that it can be restored from binlog # +########################################################################## +DROP FUNCTION f1; +DROP PROCEDURE simpleproc; +DROP TABLE tm; +DROP TABLE t; +########################################################################## +# Post recovery using mysqlbinlog # +########################################################################## +SHOW TABLES; +Tables_in_test +t +tm +SELECT * FROM tm; +f +10 +SELECT * FROM t; +f +10 +SELECT f1(); +f1() +10 +CALL simpleproc(@a); +SELECT @a; +@a +1 +"***** Clean Up *****" +DROP TABLE t,tm; +DROP PROCEDURE simpleproc; +DROP FUNCTION f1; +RESET MASTER; +########################################################################## +# Test verifies Gtid_log_event/Xid_log_event/Qery_log_event # +# specific print along with flashback option # +########################################################################## +CREATE TABLE tm(f INT) ENGINE=MYISAM; +INSERT INTO tm VALUES (10); +INSERT INTO tm VALUES (20); +CREATE TABLE t(f INT) ENGINE=INNODB; +INSERT INTO t VALUES (10); +INSERT INTO t VALUES (20); +########################################################################## +# Initial data # +########################################################################## +SELECT * FROM tm; +f +10 +20 +SELECT * FROM t; +f +10 +20 +FLUSH LOGS; +DELETE FROM tm WHERE f=20; +DELETE FROM t WHERE f=20; +FLUSH LOGS; +########################################################################## +# Data after deletion # +########################################################################## +SELECT * FROM tm; +f +10 +SELECT * FROM t; +f +10 +FOUND 2 /START TRANSACTION/ in test.sql +########################################################################## +# Data after recovery using flashback # +########################################################################## +SELECT * FROM tm; +f +10 +20 +SELECT * FROM t; +f +10 +20 +"***** Clean Up *****" +DROP TABLE t,tm; diff --git a/mysql-test/suite/compat/oracle/r/binlog_stm_ps.result b/mysql-test/suite/compat/oracle/r/binlog_stm_ps.result new file mode 100644 index 00000000..01fe3be3 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/binlog_stm_ps.result @@ -0,0 +1,98 @@ +SET sql_mode=ORACLE; +# +# MDEV-10801 sql_mode: dynamic SQL placeholders +# +CREATE TABLE t1 (a INT, b INT); +SET @a=10, @b=20; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (?,?)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:a,:b)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:aaa,:bbb)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:"a",:"b")'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:"aaa",:"bbb")'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:1,:2)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:222,:111)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:0,:65535)'; +EXECUTE stmt USING @a, @b; +PREPARE stmt FROM 'INSERT INTO t1 VALUES (:65535,:0)'; +EXECUTE stmt USING @a, @b; +SELECT * FROM t1; +a b +10 20 +10 20 +10 20 +10 20 +10 20 +10 20 +10 20 +10 20 +10 20 +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b INT) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10,20) +master-bin.000001 # Query # # COMMIT +DROP TABLE t1; +# +# MDEV-16095 Oracle-style placeholder inside GROUP BY..WITH ROLLUP breaks replication +# +FLUSH LOGS; +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1985-05-13'),('1989-12-24'); +CREATE TABLE t2 (d DATE, c BIGINT); +BEGIN +EXECUTE IMMEDIATE 'INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, :param' USING 1; +EXECUTE IMMEDIATE 'INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, :param WITH ROLLUP' USING 1; +END; +$$ +DROP TABLE t1,t2; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Binlog_checkpoint # # master-bin.000002 +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t1 (d DATE) +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES ('1985-05-13'),('1989-12-24') +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t2 (d DATE, c BIGINT) +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, 1 +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, 1 WITH ROLLUP +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP TABLE "t1","t2" /* generated by server */ diff --git a/mysql-test/suite/compat/oracle/r/binlog_stm_sp.result b/mysql-test/suite/compat/oracle/r/binlog_stm_sp.result new file mode 100644 index 00000000..468309a0 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/binlog_stm_sp.result @@ -0,0 +1,510 @@ +SET sql_mode=ORACLE; +# +# MDEV-10914 ROW data type for stored routine variables +# +CREATE TABLE t1 (a INT, b INT); +CREATE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +rec.a:=100; +rec.b:=200; +INSERT INTO t1 VALUES (rec.a,rec.b); +INSERT INTO t1 VALUES (10, rec=ROW(100,200)); +INSERT INTO t1 VALUES (10, ROW(100,200)=rec); +INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.a:=NULL; +INSERT INTO t1 VALUES (11, rec=ROW(100,200)); +INSERT INTO t1 VALUES (11, rec=ROW(100,201)); +INSERT INTO t1 VALUES (11, ROW(100,200)=rec); +INSERT INTO t1 VALUES (11, ROW(100,201)=rec); +INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.b:=NULL; +INSERT INTO t1 VALUES (12, rec=ROW(100,200)); +INSERT INTO t1 VALUES (12, ROW(100,200)=rec); +INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=rec; +END; +$$ +CALL p1(); +SELECT * FROM t1; +a b +100 200 +10 1 +10 1 +10 20 +10 21 +11 NULL +11 0 +11 NULL +11 0 +12 NULL +12 NULL +DROP TABLE t1; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT, b INT) +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +rec ROW(a INT,b INT); +BEGIN +rec.a:=100; +rec.b:=200; +INSERT INTO t1 VALUES (rec.a,rec.b); +INSERT INTO t1 VALUES (10, rec=ROW(100,200)); +INSERT INTO t1 VALUES (10, ROW(100,200)=rec); +INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.a:=NULL; +INSERT INTO t1 VALUES (11, rec=ROW(100,200)); +INSERT INTO t1 VALUES (11, rec=ROW(100,201)); +INSERT INTO t1 VALUES (11, ROW(100,200)=rec); +INSERT INTO t1 VALUES (11, ROW(100,201)=rec); +INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.b:=NULL; +INSERT INTO t1 VALUES (12, rec=ROW(100,200)); +INSERT INTO t1 VALUES (12, ROW(100,200)=rec); +INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=rec; +END +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('rec.a',100), NAME_CONST('rec.b',200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10, ROW(100,200)=ROW(100,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (10, ROW(100,200)=ROW(100,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE ROW(100,200)=ROW(100,200) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=ROW(100,200) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(NULL,200)=ROW(100,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(NULL,200)=ROW(100,201)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(100,200)=ROW(NULL,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(100,201)=ROW(NULL,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE ROW(NULL,200)=ROW(100,200) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=ROW(NULL,200) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (12, ROW(NULL,NULL)=ROW(100,200)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (12, ROW(100,200)=ROW(NULL,NULL)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE ROW(NULL,NULL)=ROW(100,200) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=ROW(NULL,NULL) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PROCEDURE p1 +# +# Testing ROW fields in LIMIT +# +FLUSH LOGS; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(10); +CREATE TABLE t2 (a INT); +CREATE PROCEDURE p1() +AS +a INT:= 1; +rec ROW(a INT); +BEGIN +rec.a:= 1; +INSERT INTO t2 SELECT 1 FROM t1 LIMIT a; +INSERT INTO t2 SELECT 2 FROM t1 LIMIT rec.a; +END; +$$ +CALL p1(); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted +DROP TABLE t1,t2; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Binlog_checkpoint # # master-bin.000002 +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t1 (a INT) +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (10),(10) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t2 (a INT) +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +a INT:= 1; +rec ROW(a INT); +BEGIN +rec.a:= 1; +INSERT INTO t2 SELECT 1 FROM t1 LIMIT a; +INSERT INTO t2 SELECT 2 FROM t1 LIMIT rec.a; +END +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT 1 FROM t1 LIMIT 1 +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT 2 FROM t1 LIMIT 1 +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP TABLE "t1","t2" /* generated by server */ +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP PROCEDURE p1 +# +# End of MDEV-10914 ROW data type for stored routine variables +# +# +# MDEV-12133 sql_mode=ORACLE: table%ROWTYPE in variable declarations +# +CREATE TABLE t1 (a INT, b INT); +CREATE PROCEDURE p1 +AS +rec t1%ROWTYPE; +BEGIN +rec.a:=100; +rec.b:=200; +SELECT rec=ROW(100,200) AS true1, ROW(100,200)=rec AS true2; +INSERT INTO t1 VALUES (rec.a,rec.b); +INSERT INTO t1 VALUES (10, rec=ROW(100,200)); +INSERT INTO t1 VALUES (10, ROW(100,200)=rec); +INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.a:=NULL; +INSERT INTO t1 VALUES (11, rec=ROW(100,200)); +INSERT INTO t1 VALUES (11, rec=ROW(100,201)); +INSERT INTO t1 VALUES (11, ROW(100,200)=rec); +INSERT INTO t1 VALUES (11, ROW(100,201)=rec); +INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.b:=NULL; +INSERT INTO t1 VALUES (12, rec=ROW(100,200)); +INSERT INTO t1 VALUES (12, ROW(100,200)=rec); +INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=rec; +END; +$$ +CALL p1(); +true1 true2 +1 1 +SELECT * FROM t1; +a b +100 200 +10 1 +10 1 +10 20 +10 21 +11 NULL +11 0 +11 NULL +11 0 +12 NULL +12 NULL +DROP TABLE t1; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Binlog_checkpoint # # master-bin.000002 +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t1 (a INT) +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (10),(10) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t2 (a INT) +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +a INT:= 1; +rec ROW(a INT); +BEGIN +rec.a:= 1; +INSERT INTO t2 SELECT 1 FROM t1 LIMIT a; +INSERT INTO t2 SELECT 2 FROM t1 LIMIT rec.a; +END +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT 1 FROM t1 LIMIT 1 +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t2 SELECT 2 FROM t1 LIMIT 1 +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP TABLE "t1","t2" /* generated by server */ +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP PROCEDURE p1 +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE TABLE t1 (a INT, b INT) +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +rec t1%ROWTYPE; +BEGIN +rec.a:=100; +rec.b:=200; +SELECT rec=ROW(100,200) AS true1, ROW(100,200)=rec AS true2; +INSERT INTO t1 VALUES (rec.a,rec.b); +INSERT INTO t1 VALUES (10, rec=ROW(100,200)); +INSERT INTO t1 VALUES (10, ROW(100,200)=rec); +INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.a:=NULL; +INSERT INTO t1 VALUES (11, rec=ROW(100,200)); +INSERT INTO t1 VALUES (11, rec=ROW(100,201)); +INSERT INTO t1 VALUES (11, ROW(100,200)=rec); +INSERT INTO t1 VALUES (11, ROW(100,201)=rec); +INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=rec; +rec.b:=NULL; +INSERT INTO t1 VALUES (12, rec=ROW(100,200)); +INSERT INTO t1 VALUES (12, ROW(100,200)=rec); +INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE rec=ROW(100,200); +INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=rec; +END +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('rec.a',100), NAME_CONST('rec.b',200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (10, ROW(100,200)=ROW(100,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (10, ROW(100,200)=ROW(100,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 10, 20 FROM DUAL WHERE ROW(100,200)=ROW(100,200) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 10, 21 FROM DUAL WHERE ROW(100,200)=ROW(100,200) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(NULL,200)=ROW(100,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(NULL,200)=ROW(100,201)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(100,200)=ROW(NULL,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (11, ROW(100,201)=ROW(NULL,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 11, 20 FROM DUAL WHERE ROW(NULL,200)=ROW(100,200) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 11, 21 FROM DUAL WHERE ROW(100,200)=ROW(NULL,200) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (12, ROW(NULL,NULL)=ROW(100,200)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 VALUES (12, ROW(100,200)=ROW(NULL,NULL)) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 12, 20 FROM DUAL WHERE ROW(NULL,NULL)=ROW(100,200) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # BEGIN GTID #-#-# +master-bin.000002 # Query # # use `test`; INSERT INTO t1 SELECT 12, 21 FROM DUAL WHERE ROW(100,200)=ROW(NULL,NULL) +master-bin.000002 # Query # # COMMIT +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ +master-bin.000002 # Gtid # # GTID #-#-# +master-bin.000002 # Query # # use `test`; DROP PROCEDURE p1 +# +# MDEV-12291 Allow ROW variables as SELECT INTO targets +# +FLUSH LOGS; +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10, 'b10'); +CREATE TABLE t2 LIKE t1; +CREATE PROCEDURE p1 +AS +rec1 ROW(a INT, b VARCHAR(32)); +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END; +$$ +CALL p1(); +SELECT * FROM t1; +a b +10 b10 +DROP TABLE t1; +DROP TABLE t2; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000003 # Binlog_checkpoint # # master-bin.000003 +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; CREATE TABLE t1 (a INT, b VARCHAR(32)) +master-bin.000003 # Gtid # # BEGIN GTID #-#-# +master-bin.000003 # Query # # use `test`; INSERT INTO t1 VALUES (10, 'b10') +master-bin.000003 # Query # # COMMIT +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; CREATE TABLE t2 LIKE t1 +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +rec1 ROW(a INT, b VARCHAR(32)); +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END +master-bin.000003 # Gtid # # BEGIN GTID #-#-# +master-bin.000003 # Query # # use `test`; INSERT INTO t2 VALUES ( NAME_CONST('rec1.a',10), NAME_CONST('rec1.b',_latin1'b10' COLLATE 'latin1_swedish_ci')) +master-bin.000003 # Query # # COMMIT +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; DROP TABLE "t2" /* generated by server */ +master-bin.000003 # Gtid # # GTID #-#-# +master-bin.000003 # Query # # use `test`; DROP PROCEDURE p1 +FLUSH LOGS; +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10, 'b10'); +CREATE TABLE t2 LIKE t1; +CREATE PROCEDURE p1 +AS +rec1 t1%ROWTYPE; +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END; +$$ +CALL p1(); +SELECT * FROM t1; +a b +10 b10 +DROP TABLE t1; +DROP TABLE t2; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000004 # Binlog_checkpoint # # master-bin.000004 +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; CREATE TABLE t1 (a INT, b VARCHAR(32)) +master-bin.000004 # Gtid # # BEGIN GTID #-#-# +master-bin.000004 # Query # # use `test`; INSERT INTO t1 VALUES (10, 'b10') +master-bin.000004 # Query # # COMMIT +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; CREATE TABLE t2 LIKE t1 +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +rec1 t1%ROWTYPE; +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END +master-bin.000004 # Gtid # # BEGIN GTID #-#-# +master-bin.000004 # Query # # use `test`; INSERT INTO t2 VALUES ( NAME_CONST('rec1.a',10), NAME_CONST('rec1.b',_latin1'b10' COLLATE 'latin1_swedish_ci')) +master-bin.000004 # Query # # COMMIT +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; DROP TABLE "t2" /* generated by server */ +master-bin.000004 # Gtid # # GTID #-#-# +master-bin.000004 # Query # # use `test`; DROP PROCEDURE p1 +FLUSH LOGS; +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10, 'b10'); +CREATE TABLE t2 LIKE t1; +CREATE PROCEDURE p1 +AS +CURSOR cur1 IS SELECT * FROM t1; +rec1 cur1%ROWTYPE; +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END; +$$ +CALL p1(); +SELECT * FROM t1; +a b +10 b10 +DROP TABLE t1; +DROP TABLE t2; +DROP PROCEDURE p1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000005 # Binlog_checkpoint # # master-bin.000005 +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; CREATE TABLE t1 (a INT, b VARCHAR(32)) +master-bin.000005 # Gtid # # BEGIN GTID #-#-# +master-bin.000005 # Query # # use `test`; INSERT INTO t1 VALUES (10, 'b10') +master-bin.000005 # Query # # COMMIT +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; CREATE TABLE t2 LIKE t1 +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +CURSOR cur1 IS SELECT * FROM t1; +rec1 cur1%ROWTYPE; +BEGIN +SELECT * INTO rec1 FROM t1; +INSERT INTO t2 VALUES (rec1.a, rec1.b); +END +master-bin.000005 # Gtid # # BEGIN GTID #-#-# +master-bin.000005 # Query # # use `test`; INSERT INTO t2 VALUES ( NAME_CONST('rec1.a',10), NAME_CONST('rec1.b',_latin1'b10' COLLATE 'latin1_swedish_ci')) +master-bin.000005 # Query # # COMMIT +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; DROP TABLE "t2" /* generated by server */ +master-bin.000005 # Gtid # # GTID #-#-# +master-bin.000005 # Query # # use `test`; DROP PROCEDURE p1 +# +# MDEV-16020 SP variables inside GROUP BY..WITH ROLLUP break replication +# +FLUSH LOGS; +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1985-05-13'),('1989-12-24'); +CREATE TABLE t2 (d DATE, c BIGINT); +DECLARE +var INT; +BEGIN +INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, var; +INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, var WITH ROLLUP; +END; +$$ +DROP TABLE t1,t2; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000006 # Binlog_checkpoint # # master-bin.000006 +master-bin.000006 # Gtid # # GTID #-#-# +master-bin.000006 # Query # # use `test`; CREATE TABLE t1 (d DATE) +master-bin.000006 # Gtid # # BEGIN GTID #-#-# +master-bin.000006 # Query # # use `test`; INSERT INTO t1 VALUES ('1985-05-13'),('1989-12-24') +master-bin.000006 # Query # # COMMIT +master-bin.000006 # Gtid # # GTID #-#-# +master-bin.000006 # Query # # use `test`; CREATE TABLE t2 (d DATE, c BIGINT) +master-bin.000006 # Gtid # # BEGIN GTID #-#-# +master-bin.000006 # Query # # use `test`; INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, NAME_CONST('var',NULL) +master-bin.000006 # Query # # COMMIT +master-bin.000006 # Gtid # # BEGIN GTID #-#-# +master-bin.000006 # Query # # use `test`; INSERT INTO t2 SELECT d, COUNT(*) FROM t1 GROUP BY d, NAME_CONST('var',NULL) WITH ROLLUP +master-bin.000006 # Query # # COMMIT +master-bin.000006 # Gtid # # GTID #-#-# +master-bin.000006 # Query # # use `test`; DROP TABLE "t1","t2" /* generated by server */ diff --git a/mysql-test/suite/compat/oracle/r/binlog_stm_sp_package.result b/mysql-test/suite/compat/oracle/r/binlog_stm_sp_package.result new file mode 100644 index 00000000..8c1ee056 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/binlog_stm_sp_package.result @@ -0,0 +1,268 @@ +SET sql_mode=ORACLE; +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE IF NOT EXISTS p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +Warnings: +Note 1304 PACKAGE p1 already exists +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +END; +$$ +DROP PACKAGE BODY p1; +DROP PACKAGE p1; +DROP PACKAGE IF EXISTS p1; +Warnings: +Note 1305 PACKAGE test.p1 does not exist +# +# Creating a package with a COMMENT clause +# +CREATE PACKAGE p1 COMMENT 'package-p1-comment' AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 COMMENT 'package-body-p1-comment' AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +DROP PACKAGE p1; +# +# Creating a package with a different DEFINER +# +CREATE DEFINER=xxx@localhost PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +DROP PACKAGE p1; +# +# Creating a package with a different DEFINER, with SQL SECURITY INVOKER +# +CREATE DEFINER=xxx@localhost PACKAGE p1 SQL SECURITY INVOKER AS +PROCEDURE p1; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +DROP PACKAGE p1; +# +# Creating a new package in a remote database +# +CREATE DATABASE test2; +CREATE PACKAGE test2.test2 COMMENT 'package-test2-comment' AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +$$ +CREATE PACKAGE BODY test2.test2 COMMENT 'package-body-test2-comment' AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +PROCEDURE p1 AS BEGIN SELECT f1(); END; +END; +$$ +DROP PACKAGE BODY test2.test2; +DROP PACKAGE test2.test2; +DROP DATABASE test2; +# +# MDEV-13139 Package-wide variables in CREATE PACKAGE +# +CREATE TABLE t1 (a INT); +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT:=0; +PROCEDURE p1 AS +BEGIN +INSERT INTO t1 VALUES (a); +a:=a+1; +END; +BEGIN +a:=10; +END; +$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT * FROM t1; +a +10 +11 +# sp-cache-invalidate +CALL p1.p1(); +CALL p1.p1(); +SELECT * FROM t1; +a +10 +11 +10 +11 +DROP PACKAGE p1; +DROP TABLE t1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE "p1" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE IF NOT EXISTS "p1" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE BODY "p1" AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE BODY p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE IF EXISTS p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE "p1" COMMENT 'package-p1-comment' + AS +PROCEDURE p1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE BODY "p1" COMMENT 'package-body-p1-comment' + AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="xxx"@"localhost" PACKAGE "p1" AS +PROCEDURE p1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="xxx"@"localhost" PACKAGE BODY "p1" AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="xxx"@"localhost" PACKAGE "p1" SQL SECURITY INVOKER + AS +PROCEDURE p1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="xxx"@"localhost" PACKAGE BODY "p1" SQL SECURITY INVOKER + AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # CREATE DATABASE test2 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE "test2"."test2" COMMENT 'package-test2-comment' + AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE BODY "test2"."test2" COMMENT 'package-body-test2-comment' + AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +PROCEDURE p1 AS BEGIN SELECT f1(); END; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE BODY test2.test2 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE test2.test2 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # DROP DATABASE test2 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT) +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE "p1" AS +PROCEDURE p1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" PACKAGE BODY "p1" AS +a INT:=0; +PROCEDURE p1 AS +BEGIN +INSERT INTO t1 VALUES (a); +a:=a+1; +END; +BEGIN +a:=10; +END +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a',10)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a',11)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE DEFINER="root"@"localhost" FUNCTION "dummy"() RETURN int(11) +AS +BEGIN +RETURN 1; +END +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP FUNCTION dummy +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a',10)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a',11)) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP PACKAGE p1 +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE "t1" /* generated by server */ diff --git a/mysql-test/suite/compat/oracle/r/column_compression.result b/mysql-test/suite/compat/oracle/r/column_compression.result new file mode 100644 index 00000000..2709fe04 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/column_compression.result @@ -0,0 +1,1333 @@ +SET sql_mode=ORACLE; +SET column_compression_zlib_wrap=true; +CREATE TABLE t1 (a BLOB COMPRESSED); +INSERT INTO t1 VALUES (REPEAT('a',10000)); +SELECT DATA_LENGTH<100 AS c FROM INFORMATION_SCHEMA.TABLES +WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test'; +c +1 +DROP TABLE t1; +# +# MDEV-17363 - Compressed columns cannot be restored from dump +# +CREATE TABLE t1(a INT NOT NULL COMPRESSED); +ERROR 42000: Incorrect column specifier for column 'a' +SHOW WARNINGS; +Level Code Message +Error 1063 Incorrect column specifier for column 'a' +CREATE TABLE t1( +a JSON COMPRESSED, +b VARCHAR(1000) COMPRESSED BINARY, +c NVARCHAR(1000) COMPRESSED BINARY, +d TINYTEXT COMPRESSED BINARY +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid("a")), + "b" varchar(1000) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL, + "c" varchar(1000) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + "d" tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +# +# VARCHAR and TEXT variants +# +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a VARCHAR(10) BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a VARCHAR2(10) BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR2(10) BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR2(10) COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a TINYTEXT COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a TINYTEXT COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a TINYTEXT BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinytext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYTEXT BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a TINYTEXT COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a TINYTEXT COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYTEXT COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a TEXT COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a TEXT COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a TEXT BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" text /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TEXT BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a TEXT COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a TEXT COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TEXT COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a MEDIUMTEXT BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMTEXT BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMTEXT COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# The `compressed opt_binary` grammar sequence is covered. +# +CREATE TABLE t1 (a LONGTEXT COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED BINARY); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED BINARY ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED BYTE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED ASCII); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED UNICODE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a LONGTEXT COMPRESSED BYTE DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED BINARY DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED ASCII DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET utf8 DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT('a',100))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci GENERATED ALWAYS AS (repeat('a',100)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a LONGTEXT BINARY COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT ASCII COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longtext /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGTEXT BYTE COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a LONGTEXT COMPRESSED BYTE COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED ASCII COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET utf8 COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a LONGTEXT COMPRESSED BYTE DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED BINARY DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED ASCII DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET utf8 DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# VARBINARY and BLOB variables +# +# +# The following statements run without warnings. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED GENERATED ALWAYS AS (REPEAT('a',10))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ GENERATED ALWAYS AS (repeat('a',10)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a VARCHAR(10) DEFAULT '' COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(10) NULL COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a VARCHAR(10) COMPRESSED NULL COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# +CREATE TABLE t1 (a TINYBLOB COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a TINYBLOB COMPRESSED DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYBLOB COMPRESSED NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYBLOB COMPRESSED GENERATED ALWAYS AS (REPEAT('a',10))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ GENERATED ALWAYS AS (repeat('a',10)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a TINYBLOB DEFAULT '' COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a TINYBLOB NULL COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" tinyblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a TINYBLOB COMPRESSED COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a TINYBLOB COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a TINYBLOB COMPRESSED NULL COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# +CREATE TABLE t1 (a BLOB COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a BLOB COMPRESSED DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a BLOB COMPRESSED NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a BLOB COMPRESSED GENERATED ALWAYS AS (REPEAT('a',10))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ GENERATED ALWAYS AS (repeat('a',10)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a BLOB DEFAULT '' COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a BLOB NULL COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a BLOB COMPRESSED COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a BLOB COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a BLOB COMPRESSED NULL COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED GENERATED ALWAYS AS (REPEAT('a',10))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ GENERATED ALWAYS AS (repeat('a',10)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a MEDIUMBLOB DEFAULT '' COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMBLOB NULL COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mediumblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a MEDIUMBLOB COMPRESSED NULL COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements run without warnings. +# +CREATE TABLE t1 (a LONGBLOB COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements run without warnings. +# They have extra column attributes (or GENERATED) after COMPRESSED. +# +CREATE TABLE t1 (a LONGBLOB COMPRESSED DEFAULT ''); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGBLOB COMPRESSED NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGBLOB COMPRESSED GENERATED ALWAYS AS (REPEAT('a',10))); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ GENERATED ALWAYS AS (repeat('a',10)) VIRTUAL +) +DROP TABLE t1; +# +# The following statements return deprecated syntax warnings +# +CREATE TABLE t1 (a LONGBLOB DEFAULT '' COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT '' +) +DROP TABLE t1; +CREATE TABLE t1 (a LONGBLOB NULL COMPRESSED); +Warnings: +Warning 1287 ' ... COMPRESSED...' is deprecated and will be removed in a future release. Please use ' COMPRESSED... ...' instead +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" longblob /*!100301 COMPRESSED*/ DEFAULT NULL +) +DROP TABLE t1; +# +# The following statements fail by the grammar, +# because COMPRESSED immediately follows 'field_type'. +# +CREATE TABLE t1 (a LONGBLOB COMPRESSED COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# The following statements are not prohibited by the *.yy grammar, +# because the sequence `field_type attribute COMPRESSED` is allowed +# (notice there is at least one attribute after `field_type`). +# The first COMPRESSED is parsed inside `field_type`. +# The second COMPRESSED passes through the parser but then is caught +# inside Column_definition::set_compressed_deprecated_with_type_check() +# and a syntax error is raised. +# +CREATE TABLE t1 (a LONGBLOB COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a LONGBLOB COMPRESSED NULL COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +# +# NVARCHAR +# +CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(10) /*!100301 COMPRESSED*/ CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED BINARY COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 +CREATE TABLE t1 (a NVARCHAR(10) COMPRESSED DEFAULT '' COMPRESSED); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPRESSED)' at line 1 diff --git a/mysql-test/suite/compat/oracle/r/custom_aggregate_functions.result b/mysql-test/suite/compat/oracle/r/custom_aggregate_functions.result new file mode 100644 index 00000000..21fac193 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/custom_aggregate_functions.result @@ -0,0 +1,136 @@ +SET sql_mode=ORACLE; +create aggregate function f1(x INT) return INT AS +begin +insert into t1(sal) values (x); +return x; +end| +ERROR HY000: Aggregate specific instruction(FETCH GROUP NEXT ROW) missing from the aggregate function +create function f1(x INT) return INT AS +begin +set x=5; +fetch group next row; +return x+1; +end | +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE TABLE marks(stud_id INT, grade_count INT); +INSERT INTO marks VALUES (1,6), (2,4), (3,7), (4,5), (5,8); +SELECT * FROM marks; +stud_id grade_count +1 6 +2 4 +3 7 +4 5 +5 8 +# Using PL/SQL syntax: EXCEPTION WHEN NO_DATA_FOUND +CREATE AGGREGATE FUNCTION IF NOT EXISTS aggregate_count(x INT) RETURN INT AS +count_students INT DEFAULT 0; +BEGIN +LOOP +FETCH GROUP NEXT ROW; +IF x THEN +count_students:= count_students + 1; +END IF; +END LOOP; +EXCEPTION +WHEN NO_DATA_FOUND THEN +RETURN count_students; +END aggregate_count // +SELECT aggregate_count(stud_id) FROM marks; +aggregate_count(stud_id) +5 +DROP FUNCTION IF EXISTS aggregate_count; +# Using SQL/PSM systax: CONTINUE HANDLER +CREATE AGGREGATE FUNCTION IF NOT EXISTS aggregate_count(x INT) RETURN INT AS +count_students INT DEFAULT 0; +CONTINUE HANDLER FOR NOT FOUND RETURN count_students; +BEGIN +LOOP +FETCH GROUP NEXT ROW; +IF x THEN +SET count_students= count_students + 1; +END IF; +END LOOP; +END // +SELECT aggregate_count(stud_id) FROM marks; +aggregate_count(stud_id) +5 +DROP FUNCTION IF EXISTS aggregate_count; +DROP TABLE marks; +# +# MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW +# +CREATE PROCEDURE p1 AS +BEGIN +FETCH GROUP NEXT ROW; +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +BEGIN NOT ATOMIC +FETCH GROUP NEXT ROW; +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE DEFINER=root@localhost FUNCTION f1 RETURN INT AS +BEGIN +FETCH GROUP NEXT ROW; +RETURN 0; +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1 +AFTER INSERT ON t1 FOR EACH ROW +FETCH GROUP NEXT ROW; +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +DROP TABLE t1; +CREATE EVENT ev1 +ON SCHEDULE EVERY 1 HOUR +STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH +ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK +DO FETCH GROUP NEXT ROW; +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +FETCH GROUP NEXT ROW; -- In a package procedure +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 0; +END; +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +FUNCTION f1 RETURN INT AS +BEGIN +FETCH GROUP NEXT ROW; -- In a package function +RETURN 0; +END; +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 0; +END; +BEGIN +FETCH GROUP NEXT ROW; -- In a package executable section +END; +$$ +ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context +DROP PACKAGE pkg1; diff --git a/mysql-test/suite/compat/oracle/r/empty_string_literal.result b/mysql-test/suite/compat/oracle/r/empty_string_literal.result new file mode 100644 index 00000000..4af576e9 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/empty_string_literal.result @@ -0,0 +1,181 @@ +USE test; +# +# MDEV-14013 : sql_mode=EMPTY_STRING_IS_NULL +# +set @mode='ORACLE,EMPTY_STRING_IS_NULL'; +SET SESSION character_set_connection=latin2; +SET SESSION character_set_client=cp1250; +# +# Test litteral +# +SET sql_mode=@mode; +select @@sql_mode; +@@sql_mode +PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,EMPTY_STRING_IS_NULL,SIMULTANEOUS_ASSIGNMENT +SELECT '',CHARSET(''), null, CHARSET(null), CAST(null as char(10)), CHARSET(CAST(null as char(10))), 'x', CHARSET('x'); +NULL CHARSET('') NULL CHARSET(null) CAST(null as char(10)) CHARSET(CAST(null as char(10))) x CHARSET('x') +NULL latin2 NULL binary NULL latin2 x latin2 +SELECT CHARSET(NULLIF('','')),NULLIF('',''); +CHARSET(NULLIF('','')) NULLIF('','') +latin2 NULL +SET sql_mode=default; +SELECT '',CHARSET(''), null, CHARSET(null), CAST(null as char(10)), CHARSET(CAST(null as char(10))), 'x', CHARSET('x'); + CHARSET('') NULL CHARSET(null) CAST(null as char(10)) CHARSET(CAST(null as char(10))) x CHARSET('x') + latin2 NULL binary NULL latin2 x latin2 +SELECT CHARSET(NULLIF('','')),NULLIF('',''); +CHARSET(NULLIF('','')) NULLIF('','') +latin2 NULL +# +# Test NCHAR litteral +# +SET sql_mode=@mode; +SELECT N'',CHARSET(N''), N'x', CHARSET(N'x'); +NULL CHARSET(N'') x CHARSET(N'x') +NULL utf8mb3 x utf8mb3 +SELECT CHARSET(NULLIF(N'',N'')),NULLIF(N'',N''); +CHARSET(NULLIF(N'',N'')) NULLIF(N'',N'') +utf8mb3 NULL +SET sql_mode=default; +SELECT N'',CHARSET(N''), N'x', CHARSET(N'x'); + CHARSET(N'') x CHARSET(N'x') + utf8mb3 x utf8mb3 +SELECT CHARSET(NULLIF(N'',N'')),NULLIF(N'',N''); +CHARSET(NULLIF(N'',N'')) NULLIF(N'',N'') +utf8mb3 NULL +# +# Test CHARSET prefix litteral +# +SET sql_mode=@mode; +SELECT _cp1250 '',CHARSET(_cp1250 ''), _cp1250 'x', CHARSET(_cp1250 'x'); +NULL CHARSET(_cp1250 '') x CHARSET(_cp1250 'x') +NULL cp1250 x cp1250 +SELECT CHARSET(NULLIF(_cp1250 '',_cp1250 '')),NULLIF(_cp1250 '',_cp1250 ''); +CHARSET(NULLIF(_cp1250 '',_cp1250 '')) NULLIF(_cp1250 '',_cp1250 '') +cp1250 NULL +SET sql_mode=default; +SELECT _cp1250 '',CHARSET(_cp1250 ''), _cp1250 'x', CHARSET(_cp1250 'x'); + CHARSET(_cp1250 '') x CHARSET(_cp1250 'x') + cp1250 x cp1250 +SELECT CHARSET(NULLIF(_cp1250 '',_cp1250 '')),NULLIF(_cp1250 '',_cp1250 ''); +CHARSET(NULLIF(_cp1250 '',_cp1250 '')) NULLIF(_cp1250 '',_cp1250 '') +cp1250 NULL +SET sql_mode=@mode; +# +# Test litteral concat +# +SELECT 'a' 'b'; +a +ab +SELECT 'a' ''; +a +a +SELECT '' 'b'; +b +b +SELECT '' ''; +NULL +NULL +SELECT '' 'b' 'c'; +b +bc +SELECT '' '' 'c'; +c +c +SELECT 'a' '' 'c'; +a +ac +SELECT 'a' '' ''; +a +a +SELECT '' '' ''; +NULL +NULL +SELECT '' '' '',CHARSET('' '' ''); +NULL CHARSET('' '' '') +NULL latin2 +SELECT _latin1'' '' '',CHARSET(_latin1'' '' ''); +NULL CHARSET(_latin1'' '' '') +NULL latin1 +SELECT N'' '' '',CHARSET(N'' '' ''); +NULL CHARSET(N'' '' '') +NULL utf8mb3 +# +# UNION - implicit group by +# +SELECT 1, null +UNION +SELECT 1 , '' +ORDER BY 1; +1 NULL +1 NULL +SELECT 1, null +UNION +SELECT 1 , N'' +ORDER BY 1; +1 NULL +1 NULL +SELECT 1, null +UNION +SELECT 1 , _cp1250 '' +ORDER BY 1; +1 NULL +1 NULL +SELECT NULLIF(_cp1250 '',_cp1250 '') +UNION +SELECT NULLIF(N'',N''); +NULLIF(_cp1250 '',_cp1250 '') +NULL +SELECT 1 , _latin2 '' +UNION +SELECT 1 , _cp1250 ''; +ERROR HY000: Illegal mix of collations (latin2_general_ci,IGNORABLE) and (cp1250_general_ci,IGNORABLE) for operation 'UNION' +SELECT 1, null +UNION +SELECT 1 , '' +UNION +SELECT 1 , N''; +1 NULL +1 NULL +CREATE TABLE t1 (c1 INT,c2 VARCHAR(10)); +INSERT INTO t1 VALUES (1,'one'); +INSERT INTO t1 VALUES (1,''); +INSERT INTO t1 VALUES (1,null); +# +# Test in a view +# +CREATE VIEW v1 +AS SELECT c1, c2 +FROM t1 +UNION +SELECT c1 , '' + FROM t1 +ORDER BY 1,2; +SELECT * FROM v1; +c1 c2 +1 NULL +1 one +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select "t1"."c1" AS "c1","t1"."c2" AS "c2" from "t1" union select "t1"."c1" AS "c1",NULL AS "NULL" from "t1" order by 1,2 cp1250 latin2_general_ci +DROP VIEW v1; +DROP TABLE t1; +EXPLAIN EXTENDED SELECT ''; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select NULL AS "NULL" +EXPLAIN EXTENDED SELECT _latin1''; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select NULL AS "NULL" +EXPLAIN EXTENDED SELECT N''; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select NULL AS "NULL" +EXPLAIN EXTENDED SELECT '' ''; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select NULL AS "NULL" diff --git a/mysql-test/suite/compat/oracle/r/events.result b/mysql-test/suite/compat/oracle/r/events.result new file mode 100644 index 00000000..1f62e2e5 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/events.result @@ -0,0 +1,27 @@ +set sql_mode='ORACLE'; +# +# MDEV-16891 EVENTs created with SQL_MODE=ORACLE fail to execute +# +SET GLOBAL event_scheduler=off; +SET sql_mode='ORACLE'; +CREATE TABLE t1 (a TIMESTAMP); +CREATE EVENT e1 +ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MICROSECOND +DO INSERT INTO t1 VALUES(NOW()); +Warnings: +Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. +SET GLOBAL event_scheduler=on; +SELECT COUNT(*) FROM t1; +COUNT(*) +1 +DROP TABLE t1; +SET GLOBAL event_scheduler=off; +# +# MDEV-28588 SIGSEGV in __memmove_avx_unaligned_erms, strmake_root +# +CREATE EVENT ev ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO BEGIN END; +Warnings: +Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. +SELECT EVENT_DEFINITION FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='test' AND EVENT_NAME='ev'; +EVENT_DEFINITION BEGIN END +DROP EVENT ev; diff --git a/mysql-test/suite/compat/oracle/r/exception.result b/mysql-test/suite/compat/oracle/r/exception.result new file mode 100644 index 00000000..3bd23980 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/exception.result @@ -0,0 +1,409 @@ +SET sql_mode=ORACLE; +# +# sql_mode=ORACLE: Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX +# +# +# Testing NO_DATA_FOUND and TOO_MANY_ROWS +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1(lim INT, res OUT VARCHAR) +AS +a INT; +BEGIN +SELECT a INTO a FROM t1 LIMIT lim; +EXCEPTION +WHEN TOO_MANY_ROWS THEN res:='--- too_many_rows cought ---'; +WHEN NO_DATA_FOUND THEN res:='--- no_data_found cought ---'; +END; +$$ +SET @res=''; +CALL p1(0, @res); +SELECT @res; +@res +--- no_data_found cought --- +CALL p1(2, @res); +SELECT @res; +@res +--- too_many_rows cought --- +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing DUP_VAL_ON_INDEX +# +CREATE TABLE t1 (a INT PRIMARY KEY); +CREATE PROCEDURE p1(res OUT VARCHAR) +AS +BEGIN +INSERT INTO t1 VALUES (10); +INSERT INTO t1 VALUES (10); +EXCEPTION +WHEN DUP_VAL_ON_INDEX THEN res:='--- dup_val_on_index cought ---'; +END; +$$ +SET @res=''; +CALL p1(@res); +SELECT @res; +@res +--- dup_val_on_index cought --- +SELECT * FROM t1; +a +10 +DROP PROCEDURE p1; +DROP TABLE t1; +# +# MDEV-10840 sql_mode=ORACLE: RAISE statement for predefined exceptions +# +# +# RAISE outside of an SP context +# +RAISE NO_DATA_FOUND; +ERROR 42000: Undefined CONDITION: NO_DATA_FOUND +RAISE INVALID_CURSOR; +ERROR 42000: Undefined CONDITION: INVALID_CURSOR +RAISE DUP_VAL_ON_INDEX; +ERROR 42000: Undefined CONDITION: DUP_VAL_ON_INDEX +RAISE TOO_MANY_ROWS; +ERROR 42000: Undefined CONDITION: TOO_MANY_ROWS +RAISE; +ERROR 0K000: RESIGNAL when handler not active +# +# RAISE for an undefinite exception +# +CREATE PROCEDURE p1 +AS +BEGIN +RAISE xxx; +END; +$$ +ERROR 42000: Undefined CONDITION: xxx +# +# RAISE for predefined exceptions +# +CREATE PROCEDURE p1 +AS +BEGIN +RAISE no_data_found; +END; +$$ +CALL p1(); +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +DROP PROCEDURE p1; +CREATE PROCEDURE p1 +AS +BEGIN +RAISE invalid_cursor; +END; +$$ +CALL p1(); +ERROR 24000: Cursor is not open +DROP PROCEDURE p1; +CREATE PROCEDURE p1 +AS +BEGIN +RAISE dup_val_on_index; +END; +$$ +CALL p1(); +ERROR 23000: Duplicate entry '%-.192T' for key %d +DROP PROCEDURE p1; +CREATE PROCEDURE p1 +AS +BEGIN +raise too_many_rows; +END; +$$ +CALL p1(); +ERROR 42000: Result consisted of more than one row +DROP PROCEDURE p1; +# +# RAISE with no exception name (resignal) +# +CREATE PROCEDURE p1() +AS +BEGIN +RAISE; +END; +$$ +CALL p1(); +ERROR 0K000: RESIGNAL when handler not active +DROP PROCEDURE p1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1(lim INT) +AS +a INT; +BEGIN +SELECT a INTO a FROM t1 LIMIT lim; +EXCEPTION +WHEN TOO_MANY_ROWS THEN RAISE; +WHEN NO_DATA_FOUND THEN RAISE; +END; +$$ +CALL p1(0); +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +CALL p1(2); +ERROR 42000: Result consisted of more than one row +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1(lim INT) +AS +a INT; +BEGIN +SELECT a INTO a FROM t1 LIMIT lim; +EXCEPTION +WHEN OTHERS THEN RAISE; +END; +$$ +CALL p1(0); +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +CALL p1(2); +ERROR 42000: Result consisted of more than one row +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +a INT; +CURSOR c IS SELECT a FROM t1; +BEGIN +FETCH c INTO a; +EXCEPTION +WHEN INVALID_CURSOR THEN RAISE; +END; +$$ +CALL p1(); +ERROR 24000: Cursor is not open +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +a INT; +CURSOR c IS SELECT a FROM t1; +BEGIN +FETCH c INTO a; +EXCEPTION +WHEN OTHERS THEN RAISE; +END; +$$ +CALL p1(); +ERROR 24000: Cursor is not open +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing that warning-alike errors are caught by OTHERS +# +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1 RETURN VARCHAR +AS +a INT:=10; +BEGIN +SELECT a INTO a FROM t1; +RETURN 'OK'; +EXCEPTION +WHEN OTHERS THEN RETURN 'Exception'; +END; +$$ +SELECT f1() FROM DUAL; +f1() +Exception +DROP FUNCTION f1; +DROP TABLE t1; +# +# End of MDEV-10840 sql_mode=ORACLE: RAISE statement for predefined exceptions +# +# +# MDEV-10587 sql_mode=ORACLE: User defined exceptions +# +# +# Checking that duplicate WHEN clause is not allowed +# +CREATE FUNCTION f1() RETURN VARCHAR +AS +e EXCEPTION; +BEGIN +RETURN 'Got no exceptions'; +EXCEPTION +WHEN e THEN RETURN 'Got exception e'; +WHEN e THEN RETURN 'Got exception e'; +END; +$$ +ERROR 42000: Duplicate handler declared in the same block +# +# Checking that raised user exceptions are further caught by name +# +CREATE FUNCTION f1(c VARCHAR) RETURN VARCHAR +AS +e EXCEPTION; +f EXCEPTION; +BEGIN +IF c = 'e' THEN RAISE e; END IF; +IF c = 'f' THEN RAISE f; END IF; +RETURN 'Got no exceptions'; +EXCEPTION +WHEN e THEN RETURN 'Got exception e'; +END; +$$ +SELECT f1(''); +f1('') +Got no exceptions +SELECT f1('e'); +f1('e') +Got exception e +SELECT f1('f'); +ERROR 45000: Unhandled user-defined exception condition +DROP FUNCTION f1; +# +# Checking that raised user exceptions are further caught by OTHERS +# +CREATE FUNCTION f1(c VARCHAR) RETURN VARCHAR +AS +e EXCEPTION; +f EXCEPTION; +BEGIN +IF c = 'e' THEN RAISE e; END IF; +IF c = 'f' THEN RAISE f; END IF; +RETURN 'Got no exceptions'; +EXCEPTION +WHEN OTHERS THEN RETURN 'Got some exception'; +END; +$$ +SELECT f1(''); +f1('') +Got no exceptions +SELECT f1('e'); +f1('e') +Got some exception +SELECT f1('f'); +f1('f') +Got some exception +DROP FUNCTION f1; +# +# Checking that 'WHEN e .. WHEN f' does not produce ER_SP_DUP_HANDLER +# +CREATE FUNCTION f1(c VARCHAR) RETURN VARCHAR +AS +e EXCEPTION; +f EXCEPTION; +a VARCHAR(64):=''; +BEGIN +BEGIN +IF c = 'e' THEN RAISE e; END IF; +IF c = 'f' THEN RAISE f; END IF; +EXCEPTION +WHEN e THEN BEGIN a:='Got EXCEPTION1/e; '; RAISE e; END; +WHEN f THEN BEGIN a:='Got EXCEPTION1/f; '; RAISE f; END; +END; +RETURN 'Got no exceptions'; +EXCEPTION +WHEN OTHERS THEN RETURN a || 'Got EXCEPTION2/OTHERS;'; +END; +$$ +SELECT f1(''); +f1('') +Got no exceptions +SELECT f1('e'); +f1('e') +Got EXCEPTION1/e; Got EXCEPTION2/OTHERS; +SELECT f1('f'); +f1('f') +Got EXCEPTION1/f; Got EXCEPTION2/OTHERS; +DROP FUNCTION f1; +# +# Checking that resignaled user exceptions are further caught by name +# +CREATE FUNCTION f1(c VARCHAR) RETURN VARCHAR +AS +e EXCEPTION; +f EXCEPTION; +a VARCHAR(64):=''; +BEGIN +BEGIN +IF c = 'e' THEN RAISE e; END IF; +IF c = 'f' THEN RAISE f; END IF; +EXCEPTION +WHEN e THEN BEGIN a:='Got EXCEPTION1/e; '; RAISE; END; +WHEN f THEN BEGIN a:='Got EXCEPTION1/f; '; RAISE; END; +END; +RETURN 'Got no exceptions'; +EXCEPTION +WHEN e THEN RETURN a || 'Got EXCEPTION2/e;'; +END; +$$ +SELECT f1(''); +f1('') +Got no exceptions +SELECT f1('e'); +f1('e') +Got EXCEPTION1/e; Got EXCEPTION2/e; +SELECT f1('f'); +ERROR 45000: Unhandled user-defined exception condition +DROP FUNCTION f1; +# +# Checking that resignaled user exceptions are further caught by OTHERS +# +CREATE FUNCTION f1(c VARCHAR) RETURN VARCHAR +AS +e EXCEPTION; +f EXCEPTION; +a VARCHAR(64):=''; +BEGIN +BEGIN +IF c = 'e' THEN RAISE e; END IF; +IF c = 'f' THEN RAISE f; END IF; +EXCEPTION +WHEN e THEN BEGIN a:='Got EXCEPTION1/e; '; RAISE; END; +WHEN f THEN BEGIN a:='Got EXCEPTION1/f; '; RAISE; END; +END; +RETURN 'Got no exceptions'; +EXCEPTION +WHEN OTHERS THEN RETURN a || 'Got EXCEPTION2/OTHERS;'; +END; +$$ +SELECT f1(''); +f1('') +Got no exceptions +SELECT f1('e'); +f1('e') +Got EXCEPTION1/e; Got EXCEPTION2/OTHERS; +SELECT f1('f'); +f1('f') +Got EXCEPTION1/f; Got EXCEPTION2/OTHERS; +DROP FUNCTION f1; +# +# End of MDEV-10587 sql_mode=ORACLE: User defined exceptions +# +# +# MDEV-12088 sql_mode=ORACLE: Do not require BEGIN..END in multi-statement exception handlers in THEN clause +# +CREATE TABLE t1 (a INT PRIMARY KEY); +INSERT INTO t1 VALUES (10),(20),(30); +CREATE PROCEDURE p1(a INT) AS +BEGIN +INSERT INTO t1 (a) VALUES (a); +EXCEPTION +WHEN DUP_VAL_ON_INDEX THEN +a:= a+1; +INSERT INTO t1 VALUES (a); +WHEN OTHERS THEN +NULL; +NULL; +END; +$$ +CALL p1(30); +SELECT * FROM t1; +a +10 +20 +30 +31 +DROP PROCEDURE p1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/func_add_months.result b/mysql-test/suite/compat/oracle/r/func_add_months.result new file mode 100644 index 00000000..0502c20f --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_add_months.result @@ -0,0 +1,91 @@ +Test for ADD_MONTHS +CREATE TABLE t1(c1 int, c2 datetime, c3 date, c4 time, c5 timestamp); +INSERT INTO t1 VALUES (1, '2011-11-12 12:10:11', '2011-11-12', '12:10:11', '2011-11-12 12:10:11'); +INSERT INTO t1 VALUES (2, '2021-11-12 00:23:12', '2021-11-12', '00:23:12', '2021-11-12 00:23:12'); +INSERT INTO t1 VALUES (3, '2011-01-22 16:45:45', '2011-01-22', '16:45:45', '2011-01-22 16:45:45'); +INSERT INTO t1 VALUES (4, '2031-05-12 04:11:34', '2031-05-12', '04:11:34', '2031-05-12 04:11:34'); +INSERT INTO t1 VALUES (5, '2031-09-02 08:15:22', '2031-09-02', '08:15:22', '2031-09-02 08:15:22'); +INSERT INTO t1 VALUES (6, '0000-09-02 00:00:00', '0000-09-02', '00:00:00', '1980-09-02 00:00:00'); +INSERT INTO t1 VALUES (7, '9999-09-02', '9999-09-02', '00:00:00', '1980-09-02'); +SELECT c1, ADD_MONTHS(c2, 2), ADD_MONTHS(c3, 2), ADD_MONTHS(c5, 2) FROM t1; +c1 ADD_MONTHS(c2, 2) ADD_MONTHS(c3, 2) ADD_MONTHS(c5, 2) +1 2012-01-12 12:10:11 2012-01-12 2012-01-12 12:10:11 +2 2022-01-12 00:23:12 2022-01-12 2022-01-12 00:23:12 +3 2011-03-22 16:45:45 2011-03-22 2011-03-22 16:45:45 +4 2031-07-12 04:11:34 2031-07-12 2031-07-12 04:11:34 +5 2031-11-02 08:15:22 2031-11-02 2031-11-02 08:15:22 +6 0000-11-02 00:00:00 0000-11-02 1980-11-02 00:00:00 +7 9999-11-02 00:00:00 9999-11-02 1980-11-02 00:00:00 +SELECT c1, ADD_MONTHS(c2, 15), ADD_MONTHS(c3, 200), ADD_MONTHS(c5, 2000) FROM t1; +c1 ADD_MONTHS(c2, 15) ADD_MONTHS(c3, 200) ADD_MONTHS(c5, 2000) +1 2013-02-12 12:10:11 2028-07-12 2178-07-12 12:10:11 +2 2023-02-12 00:23:12 2038-07-12 2188-07-12 00:23:12 +3 2012-04-22 16:45:45 2027-09-22 2177-09-22 16:45:45 +4 2032-08-12 04:11:34 2048-01-12 2198-01-12 04:11:34 +5 2032-12-02 08:15:22 2048-05-02 2198-05-02 08:15:22 +6 0001-12-02 00:00:00 0017-05-02 2147-05-02 00:00:00 +7 NULL NULL 2147-05-02 00:00:00 +Warnings: +Warning 1441 Datetime function: datetime field overflow +Warning 1441 Datetime function: datetime field overflow +SELECT c1, ADD_MONTHS(c2, 0), ADD_MONTHS(c3, -200), ADD_MONTHS(c5, -2) FROM t1; +c1 ADD_MONTHS(c2, 0) ADD_MONTHS(c3, -200) ADD_MONTHS(c5, -2) +1 2011-11-12 12:10:11 1995-03-12 2011-09-12 12:10:11 +2 2021-11-12 00:23:12 2005-03-12 2021-09-12 00:23:12 +3 2011-01-22 16:45:45 1994-05-22 2010-11-22 16:45:45 +4 2031-05-12 04:11:34 2014-09-12 2031-03-12 04:11:34 +5 2031-09-02 08:15:22 2015-01-02 2031-07-02 08:15:22 +6 0000-09-02 00:00:00 NULL 1980-07-02 00:00:00 +7 9999-09-02 00:00:00 9983-01-02 1980-07-02 00:00:00 +Warnings: +Warning 1441 Datetime function: datetime field overflow +SELECT c1, ADD_MONTHS(c2, -15), ADD_MONTHS(c3, -111), ADD_MONTHS(c5, 2) FROM t1; +c1 ADD_MONTHS(c2, -15) ADD_MONTHS(c3, -111) ADD_MONTHS(c5, 2) +1 2010-08-12 12:10:11 2002-08-12 2012-01-12 12:10:11 +2 2020-08-12 00:23:12 2012-08-12 2022-01-12 00:23:12 +3 2009-10-22 16:45:45 2001-10-22 2011-03-22 16:45:45 +4 2030-02-12 04:11:34 2022-02-12 2031-07-12 04:11:34 +5 2030-06-02 08:15:22 2022-06-02 2031-11-02 08:15:22 +6 NULL NULL 1980-11-02 00:00:00 +7 9998-06-02 00:00:00 9990-06-02 1980-11-02 00:00:00 +Warnings: +Warning 1441 Datetime function: datetime field overflow +Warning 1441 Datetime function: datetime field overflow +SELECT ADD_MONTHS(c4, 11) FROM t1 WHERE c1 = 1; +ADD_MONTHS(c4, 11) +NULL +Warnings: +Warning 1441 Datetime function: time field overflow +UPDATE t1 SET c2=ADD_MONTHS(c2, 2); +SELECT c2 FROM t1; +c2 +2012-01-12 12:10:11 +2022-01-12 00:23:12 +2011-03-22 16:45:45 +2031-07-12 04:11:34 +2031-11-02 08:15:22 +0000-11-02 00:00:00 +9999-11-02 00:00:00 +EXPLAIN EXTENDED SELECT c1, ADD_MONTHS(c2, -15) FROM t1 WHERE c1 = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` + interval -15 month AS `ADD_MONTHS(c2, -15)` from `test`.`t1` where `test`.`t1`.`c1` = 1 +SELECT ADD_MONTHS("2000-10-10", 12); +ADD_MONTHS("2000-10-10", 12) +2001-10-10 +SELECT ADD_MONTHS("2000:10:10", 12); +ADD_MONTHS("2000:10:10", 12) +2001-10-10 +SELECT ADD_MONTHS(2000, 12); +ADD_MONTHS(2000, 12) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '2000' +SELECT ADD_MONTHS('2011-01-31', 1), ADD_MONTHS('2012-01-31', 1), ADD_MONTHS('2012-01-31', 2), ADD_MONTHS('2012-01-31', 3); +ADD_MONTHS('2011-01-31', 1) ADD_MONTHS('2012-01-31', 1) ADD_MONTHS('2012-01-31', 2) ADD_MONTHS('2012-01-31', 3) +2011-02-28 2012-02-29 2012-03-31 2012-04-30 +SELECT ADD_MONTHS('2011-01-30', 1), ADD_MONTHS('2012-01-30', 1), ADD_MONTHS('2012-01-30', 2), ADD_MONTHS('2012-01-30', 3); +ADD_MONTHS('2011-01-30', 1) ADD_MONTHS('2012-01-30', 1) ADD_MONTHS('2012-01-30', 2) ADD_MONTHS('2012-01-30', 3) +2011-02-28 2012-02-29 2012-03-30 2012-04-30 +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/func_case.result b/mysql-test/suite/compat/oracle/r/func_case.result new file mode 100644 index 00000000..dfe2d165 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_case.result @@ -0,0 +1,7 @@ +SET sql_mode=ORACLE; +SELECT NVL(NULL, 'a'), NVL('a', 'b'); +NVL(NULL, 'a') NVL('a', 'b') +a a +SELECT NVL2(NULL, 'a', 'b'), NVL2('a', 'b', 'c'); +NVL2(NULL, 'a', 'b') NVL2('a', 'b', 'c') +b b diff --git a/mysql-test/suite/compat/oracle/r/func_concat.result b/mysql-test/suite/compat/oracle/r/func_concat.result new file mode 100644 index 00000000..392d5797 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_concat.result @@ -0,0 +1,393 @@ +SET sql_mode=ORACLE; +EXPLAIN EXTENDED SELECT 'a'||'b'||'c'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(concat_operator_oracle('a','b'),'c') AS "'a'||'b'||'c'" +EXPLAIN EXTENDED SELECT CONCAT('a'||'b'||'c'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(concat_operator_oracle(concat_operator_oracle('a','b'),'c')) AS "CONCAT('a'||'b'||'c')" +SELECT '' || ''; +'' || '' + +SELECT '' || 'b'; +'' || 'b' +b +SELECT '' || NULL; +'' || NULL + +SELECT 'a' || ''; +'a' || '' +a +SELECT 'a' || 'b'; +'a' || 'b' +ab +SELECT 'a' || NULL; +'a' || NULL +a +SELECT NULL || ''; +NULL || '' + +SELECT NULL || 'b'; +NULL || 'b' +b +SELECT NULL || NULL; +NULL || NULL +NULL +SELECT '' || '' || ''; +'' || '' || '' + +SELECT '' || '' || 'c'; +'' || '' || 'c' +c +SELECT '' || '' || NULL; +'' || '' || NULL + +SELECT '' || 'b' || ''; +'' || 'b' || '' +b +SELECT '' || 'b' || 'c'; +'' || 'b' || 'c' +bc +SELECT '' || 'b' || NULL; +'' || 'b' || NULL +b +SELECT '' || NULL || ''; +'' || NULL || '' + +SELECT '' || NULL || 'c'; +'' || NULL || 'c' +c +SELECT '' || NULL || NULL; +'' || NULL || NULL + +SELECT 'a' || '' || ''; +'a' || '' || '' +a +SELECT 'a' || '' || 'c'; +'a' || '' || 'c' +ac +SELECT 'a' || '' || NULL; +'a' || '' || NULL +a +SELECT 'a' || 'b' || ''; +'a' || 'b' || '' +ab +SELECT 'a' || 'b' || 'c'; +'a' || 'b' || 'c' +abc +SELECT 'a' || 'b' || NULL; +'a' || 'b' || NULL +ab +SELECT 'a' || NULL || ''; +'a' || NULL || '' +a +SELECT 'a' || NULL || 'c'; +'a' || NULL || 'c' +ac +SELECT 'a' || NULL || NULL; +'a' || NULL || NULL +a +SELECT NULL || '' || ''; +NULL || '' || '' + +SELECT NULL || '' || 'c'; +NULL || '' || 'c' +c +SELECT NULL || '' || NULL; +NULL || '' || NULL + +SELECT NULL || 'b' || ''; +NULL || 'b' || '' +b +SELECT NULL || 'b' || 'c'; +NULL || 'b' || 'c' +bc +SELECT NULL || 'b' || NULL; +NULL || 'b' || NULL +b +SELECT NULL || NULL || ''; +NULL || NULL || '' + +SELECT NULL || NULL || 'c'; +NULL || NULL || 'c' +c +SELECT NULL || NULL || NULL; +NULL || NULL || NULL +NULL +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10), c VARCHAR(10)); +INSERT INTO t1 VALUES ('', '', ''); +INSERT INTO t1 VALUES ('', '', 'c'); +INSERT INTO t1 VALUES ('', '', NULL); +INSERT INTO t1 VALUES ('', 'b', ''); +INSERT INTO t1 VALUES ('', 'b', 'c'); +INSERT INTO t1 VALUES ('', 'b', NULL); +INSERT INTO t1 VALUES ('', NULL, ''); +INSERT INTO t1 VALUES ('', NULL, 'c'); +INSERT INTO t1 VALUES ('', NULL, NULL); +INSERT INTO t1 VALUES ('a', '', ''); +INSERT INTO t1 VALUES ('a', '', 'c'); +INSERT INTO t1 VALUES ('a', '', NULL); +INSERT INTO t1 VALUES ('a', 'b', ''); +INSERT INTO t1 VALUES ('a', 'b', 'c'); +INSERT INTO t1 VALUES ('a', 'b', NULL); +INSERT INTO t1 VALUES ('a', NULL, ''); +INSERT INTO t1 VALUES ('a', NULL, 'c'); +INSERT INTO t1 VALUES ('a', NULL, NULL); +INSERT INTO t1 VALUES (NULL, '', ''); +INSERT INTO t1 VALUES (NULL, '', 'c'); +INSERT INTO t1 VALUES (NULL, '', NULL); +INSERT INTO t1 VALUES (NULL, 'b', ''); +INSERT INTO t1 VALUES (NULL, 'b', 'c'); +INSERT INTO t1 VALUES (NULL, 'b', NULL); +INSERT INTO t1 VALUES (NULL, NULL, ''); +INSERT INTO t1 VALUES (NULL, NULL, 'c'); +INSERT INTO t1 VALUES (NULL, NULL, NULL); +SELECT LENGTH(a||b||c), a||b||c FROM t1 ORDER BY a,b,c; +LENGTH(a||b||c) a||b||c +NULL NULL +0 +1 c +0 +0 +1 c +1 b +1 b +2 bc +0 +0 +1 c +0 +0 +1 c +1 b +1 b +2 bc +1 a +1 a +2 ac +1 a +1 a +2 ac +2 ab +2 ab +3 abc +SELECT LENGTH(CONCAT(a||b||c)), CONCAT(a||b||c) FROM t1 ORDER BY a,b,c; +LENGTH(CONCAT(a||b||c)) CONCAT(a||b||c) +NULL NULL +0 +1 c +0 +0 +1 c +1 b +1 b +2 bc +0 +0 +1 c +0 +0 +1 c +1 b +1 b +2 bc +1 a +1 a +2 ac +1 a +1 a +2 ac +2 ab +2 ab +3 abc +DROP TABLE t1; +# +# MDEV-12478 CONCAT function inside view casts values incorrectly with Oracle sql_mode +# +SET sql_mode=ORACLE; +CREATE VIEW v1 AS SELECT 'foo'||NULL||'bar' AS test; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select concat_operator_oracle(concat_operator_oracle('foo',NULL),'bar') AS "test" latin1 latin1_swedish_ci +SELECT * FROM v1; +test +foobar +SET sql_mode=DEFAULT; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select concat_operator_oracle(concat_operator_oracle('foo',NULL),'bar') AS `test` latin1 latin1_swedish_ci +SELECT * FROM v1; +test +foobar +DROP VIEW v1; +SET sql_mode=DEFAULT; +CREATE VIEW v1 AS SELECT CONCAT('foo',NULL,'bar') AS test; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select concat('foo',NULL,'bar') AS `test` latin1 latin1_swedish_ci +SELECT * FROM v1; +test +NULL +SET sql_mode=ORACLE; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select concat('foo',NULL,'bar') AS "test" latin1 latin1_swedish_ci +SELECT * FROM v1; +test +NULL +DROP VIEW v1; +SET sql_mode=DEFAULT; +CREATE VIEW v1 AS SELECT '0'||'1' AS test; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select '0' or '1' AS `test` latin1 latin1_swedish_ci +SELECT * FROM v1; +test +1 +SET sql_mode=ORACLE; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select '0' or '1' AS "test" latin1 latin1_swedish_ci +SELECT * FROM v1; +test +1 +DROP VIEW v1; +# +# MDEV-16186 Concatenation operator || returns wrong results in sql_mode=ORACLE +# +SELECT -1<<1||1 AS a FROM DUAL; +a +18446744073709549568 +SELECT -1||0<<1 AS a FROM DUAL; +a +18446744073709551596 +EXPLAIN EXTENDED SELECT -1<<1||1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select -1 << concat_operator_oracle(1,1) AS "a" +EXPLAIN EXTENDED SELECT -1||0<<1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(-1,0) << 1 AS "a" +SELECT -1+1||1 AS a FROM DUAL; +a +01 +SELECT -1||0+1 AS a FROM DUAL; +a +-9 +EXPLAIN EXTENDED SELECT -1+1||1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(-1 + 1,1) AS "a" +EXPLAIN EXTENDED SELECT -1||0+1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(-1,0) + 1 AS "a" +SELECT 1*1||-1 AS a FROM DUAL; +a +1-1 +SELECT 1||1*-1 AS a FROM DUAL; +a +1-1 +EXPLAIN EXTENDED SELECT 1*1||-1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(1 * 1,-1) AS "a" +EXPLAIN EXTENDED SELECT 1||1*-1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(1,1 * -1) AS "a" +SELECT -1^1||1 AS a FROM DUAL; +a +184467440737095516141 +SELECT -1||0^1 AS a FROM DUAL; +a +-11 +EXPLAIN EXTENDED SELECT -1^1||1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(-1 ^ 1,1) AS "a" +EXPLAIN EXTENDED SELECT -1||0^1 AS a FROM DUAL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select concat_operator_oracle(-1,0 ^ 1) AS "a" +# +# MDEV-17359 Concatenation operator || in like expression failed in sql_mode=ORACLE +# +SELECT 'abc' LIKE 'a'||'%'; +'abc' LIKE 'a'||'%' +1 +EXPLAIN EXTENDED SELECT 'abc' LIKE 'a'||'%'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select 'abc' like concat_operator_oracle('a','%') AS "'abc' LIKE 'a'||'%'" +SELECT 'x' FROM DUAL WHERE 11 LIKE 1||1; +x +x +SELECT 'x' FROM DUAL WHERE 1||1 LIKE 11; +x +x +SELECT 'x' FROM DUAL WHERE 1||1 LIKE 1||1; +x +x +CREATE TABLE t1 (c1 VARCHAR(10),c2 VARCHAR(10), ord INTEGER); +INSERT INTO t1 VALUES ('a', 'ab' ,1); +INSERT INTO t1 VALUES ('ab', 'ab', 2); +INSERT INTO t1 VALUES ('abc', 'ab', 3); +SELECT c1 FROM t1 WHERE c1 LIKE '%'||'b' ORDER BY ord; +c1 +ab +EXPLAIN EXTENDED SELECT c1 FROM t1 WHERE c1 LIKE '%'||'b' ORDER BY ord; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using filesort +Warnings: +Note 1003 select "test"."t1"."c1" AS "c1" from "test"."t1" where "test"."t1"."c1" like (concat_operator_oracle('%','b')) order by "test"."t1"."ord" +SELECT c1 FROM t1 WHERE c1 LIKE c2||'%'||'c' ORDER BY ord; +c1 +abc +EXPLAIN EXTENDED SELECT c1 FROM t1 WHERE c1 LIKE c2||'%'||'c' ORDER BY ord; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using filesort +Warnings: +Note 1003 select "test"."t1"."c1" AS "c1" from "test"."t1" where "test"."t1"."c1" like concat_operator_oracle(concat_operator_oracle("test"."t1"."c2",'%'),'c') order by "test"."t1"."ord" +SELECT 'x' FROM t1 WHERE c1||c2 LIKE 'aa%'; +x +x +EXPLAIN EXTENDED SELECT 'x' FROM t1 WHERE c1||c2 LIKE 'aa%'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select 'x' AS "x" from "test"."t1" where concat_operator_oracle("test"."t1"."c1","test"."t1"."c2") like 'aa%' +SELECT 'x' FROM t1 WHERE c1||c2 LIKE c2||c1; +x +x +EXPLAIN EXTENDED SELECT 'x' FROM t1 WHERE c1||c2 LIKE c2||c1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select 'x' AS "x" from "test"."t1" where concat_operator_oracle("test"."t1"."c1","test"."t1"."c2") like concat_operator_oracle("test"."t1"."c2","test"."t1"."c1") +CREATE VIEW v1 AS SELECT c1, c2, c1 LIKE c2||'_' FROM t1 ORDER BY ord; +SELECT * FROM v1; +c1 c2 c1 LIKE c2||'_' +a ab 0 +ab ab 0 +abc ab 1 +EXPLAIN EXTENDED SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 select "test"."t1"."c1" AS "c1","test"."t1"."c2" AS "c2","test"."t1"."c1" like concat_operator_oracle("test"."t1"."c2",'_') AS "c1 LIKE c2||'_'" from "test"."t1" order by "test"."t1"."ord" +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/func_decode.result b/mysql-test/suite/compat/oracle/r/func_decode.result new file mode 100644 index 00000000..2809e971 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_decode.result @@ -0,0 +1,177 @@ +SET sql_mode=ORACLE; +SELECT DECODE(10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' +SELECT DECODE(10,10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' +SELECT DECODE(10,10,'x10'); +DECODE(10,10,'x10') +x10 +SELECT DECODE(11,10,'x10'); +DECODE(11,10,'x10') +NULL +SELECT DECODE(10,10,'x10','def'); +DECODE(10,10,'x10','def') +x10 +SELECT DECODE(11,10,'x10','def'); +DECODE(11,10,'x10','def') +def +SELECT DECODE(10,10,'x10',11,'x11','def'); +DECODE(10,10,'x10',11,'x11','def') +x10 +SELECT DECODE(11,10,'x10',11,'x11','def'); +DECODE(11,10,'x10',11,'x11','def') +x11 +SELECT DECODE(12,10,'x10',11,'x11','def'); +DECODE(12,10,'x10',11,'x11','def') +def +EXPLAIN EXTENDED SELECT DECODE(12,10,'x10',11,'x11','def'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select decode_oracle(12,10,'x10',11,'x11','def') AS "DECODE(12,10,'x10',11,'x11','def')" +CREATE TABLE decode (decode int); +DROP TABLE decode; +# +# MDEV-13863 sql_mode=ORACLE: DECODE does not treat two NULLs as equivalent +# +SELECT DECODE(10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' +SELECT DECODE(10,10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE' +SELECT DECODE_ORACLE(10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE_ORACLE' +SELECT DECODE_ORACLE(10,10); +ERROR 42000: Incorrect parameter count in the call to native function 'DECODE_ORACLE' +EXPLAIN EXTENDED SELECT DECODE(12,10,'x10',11,'x11'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select decode_oracle(12,10,'x10',11,'x11') AS "DECODE(12,10,'x10',11,'x11')" +EXPLAIN EXTENDED SELECT DECODE(12,10,'x10',11,'x11','def'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select decode_oracle(12,10,'x10',11,'x11','def') AS "DECODE(12,10,'x10',11,'x11','def')" +EXPLAIN EXTENDED SELECT DECODE_ORACLE(12,10,'x10',11,'x11'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select decode_oracle(12,10,'x10',11,'x11') AS "DECODE_ORACLE(12,10,'x10',11,'x11')" +EXPLAIN EXTENDED SELECT DECODE_ORACLE(12,10,'x10',11,'x11','def'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select decode_oracle(12,10,'x10',11,'x11','def') AS "DECODE_ORACLE(12,10,'x10',11,'x11','def')" +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS +SELECT +DECODE(a,1,'x1',NULL,'xNULL') AS d1, +DECODE(a,1,'x1',NULL,'xNULL','xELSE') AS d2, +DECODE_ORACLE(a,1,'x1',NULL,'xNULL') AS d3, +DECODE_ORACLE(a,1,'x1',NULL,'xNULL','xELSE') AS d4 +FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select decode_oracle("t1"."a",1,'x1',NULL,'xNULL') AS "d1",decode_oracle("t1"."a",1,'x1',NULL,'xNULL','xELSE') AS "d2",decode_oracle("t1"."a",1,'x1',NULL,'xNULL') AS "d3",decode_oracle("t1"."a",1,'x1',NULL,'xNULL','xELSE') AS "d4" from "t1" latin1 latin1_swedish_ci +DROP VIEW v1; +DROP TABLE t1; +SELECT DECODE(TIME'10:20:31','10:20:31','then1','10:20:32','then2','def'); +DECODE(TIME'10:20:31','10:20:31','then1','10:20:32','then2','def') +then1 +SELECT DECODE(TIME'10:20:32','10:20:31','then1','10:20:32','then2','def'); +DECODE(TIME'10:20:32','10:20:31','then1','10:20:32','then2','def') +then2 +SELECT DECODE(TIME'10:20:33','10:20:31','then1',NULL,'then2NULL','10:20:33','then3','def'); +DECODE(TIME'10:20:33','10:20:31','then1',NULL,'then2NULL','10:20:33','then3','def') +then3 +SELECT DECODE(NULL,TIME'10:20:31','then1',NULL,'then2NULL','10:20:33','then3','def'); +DECODE(NULL,TIME'10:20:31','then1',NULL,'then2NULL','10:20:33','then3','def') +then2NULL +SELECT DECODE(TIMESTAMP'2001-01-01 10:20:31','2001-01-01 10:20:31','then1','2001-01-01 10:20:32','then2','def'); +DECODE(TIMESTAMP'2001-01-01 10:20:31','2001-01-01 10:20:31','then1','2001-01-01 10:20:32','then2','def') +then1 +SELECT DECODE(TIMESTAMP'2001-01-01 10:20:32','2001-01-01 10:20:31','then1','2001-01-01 10:20:32','then2','def'); +DECODE(TIMESTAMP'2001-01-01 10:20:32','2001-01-01 10:20:31','then1','2001-01-01 10:20:32','then2','def') +then2 +SELECT DECODE(TIMESTAMP'2001-01-01 10:20:33','2001-01-01 10:20:31','then1',NULL,'then2NULL','2001-01-01 10:20:33','then3','def'); +DECODE(TIMESTAMP'2001-01-01 10:20:33','2001-01-01 10:20:31','then1',NULL,'then2NULL','2001-01-01 10:20:33','then3','def') +then3 +SELECT DECODE(NULL,TIMESTAMP'2001-01-01 10:20:31','then1',NULL,'then2NULL','2001-01-01 10:20:33','then3','def'); +DECODE(NULL,TIMESTAMP'2001-01-01 10:20:31','then1',NULL,'then2NULL','2001-01-01 10:20:33','then3','def') +then2NULL +SELECT DECODE('w1','w1','then1','w2','then2','def'); +DECODE('w1','w1','then1','w2','then2','def') +then1 +SELECT DECODE('w2','w1','then1','w2','then2','def'); +DECODE('w2','w1','then1','w2','then2','def') +then2 +SELECT DECODE('w3','w1','then1',NULL,'then2NULL','w3','then3','def'); +DECODE('w3','w1','then1',NULL,'then2NULL','w3','then3','def') +then3 +SELECT DECODE(NULL,'w1','then1',NULL,'then2NULL','w3','then3','def'); +DECODE(NULL,'w1','then1',NULL,'then2NULL','w3','then3','def') +then2NULL +SELECT DECODE(1,1,'then1',2,'then2','def'); +DECODE(1,1,'then1',2,'then2','def') +then1 +SELECT DECODE(2,1,'then1',2,'then2','def'); +DECODE(2,1,'then1',2,'then2','def') +then2 +SELECT DECODE(3,1,'then1',NULL,'then2NULL',3,'then3','def'); +DECODE(3,1,'then1',NULL,'then2NULL',3,'then3','def') +then3 +SELECT DECODE(NULL,1,'then1',NULL,'then2NULL',3,'then3','def'); +DECODE(NULL,1,'then1',NULL,'then2NULL',3,'then3','def') +then2NULL +SELECT DECODE(CAST(NULL AS SIGNED),1,'then1',NULL,'then2NULL',3,'then3','def'); +DECODE(CAST(NULL AS SIGNED),1,'then1',NULL,'then2NULL',3,'then3','def') +then2NULL +SELECT DECODE(1.0,1.0,'then1',2.0,'then2','def'); +DECODE(1.0,1.0,'then1',2.0,'then2','def') +then1 +SELECT DECODE(2.0,1.0,'then1',2.0,'then2','def'); +DECODE(2.0,1.0,'then1',2.0,'then2','def') +then2 +SELECT DECODE(3.0,1.0,'then1',NULL,'then2NULL',3.0,'then3','def'); +DECODE(3.0,1.0,'then1',NULL,'then2NULL',3.0,'then3','def') +then3 +SELECT DECODE(NULL,1.0,'then1',NULL,'then2NULL',3.0,'then3','def'); +DECODE(NULL,1.0,'then1',NULL,'then2NULL',3.0,'then3','def') +then2NULL +SELECT DECODE(CAST(NULL AS DECIMAL),1.0,'then1',NULL,'then2NULL',3.0,'then3','def'); +DECODE(CAST(NULL AS DECIMAL),1.0,'then1',NULL,'then2NULL',3.0,'then3','def') +then2NULL +SELECT DECODE(1e0,1e0,'then1',2e0,'then2','def'); +DECODE(1e0,1e0,'then1',2e0,'then2','def') +then1 +SELECT DECODE(2e0,1e0,'then1',2e0,'then2','def'); +DECODE(2e0,1e0,'then1',2e0,'then2','def') +then2 +SELECT DECODE(3e0,1e0,'then1',NULL,'then2NULL',3e0,'then3','def'); +DECODE(3e0,1e0,'then1',NULL,'then2NULL',3e0,'then3','def') +then3 +SELECT DECODE(NULL,1e0,'then1',NULL,'then2NULL',3e0,'then3','def'); +DECODE(NULL,1e0,'then1',NULL,'then2NULL',3e0,'then3','def') +then2NULL +SELECT DECODE(CAST(NULL AS DOUBLE),1e0,'then1',NULL,'then2NULL',3e0,'then3','def'); +DECODE(CAST(NULL AS DOUBLE),1e0,'then1',NULL,'then2NULL',3e0,'then3','def') +then2NULL +SELECT DECODE(NULL,NULL,1,2) FROM DUAL; +DECODE(NULL,NULL,1,2) +1 +SELECT DECODE(NULL,10,10,NULL,1,2) FROM DUAL; +DECODE(NULL,10,10,NULL,1,2) +1 +SELECT DECODE_ORACLE(NULL,NULL,1,2) FROM DUAL; +DECODE_ORACLE(NULL,NULL,1,2) +1 +SELECT DECODE_ORACLE(NULL,10,10,NULL,1,2) FROM DUAL; +DECODE_ORACLE(NULL,10,10,NULL,1,2) +1 +CREATE OR REPLACE TABLE t1 (a VARCHAR(10) DEFAULT NULL); +INSERT INTO t1 VALUES (NULL),(1); +SELECT a, DECODE(a,NULL,1,2) FROM t1; +a DECODE(a,NULL,1,2) +NULL 1 +1 2 +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/func_length.result b/mysql-test/suite/compat/oracle/r/func_length.result new file mode 100644 index 00000000..e260f5ad --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_length.result @@ -0,0 +1,21 @@ +SET sql_mode=ORACLE; +# +# MDEV-12783 sql_mode=ORACLE: Functions LENGTH() and LENGTHB() +# +SELECT LENGTH(null), LENGTH('a'), LENGTH(123); +LENGTH(null) LENGTH('a') LENGTH(123) +NULL 1 3 +SELECT LENGTHB(null), LENGTHB('a'), LENGTHB(123); +LENGTHB(null) LENGTHB('a') LENGTHB(123) +NULL 1 3 +SELECT LENGTH(_utf8 0xC39F), LENGTH(CHAR(14844588 USING utf8)); +LENGTH(_utf8 0xC39F) LENGTH(CHAR(14844588 USING utf8)) +1 1 +SELECT LENGTHB(_utf8 0xC39F), LENGTHB(CHAR(14844588 USING utf8)); +LENGTHB(_utf8 0xC39F) LENGTHB(CHAR(14844588 USING utf8)) +2 3 +EXPLAIN EXTENDED SELECT LENGTH('a'), LENGTHB('a'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select char_length('a') AS "LENGTH('a')",octet_length('a') AS "LENGTHB('a')" diff --git a/mysql-test/suite/compat/oracle/r/func_misc.result b/mysql-test/suite/compat/oracle/r/func_misc.result new file mode 100644 index 00000000..28f27873 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_misc.result @@ -0,0 +1,319 @@ +SET sql_mode=ORACLE; +# +# MDEV-10578 sql_mode=ORACLE: SP control functions SQLCODE, SQLERRM +# +# +# Using SQLCODE and SQLERRM outside of an SP +# +SELECT SQLCODE; +ERROR 42S22: Unknown column 'SQLCODE' in 'field list' +SELECT SQLERRM; +ERROR 42S22: Unknown column 'SQLERRM' in 'field list' +CREATE TABLE t1 (SQLCODE INT, SQLERRM VARCHAR(10)); +INSERT INTO t1 VALUES (10, 'test'); +SELECT SQLCODE, SQLERRM FROM t1; +SQLCODE SQLERRM +10 test +DROP TABLE t1; +# +# Normal SQLCODE and SQLERRM usage +# +CREATE PROCEDURE p1(stmt VARCHAR) +AS +BEGIN +EXECUTE IMMEDIATE stmt; +SELECT 'Error1: ' || SQLCODE || ' ' || SQLERRM; +EXCEPTION +WHEN OTHERS THEN +SELECT 'Error2: ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1('SELECT 1'); +1 +1 +'Error1: ' || SQLCODE || ' ' || SQLERRM +Error1: 0 normal, successful completion +CALL p1('xxx'); +'Error2: ' || SQLCODE || ' ' || SQLERRM +Error2: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 +CALL p1('SELECT 1'); +1 +1 +'Error1: ' || SQLCODE || ' ' || SQLERRM +Error1: 0 normal, successful completion +DROP PROCEDURE p1; +# +# SQLCODE and SQLERRM hidden by local variables +# +CREATE PROCEDURE p1() +AS +sqlcode INT:= 10; +sqlerrm VARCHAR(64) := 'test'; +BEGIN +SELECT 'Error: ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1; +'Error: ' || SQLCODE || ' ' || SQLERRM +Error: 10 test +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +sqlcode INT; +sqlerrm VARCHAR(64); +BEGIN +SQLCODE:= 10; +sqlerrm:= 'test'; +SELECT 'Error: ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1; +'Error: ' || SQLCODE || ' ' || SQLERRM +Error: 10 test +DROP PROCEDURE p1; +# +# SQLCODE and SQLERRM hidden by parameters +# +CREATE PROCEDURE p1(sqlcode INT, sqlerrm VARCHAR) +AS +BEGIN +SELECT 'Error: ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1(10, 'test'); +'Error: ' || SQLCODE || ' ' || SQLERRM +Error: 10 test +DROP PROCEDURE p1; +# +# SQLCODE and SQLERRM in CREATE..SELECT +# +CREATE PROCEDURE p1 +AS +BEGIN +CREATE TABLE t1 AS SELECT SQLCODE, SQLERRM; +END; +$$ +CALL p1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "SQLCODE" int(11) NOT NULL, + "SQLERRM" varchar(512) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# SQLCODE and SQLERRM in EXPLAIN EXTENDED SELECT +# +CREATE PROCEDURE p1 +AS +BEGIN +EXPLAIN EXTENDED SELECT SQLCode, SQLErrm; +END; +$$ +CALL p1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select SQLCODE AS "SQLCode",SQLERRM AS "SQLErrm" +DROP PROCEDURE p1; +# +# Warning-alike errors in stored functions +# +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1 RETURN VARCHAR +AS +a INT; +BEGIN +SELECT a INTO a FROM t1; +RETURN 'No exception ' || SQLCODE || ' ' || SQLERRM; +EXCEPTION +WHEN NO_DATA_FOUND THEN +RETURN 'Exception ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f1() FROM DUAL; +f1() +Exception 1329 No data - zero rows fetched, selected, or processed +DROP FUNCTION f1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1 RETURN VARCHAR +AS +a INT; +BEGIN +SELECT a INTO a FROM t1; +RETURN 'No exception ' || SQLCODE || ' ' || SQLERRM; +EXCEPTION +WHEN OTHERS THEN +RETURN 'Exception ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f1() FROM DUAL; +f1() +Exception 1329 No data - zero rows fetched, selected, or processed +DROP FUNCTION f1; +DROP TABLE t1; +# +# Warning-alike errors in stored procedures +# +CREATE TABLE t1 (a INT); +CREATE PROCEDURE p1(res OUT VARCHAR) +AS +a INT; +BEGIN +SELECT a INTO a FROM t1; +res:= 'No exception ' || SQLCODE || ' ' || SQLERRM; +EXCEPTION +WHEN NO_DATA_FOUND THEN +res:= 'Exception ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1(@a); +SELECT @a; +@a +Exception 1329 No data - zero rows fetched, selected, or processed +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +CREATE PROCEDURE p1(res OUT VARCHAR) +AS +a INT; +BEGIN +SELECT a INTO a FROM t1; +res:= 'No exception ' || SQLCODE || ' ' || SQLERRM; +EXCEPTION +WHEN OTHERS THEN +res:= 'Exception ' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CALL p1(@a); +SELECT @a; +@a +Exception 1329 No data - zero rows fetched, selected, or processed +DROP PROCEDURE p1; +DROP TABLE t1; +# +# SQLCODE and SQLERRM are cleared on RETURN +# +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1 RETURN VARCHAR +AS +a INT:=10; +BEGIN +SELECT a INTO a FROM t1; +RETURN 'Value=' || a; +EXCEPTION +WHEN NO_DATA_FOUND THEN RETURN 'Exception|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CREATE FUNCTION f2 RETURN VARCHAR +AS +a VARCHAR(128); +BEGIN +RETURN f1() || '|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f1() FROM DUAL; +f1() +Exception|1329 No data - zero rows fetched, selected, or processed +SELECT f2() FROM DUAL; +f2() +Exception|1329 No data - zero rows fetched, selected, or processed|0 normal, successful completion +DROP TABLE t1; +DROP FUNCTION f2; +DROP FUNCTION f1; +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1 RETURN VARCHAR +AS +a INT:=10; +BEGIN +SELECT a INTO a FROM t1; +RETURN 'Value=' || a; +EXCEPTION +WHEN OTHERS THEN RETURN 'Exception|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CREATE FUNCTION f2 RETURN VARCHAR +AS +a VARCHAR(128); +BEGIN +RETURN f1() || '|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f1() FROM DUAL; +f1() +Exception|1329 No data - zero rows fetched, selected, or processed +SELECT f2() FROM DUAL; +f2() +Exception|1329 No data - zero rows fetched, selected, or processed|0 normal, successful completion +DROP TABLE t1; +DROP FUNCTION f2; +DROP FUNCTION f1; +# +# SQLCODE and SQLERRM are cleared on a return from a PROCEDURE +# +CREATE TABLE t1 (a INT); +CREATE PROCEDURE p1(res OUT VARCHAR) +AS +a INT:=10; +BEGIN +SELECT a INTO a FROM t1; +res:='Value=' || a; +EXCEPTION +WHEN NO_DATA_FOUND THEN res:='Exception|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CREATE FUNCTION f2 RETURN VARCHAR +AS +res VARCHAR(128); +BEGIN +CALL p1(res); +RETURN res || '|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f2() FROM DUAL; +f2() +Exception|1329 No data - zero rows fetched, selected, or processed|0 normal, successful completion +DROP FUNCTION f2; +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +CREATE PROCEDURE p1(res OUT VARCHAR) +AS +a INT:=10; +BEGIN +SELECT a INTO a FROM t1; +res:='Value=' || a; +EXCEPTION +WHEN OTHERS THEN res:='Exception|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +CREATE FUNCTION f2 RETURN VARCHAR +AS +res VARCHAR(128); +BEGIN +CALL p1(res); +RETURN res || '|' || SQLCODE || ' ' || SQLERRM; +END; +$$ +SELECT f2() FROM DUAL; +f2() +Exception|1329 No data - zero rows fetched, selected, or processed|0 normal, successful completion +DROP FUNCTION f2; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# End of MDEV-10578 sql_mode=ORACLE: SP control functions SQLCODE, SQLERRM +# +# +# MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions +# +BEGIN +SELECT SQLCODE; +END +$$ +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def SQLCODE 3 11 1 N 32897 0 63 +SQLCODE +0 diff --git a/mysql-test/suite/compat/oracle/r/func_pad.result b/mysql-test/suite/compat/oracle/r/func_pad.result new file mode 100644 index 00000000..ca7d52cd --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_pad.result @@ -0,0 +1,71 @@ +SET sql_mode=ORACLE; +# +# MDEV-15739 - sql_mode=ORACLE: Make LPAD and RPAD return NULL instead of empty string +# +SELECT RPAD('a',0), RPAD('abc',1), RPAD('abc',2) ; +RPAD('a',0) RPAD('abc',1) RPAD('abc',2) +NULL a ab +SELECT RPAD('a',0,'.'), RPAD('abc',1,'.'), RPAD('abc',2,'.') ; +RPAD('a',0,'.') RPAD('abc',1,'.') RPAD('abc',2,'.') +NULL a ab +SELECT LPAD('a',0), LPAD('abc',1), LPAD('abc',2) ; +LPAD('a',0) LPAD('abc',1) LPAD('abc',2) +NULL a ab +SELECT LPAD('a',0,'.'), LPAD('abc',1,'.'), LPAD('abc',2,'.') ; +LPAD('a',0,'.') LPAD('abc',1,'.') LPAD('abc',2,'.') +NULL a ab +CREATE TABLE t1 (c1 VARCHAR(10),c2 INTEGER, c3 VARCHAR(10), ord INTEGER); +INSERT INTO t1 VALUES ('a',1,null,1); +INSERT INTO t1 VALUES ('a',null,'.',2); +INSERT INTO t1 VALUES (null,1,'.',3); +INSERT INTO t1 VALUES ('a',-1,'.',4); +INSERT INTO t1 VALUES ('a',0,'.',5); +INSERT INTO t1 VALUES ('a',1,'.',6); +INSERT INTO t1 VALUES ('a',2,'.',7); +SELECT LPAD(c1,c2,c3), LPAD(c1,c2) FROM t1 ORDER BY ord; +LPAD(c1,c2,c3) LPAD(c1,c2) +NULL a +NULL NULL +NULL NULL +NULL NULL +NULL NULL +a a +.a a +SELECT RPAD(c1,c2,c3), RPAD(c1,c2) FROM t1 ORDER BY ord; +RPAD(c1,c2,c3) RPAD(c1,c2) +NULL a +NULL NULL +NULL NULL +NULL NULL +NULL NULL +a a +a. a +EXPLAIN EXTENDED SELECT RPAD('a',0,'.'), LPAD('a',0,'.'), LPAD(c1,c2,c3), LPAD(c1,c2), RPAD(c1,c2,c3), RPAD(c1,c2) FROM t1 ORDER BY ord; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using filesort +Warnings: +Note 1003 select rpad_oracle('a',0,'.') AS "RPAD('a',0,'.')",lpad_oracle('a',0,'.') AS "LPAD('a',0,'.')",lpad_oracle("test"."t1"."c1","test"."t1"."c2","test"."t1"."c3") AS "LPAD(c1,c2,c3)",lpad_oracle("test"."t1"."c1","test"."t1"."c2") AS "LPAD(c1,c2)",rpad_oracle("test"."t1"."c1","test"."t1"."c2","test"."t1"."c3") AS "RPAD(c1,c2,c3)",rpad_oracle("test"."t1"."c1","test"."t1"."c2") AS "RPAD(c1,c2)" from "test"."t1" order by "test"."t1"."ord" +CREATE VIEW v1 AS SELECT RPAD('a',0,'.') AS "C1", LPAD('a',0,'.') AS "C2", LPAD(c1,c2,c3) AS "C3", LPAD(c1,c2) AS "C4", RPAD(c1,c2,c3) AS "C5", RPAD(c1,c2) AS "C6" FROM t1 ORDER BY ord; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select rpad_oracle('a',0,'.') AS "C1",lpad_oracle('a',0,'.') AS "C2",lpad_oracle("t1"."c1","t1"."c2","t1"."c3") AS "C3",lpad_oracle("t1"."c1","t1"."c2") AS "C4",rpad_oracle("t1"."c1","t1"."c2","t1"."c3") AS "C5",rpad_oracle("t1"."c1","t1"."c2") AS "C6" from "t1" order by "t1"."ord" latin1 latin1_swedish_ci +SELECT * FROM v1; +C1 C2 C3 C4 C5 C6 +NULL NULL NULL a NULL a +NULL NULL NULL NULL NULL NULL +NULL NULL NULL NULL NULL NULL +NULL NULL NULL NULL NULL NULL +NULL NULL NULL NULL NULL NULL +NULL NULL a a a a +NULL NULL .a a a. a +SELECT c1||'-'||c2||'-'||c3||'-'||c4||'-'||c5||'-'||c6 FROM v1; +c1||'-'||c2||'-'||c3||'-'||c4||'-'||c5||'-'||c6 +---a--a +----- +----- +----- +----- +--a-a-a-a +--.a- a-a.-a +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/func_replace.result b/mysql-test/suite/compat/oracle/r/func_replace.result new file mode 100644 index 00000000..02516096 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_replace.result @@ -0,0 +1,32 @@ +SET sql_mode=ORACLE; +# +# MDEV-13003 - Oracle compatibility : Replace function +# +SELECT REPLACE(null,'a','b') ; +REPLACE(null,'a','b') +NULL +SELECT REPLACE('ab',null,'b') ; +REPLACE('ab',null,'b') +ab +SELECT REPLACE('ab','a',null) ; +REPLACE('ab','a',null) +b +SELECT REPLACE('ab',null,null) ; +REPLACE('ab',null,null) +ab +SELECT REPLACE('aaa','a',null) ; +REPLACE('aaa','a',null) +NULL +EXPLAIN EXTENDED SELECT REPLACE('ab','a',null) ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select replace_oracle('ab','a',NULL) AS "REPLACE('ab','a',null)" +CREATE VIEW v1 AS SELECT REPLACE('ab','a',null) ; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select replace_oracle('ab','a',NULL) AS "REPLACE('ab','a',null)" latin1 latin1_swedish_ci +SELECT * FROM v1; +REPLACE('ab','a',null) +b +DROP VIEW v1; diff --git a/mysql-test/suite/compat/oracle/r/func_substr.result b/mysql-test/suite/compat/oracle/r/func_substr.result new file mode 100644 index 00000000..5d9fdd5f --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_substr.result @@ -0,0 +1,87 @@ +# +# MDEV-14012 - sql_mode=Oracle: substr(): treat position 0 as position 1 +# MDEV-10574 - sql_mode=Oracle: return null instead of empty string +# +SET sql_mode=ORACLE; +SELECT SUBSTR('abc',2,1),SUBSTR('abc',1,1), SUBSTR('abc',0,1) FROM dual; +SUBSTR('abc',2,1) SUBSTR('abc',1,1) SUBSTR('abc',0,1) +b a a +SELECT SUBSTR('abc',2),SUBSTR('abc',1), SUBSTR('abc',0) FROM dual; +SUBSTR('abc',2) SUBSTR('abc',1) SUBSTR('abc',0) +bc abc abc +SELECT SUBSTR(null,2,1),SUBSTR(null,1), SUBSTR(null,0) FROM dual; +SUBSTR(null,2,1) SUBSTR(null,1) SUBSTR(null,0) +NULL NULL NULL +SELECT SUBSTR('abc',-2),SUBSTR('abc',-1), SUBSTR('abc',-0) FROM dual; +SUBSTR('abc',-2) SUBSTR('abc',-1) SUBSTR('abc',-0) +bc c abc +SELECT SUBSTR('abc',-2,1),SUBSTR('abc',-1,1), SUBSTR('abc',-0,1) FROM dual; +SUBSTR('abc',-2,1) SUBSTR('abc',-1,1) SUBSTR('abc',-0,1) +b c a +SELECT SUBSTR('abc',null) FROM dual; +SUBSTR('abc',null) +NULL +SELECT SUBSTR('abc',2,null),SUBSTR('abc',1,null), SUBSTR('abc',0,null) FROM dual; +SUBSTR('abc',2,null) SUBSTR('abc',1,null) SUBSTR('abc',0,null) +NULL NULL NULL +SELECT SUBSTR('abc',2,0),SUBSTR('abc',1,0), SUBSTR('abc',0,0) FROM dual; +SUBSTR('abc',2,0) SUBSTR('abc',1,0) SUBSTR('abc',0,0) +NULL NULL NULL +SELECT SUBSTR('abc',2,-1),SUBSTR('abc',1,-1), SUBSTR('abc',0,-1) FROM dual; +SUBSTR('abc',2,-1) SUBSTR('abc',1,-1) SUBSTR('abc',0,-1) +NULL NULL NULL +SELECT SUBSTR(SPACE(0),1) FROM DUAL; +SUBSTR(SPACE(0),1) +NULL +CREATE TABLE t1 (c1 VARCHAR(10),start INTEGER, length INTEGER); +INSERT INTO t1 VALUES ('abc', 1, 1); +INSERT INTO t1 VALUES ('abc', 0, 1); +INSERT INTO t1 VALUES (null, 1, 1); +INSERT INTO t1 VALUES (null, 0, 1); +INSERT INTO t1 VALUES ('abc', 1, 0); +INSERT INTO t1 VALUES ('abc', 0, 0); +INSERT INTO t1 VALUES (null, 1, 0); +INSERT INTO t1 VALUES (null, 0, 0); +INSERT INTO t1 VALUES ('abc', 1, -1); +INSERT INTO t1 VALUES ('abc', 0, -1); +INSERT INTO t1 VALUES (null, 1, -1); +INSERT INTO t1 VALUES (null, 0, -1); +INSERT INTO t1 VALUES (SPACE(0), 0, 1); +SELECT SUBSTR(c1,start,length) FROM t1; +SUBSTR(c1,start,length) +a +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +DROP TABLE t1; +CREATE TABLE t1 (c1 VARCHAR(10) NOT NULL); +CREATE TABLE t2 AS SELECT SUBSTR(C1,1,1) AS C1 from t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE "t2" ( + "C1" varchar(1) DEFAULT NULL +) +DROP TABLE t2; +DROP TABLE t1; +EXPLAIN EXTENDED SELECT SUBSTR('abc',2,1) ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select substr_oracle('abc',2,1) AS "SUBSTR('abc',2,1)" +CREATE VIEW v1 AS SELECT SUBSTR('abc',2,1) ; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select substr_oracle('abc',2,1) AS "SUBSTR('abc',2,1)" latin1 latin1_swedish_ci +SELECT * FROM v1; +SUBSTR('abc',2,1) +b +DROP VIEW v1; diff --git a/mysql-test/suite/compat/oracle/r/func_time.result b/mysql-test/suite/compat/oracle/r/func_time.result new file mode 100644 index 00000000..06316340 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_time.result @@ -0,0 +1,31 @@ +SET sql_mode=ORACLE; +# +# Start of 10.3 tests +# +# +# MDEV-16152 Expressions with INTERVAL return bad results in some cases +# +SELECT TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1, +-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2; +c1 c2 +1991-01-01 10:20:30 1991-01-01 10:20:30 +SELECT TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1, +INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2, ++INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3; +c1 c2 c3 +2011-01-01 10:20:30 2011-01-01 10:20:30 2011-01-01 10:20:30 +EXPLAIN EXTENDED SELECT +TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1, +-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS "c1",TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS "c2" +EXPLAIN EXTENDED SELECT +TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1, +INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2, ++INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c1",TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c2",TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c3" diff --git a/mysql-test/suite/compat/oracle/r/func_to_char.result b/mysql-test/suite/compat/oracle/r/func_to_char.result new file mode 100644 index 00000000..1f95acec --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_to_char.result @@ -0,0 +1,448 @@ +set @save_sql_mode=@@sql_mode; +# +# test for datetime +# +CREATE TABLE t_to_char1(c0 int, c1 date, c2 time, c3 datetime); +INSERT INTO t_to_char1 VALUES (1, '1000-1-1', '00:00:00', '1000-1-1 00:00:00'); +INSERT INTO t_to_char1 VALUES (2, '9999-12-31', '23:59:59', '9999-12-31 23:59:59'); +INSERT INTO t_to_char1 VALUES (3, '2021-01-03', '08:30:00', '2021-01-03 08:30:00'); +INSERT INTO t_to_char1 VALUES (4, '2021-07-03', '18:30:00', '2021-07-03 18:30:00'); +CREATE TABLE t_to_char2(c1 timestamp); +INSERT INTO t_to_char2 VALUES ('1980-01-11 04:50:39'); +INSERT INTO t_to_char2 VALUES ('2000-11-11 12:50:00'); +INSERT INTO t_to_char2 VALUES ('2030-11-11 18:20:10'); +SELECT TO_CHAR(c1, 'YYYY-MM-DD') FROM t_to_char2; +TO_CHAR(c1, 'YYYY-MM-DD') +1980-01-11 +2000-11-11 +2030-11-11 +SELECT TO_CHAR(c1, 'HH24-MI-SS') FROM t_to_char2; +TO_CHAR(c1, 'HH24-MI-SS') +04-50-39 +12-50-00 +18-20-10 +# +# test YYYY/YY/MM/DD/HH/HH24/MI/SS +# +SELECT TO_CHAR(c1, 'YYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'YY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000-01-01 12:00:00 00-01-01 00:00:00 +9999-12-31 11:59:59 99-12-31 23:59:59 +2021-01-03 08:30:00 21-01-03 08:30:00 +2021-07-03 06:30:00 21-07-03 18:30:00 +SELECT TO_CHAR(c1, 'yyyy-mm-dd') AS C1, TO_CHAR(c2, 'hh:mi:ss') AS C2, TO_CHAR(c3, 'yy-mm-dd hh24:mi:ss') AS C3 FROM t_to_char1; +C1 C2 C3 +1000-01-01 12:00:00 00-01-01 00:00:00 +9999-12-31 11:59:59 99-12-31 23:59:59 +2021-01-03 08:30:00 21-01-03 08:30:00 +2021-07-03 06:30:00 21-07-03 18:30:00 +# +# test YYY/Y/MON/DD/DY/HH/HH12/MI/SS +# +SELECT TO_CHAR(c1, 'YYY-MON-DD') AS C1, TO_CHAR(c2, 'HH12:MI:SS') AS C2, TO_CHAR(c3, 'Y-MONTH-DY HH:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +000-Jan-01 12:00:00 0-January -Wed 12:00:00 +999-Dec-31 11:59:59 9-December -Fri 11:59:59 +021-Jan-03 08:30:00 1-January -Sun 08:30:00 +021-Jul-03 06:30:00 1-July -Sat 06:30:00 +SELECT TO_CHAR(c1, 'yyy-Mon-Dd') AS C1, TO_CHAR(c2, 'Hh12:mi:Ss') AS C2, TO_CHAR(c3, 'y-Month-Dy Hh:Mi:Ss') AS C3 FROM t_to_char1; +C1 C2 C3 +000-Jan-01 12:00:00 0-January -Wed 12:00:00 +999-Dec-31 11:59:59 9-December -Fri 11:59:59 +021-Jan-03 08:30:00 1-January -Sun 08:30:00 +021-Jul-03 06:30:00 1-July -Sat 06:30:00 +# +# test RRRR/RR/DAY +# +SELECT TO_CHAR(c1, 'RRRR-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'RRRR-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000-01-01 12:00:00 1000-01-01 00:00:00 +9999-12-31 11:59:59 9999-12-31 23:59:59 +2021-01-03 08:30:00 2021-01-03 08:30:00 +2021-07-03 06:30:00 2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'RR-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'YY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +00-01-01 12:00:00 00-01-01 00:00:00 +99-12-31 11:59:59 99-12-31 23:59:59 +21-01-03 08:30:00 21-01-03 08:30:00 +21-07-03 06:30:00 21-07-03 18:30:00 +SELECT TO_CHAR(c1, 'Rrrr-Mm-Dd') AS C1, TO_CHAR(c2, 'hh:mi:ss') AS C2, TO_CHAR(c3, 'Rrrr-mm-dd Hh24:mi:ss') AS C3 FROM t_to_char1; +C1 C2 C3 +1000-01-01 12:00:00 1000-01-01 00:00:00 +9999-12-31 11:59:59 9999-12-31 23:59:59 +2021-01-03 08:30:00 2021-01-03 08:30:00 +2021-07-03 06:30:00 2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'rr-mm-dd') AS C1, TO_CHAR(c2, 'hh:mi:ss') AS C2, TO_CHAR(c3, 'yy-mm-dd hh24:Mi:ss') AS C3 FROM t_to_char1; +C1 C2 C3 +00-01-01 12:00:00 00-01-01 00:00:00 +99-12-31 11:59:59 99-12-31 23:59:59 +21-01-03 08:30:00 21-01-03 08:30:00 +21-07-03 06:30:00 21-07-03 18:30:00 +# +# test AD/A.D./BC/B.C./AM/A.M./PM/P.M. +# +SELECT TO_CHAR(c1, 'ADYYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'AD.YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +AD1000-01-01 12:00:00 AD.1000-01-01 00:00:00 +AD9999-12-31 11:59:59 AD.9999-12-31 23:59:59 +AD2021-01-03 08:30:00 AD.2021-01-03 08:30:00 +AD2021-07-03 06:30:00 AD.2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 12:00:00 A.D..1000-01-01 00:00:00 +A.D.9999-12-31 11:59:59 A.D..9999-12-31 23:59:59 +A.D.2021-01-03 08:30:00 A.D..2021-01-03 08:30:00 +A.D.2021-07-03 06:30:00 A.D..2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'ADYYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'AD.YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +AD1000-01-01 12:00:00 AD.1000-01-01 00:00:00 +AD9999-12-31 11:59:59 AD.9999-12-31 23:59:59 +AD2021-01-03 08:30:00 AD.2021-01-03 08:30:00 +AD2021-07-03 06:30:00 AD.2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 12:00:00 A.D..1000-01-01 00:00:00 +A.D.9999-12-31 11:59:59 A.D..9999-12-31 23:59:59 +A.D.2021-01-03 08:30:00 A.D..2021-01-03 08:30:00 +A.D.2021-07-03 06:30:00 A.D..2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'BCYYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'BCYYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +AD1000-01-01 12:00:00 AD1000-01-01 00:00:00 +AD9999-12-31 11:59:59 AD9999-12-31 23:59:59 +AD2021-01-03 08:30:00 AD2021-01-03 08:30:00 +AD2021-07-03 06:30:00 AD2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'B.C.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'B.C.YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 12:00:00 A.D.1000-01-01 00:00:00 +A.D.9999-12-31 11:59:59 A.D.9999-12-31 23:59:59 +A.D.2021-01-03 08:30:00 A.D.2021-01-03 08:30:00 +A.D.2021-07-03 06:30:00 A.D.2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'bcyyyy-mm-dd') AS C1, TO_CHAR(c2, 'hh:mi:ss') AS C2, TO_CHAR(c3, 'BcYYyy-MM-DD Hh24:mi:sS') AS C3 FROM t_to_char1; +C1 C2 C3 +AD1000-01-01 12:00:00 AD1000-01-01 00:00:00 +AD9999-12-31 11:59:59 AD9999-12-31 23:59:59 +AD2021-01-03 08:30:00 AD2021-01-03 08:30:00 +AD2021-07-03 06:30:00 AD2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'b.c.yyyy-mm-dd') AS C1, TO_CHAR(c2, 'hh:mI:Ss') AS C2, TO_CHAR(c3, 'b.C.Yyyy-Mm-dd hH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 12:00:00 A.D.1000-01-01 00:00:00 +A.D.9999-12-31 11:59:59 A.D.9999-12-31 23:59:59 +A.D.2021-01-03 08:30:00 A.D.2021-01-03 08:30:00 +A.D.2021-07-03 06:30:00 A.D.2021-07-03 18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'PMHH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD P.M.HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 AM12:00:00 A.D..1000-01-01 A.M.00:00:00 +A.D.9999-12-31 PM11:59:59 A.D..9999-12-31 P.M.23:59:59 +A.D.2021-01-03 AM08:30:00 A.D..2021-01-03 A.M.08:30:00 +A.D.2021-07-03 PM06:30:00 A.D..2021-07-03 P.M.18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'pmHH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD p.m.HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 AM12:00:00 A.D..1000-01-01 A.M.00:00:00 +A.D.9999-12-31 PM11:59:59 A.D..9999-12-31 P.M.23:59:59 +A.D.2021-01-03 AM08:30:00 A.D..2021-01-03 A.M.08:30:00 +A.D.2021-07-03 PM06:30:00 A.D..2021-07-03 P.M.18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'AMHH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD A.m.HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 AM12:00:00 A.D..1000-01-01 A.M.00:00:00 +A.D.9999-12-31 PM11:59:59 A.D..9999-12-31 P.M.23:59:59 +A.D.2021-01-03 AM08:30:00 A.D..2021-01-03 A.M.08:30:00 +A.D.2021-07-03 PM06:30:00 A.D..2021-07-03 P.M.18:30:00 +SELECT TO_CHAR(c1, 'A.D.YYYY-MM-DD') AS C1, TO_CHAR(c2, 'amHH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD a.M.HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +A.D.1000-01-01 AM12:00:00 A.D..1000-01-01 A.M.00:00:00 +A.D.9999-12-31 PM11:59:59 A.D..9999-12-31 P.M.23:59:59 +A.D.2021-01-03 AM08:30:00 A.D..2021-01-03 A.M.08:30:00 +A.D.2021-07-03 PM06:30:00 A.D..2021-07-03 P.M.18:30:00 +# +# test format without order +# +SELECT TO_CHAR(c1, 'MM-YYYY-DD') AS C1, TO_CHAR(c2, 'HH:SS:MI') AS C2, TO_CHAR(c3, 'DD-YY-MM MI:SS:HH24') AS C3 FROM t_to_char1; +C1 C2 C3 +01-1000-01 12:00:00 01-00-01 00:00:00 +12-9999-31 11:59:59 31-99-12 59:59:23 +01-2021-03 08:00:30 03-21-01 30:00:08 +07-2021-03 06:00:30 03-21-07 30:00:18 +SELECT TO_CHAR(c1, 'yyy-Dd-Mon') AS C1, TO_CHAR(c2, 'mi:Hh12:Ss') AS C2, TO_CHAR(c3, 'Ss:Hh:Mi Dy-y-Month') AS C3 FROM t_to_char1; +C1 C2 C3 +000-01-Jan 00:12:00 00:12:00 Wed-0-January +999-31-Dec 59:11:59 59:11:59 Fri-9-December +021-03-Jan 30:08:00 00:08:30 Sun-1-January +021-03-Jul 30:06:00 00:06:30 Sat-1-July +SELECT TO_CHAR(c1, 'Dd-Mm-Rrrr') AS C1, TO_CHAR(c2, 'ss:hh:mi') AS C2, TO_CHAR(c3, 'ss:Rrrr-hh24-dd mon:mi') AS C3 FROM t_to_char1; +C1 C2 C3 +01-01-1000 00:12:00 00:1000-00-01 Jan:00 +31-12-9999 59:11:59 59:9999-23-31 Dec:59 +03-01-2021 00:08:30 00:2021-08-03 Jan:30 +03-07-2021 00:06:30 00:2021-18-03 Jul:30 +SELECT TO_CHAR(c1, 'YYYYA.D.-MM-DD') AS C1, TO_CHAR(c2, 'HH:MI:SS') AS C2, TO_CHAR(c3, 'A.D..YYYY-MM-DD HH24:MI:SS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000A.D.-01-01 12:00:00 A.D..1000-01-01 00:00:00 +9999A.D.-12-31 11:59:59 A.D..9999-12-31 23:59:59 +2021A.D.-01-03 08:30:00 A.D..2021-01-03 08:30:00 +2021A.D.-07-03 06:30:00 A.D..2021-07-03 18:30:00 +# +# test for special characters +# +SELECT TO_CHAR(c1, 'YYYYMMDD') AS C1, TO_CHAR(c2, 'HHMISS') AS C2, TO_CHAR(c3, 'YYMMDDHH24MISS') AS C3 FROM t_to_char1; +C1 C2 C3 +10000101 120000 000101000000 +99991231 115959 991231235959 +20210103 083000 210103083000 +20210703 063000 210703183000 +SELECT TO_CHAR(c1, 'YYYY!!MM@DD') AS C1, TO_CHAR(c2, 'HH#MI$SS') AS C2, TO_CHAR(c3, 'YY%MM^DD*HH24(MI)SS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000!!01@01 12#00$00 00%01^01*00(00)00 +9999!!12@31 11#59$59 99%12^31*23(59)59 +2021!!01@03 08#30$00 21%01^03*08(30)00 +2021!!07@03 06#30$00 21%07^03*18(30)00 +SELECT TO_CHAR(c1, 'YYYY_MM+DD') AS C1, TO_CHAR(c2, 'HH=MI{SS') AS C2, TO_CHAR(c3, 'YY}MMDDHH24MISS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000_01+01 12=00{00 00}0101000000 +9999_12+31 11=59{59 99}1231235959 +2021_01+03 08=30{00 21}0103083000 +2021_07+03 06=30{00 21}0703183000 +SELECT TO_CHAR(c1, 'YYYY,MM.DD') AS C1, TO_CHAR(c2, 'HH/MI;SS') AS C2, TO_CHAR(c3, 'YY>MM01<01]00[0000 +9999,12.31 11/59;59 99>12<31]23[5959 +2021,01.03 08/30;00 21>01<03]08[3000 +2021,07.03 06/30;00 21>07<03]18[3000 +SELECT TO_CHAR(c1, 'YYYY||||MM|DD') AS C1, TO_CHAR(c2, 'HH&|MI|&|SS') AS C2, TO_CHAR(c3, 'YY&&&\\MM|&&|DD HH24|| MI&||"abx"|SS') AS C3 FROM t_to_char1; +C1 C2 C3 +1000|||0101 12&|00&|00 00&&&\01&&|01 00| 00&||abx00 +9999|||1231 11&|59&|59 99&&&\12&&|31 23| 59&||abx59 +2021|||0103 08&|30&|00 21&&&\01&&|03 08| 30&||abx00 +2021|||0703 06&|30&|00 21&&&\07&&|03 18| 30&||abx00 +SELECT TO_CHAR(c1, 'YYYY&MM-DD') FROM t_to_char1 where c0=1; +ERROR HY000: Invalid argument error: date format not recognized at &MM-DD in function to_char. +SELECT TO_CHAR(c1, 'YYYY"abx"MM"bsz"DD') AS C1 FROM t_to_char1; +C1 +1000abx01bsz01 +9999abx12bsz31 +2021abx01bsz03 +2021abx07bsz03 +# +# test for other locale +# +SET character_set_client='utf8'; +SET character_set_connection='utf8'; +SET character_set_results='utf8'; +SET lc_time_names='zh_TW'; +SELECT TO_CHAR(c1, 'YYYY-MON-DAY') FROM t_to_char1; +TO_CHAR(c1, 'YYYY-MON-DAY') +1000- 1月-週三 +9999-12月-週五 +2021- 1月-週日 +2021- 7月-週六 +SET lc_time_names='de_DE'; +SELECT TO_CHAR(c1, 'YYYY-MON-DAY') FROM t_to_char1; +TO_CHAR(c1, 'YYYY-MON-DAY') +1000-Jan-Mittwoch +9999-Dez-Freitag +2021-Jan-Sonntag +2021-Jul-Samstag +SET lc_time_names='en_US'; +SELECT TO_CHAR(c1, 'YYYY-MON-DAY') FROM t_to_char1; +TO_CHAR(c1, 'YYYY-MON-DAY') +1000-Jan-Wednesday +9999-Dec-Friday +2021-Jan-Sunday +2021-Jul-Saturday +SET lc_time_names='zh_CN'; +SELECT TO_CHAR(c1, 'YYYY-MON-DAY') FROM t_to_char1; +TO_CHAR(c1, 'YYYY-MON-DAY') +1000- 1月-星期三 +9999-12月-星期五 +2021- 1月-星期日 +2021- 7月-星期六 +# +# test for invalid format +# +SELECT TO_CHAR(c1, 'YYYYaxMON-DAY') FROM t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at axMON-DA in function to_char. +SELECT TO_CHAR(c1, 'YYYY\nMON-DAY') FROM t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at +MON-DAY in function to_char. +SELECT TO_CHAR(c1, 'YYYY\rMON-DAY') FROM t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at MON-DAY in function to_char. +SELECT TO_CHAR(c1, 'YYYY分隔MON-DAY') FROM t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at 分隔MO in function to_char. +SELECT TO_CHAR(c1, 'YYYY-分隔MON-DAY') FROM t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at 分隔MO in function to_char. +select to_char(c3, 'YYYYxDDD') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at xDDD in function to_char. +select to_char(c3, 'YYYY&DDD') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at &DDD in function to_char. +select to_char(c3, 'xxYYYY-DD') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at xxYYYY-D in function to_char. +SET character_set_client='latin1'; +SET character_set_connection='latin1'; +SET character_set_results='latin1'; +# +# test for unusual format +# +select to_char(c3, 'YYYYYYYYYYYYYYY') from t_to_char1; +to_char(c3, 'YYYYYYYYYYYYYYY') +100010001000000 +999999999999999 +202120212021021 +202120212021021 +select to_char(c3, 'YYYYYYYYYYYYYYYDDDDDD') from t_to_char1; +to_char(c3, 'YYYYYYYYYYYYYYYDDDDDD') +100010001000000010101 +999999999999999313131 +202120212021021030303 +202120212021021030303 +# +# oracle max length is 144 +# +select to_char(c3, 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: datetime format string is too long in function to_char. +CREATE TABLE t_f(c1 varchar(150)); +insert into t_f values('YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-DD'); +select to_char('2000-11-11', c1) from t_f; +to_char('2000-11-11', c1) +NULL +Warnings: +Warning 3047 Invalid argument error: datetime format string is too long in function to_char. +DROP TABLE t_f; +select to_char(c3, 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-DD-MM') from t_to_char1 where c0 = 1; +to_char(c3, 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-DD-MM') +100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000-01-01 +# +# now only support two parameter. +# +select to_char(c3) from t_to_char1 where c0 =1; +to_char(c3) +1000-01-01 00:00:00 +select to_char(c3, "YYYY-MM-DD HH:MI:SS") from t_to_char1 where c0 =1; +to_char(c3, "YYYY-MM-DD HH:MI:SS") +1000-01-01 12:00:00 +select to_char(c3, "YYYY-MM-DD HH:MI:SS", "zh_CN") from t_to_char1 where c0 = 1; +ERROR 42000: Incorrect parameter count in the call to native function 'to_char' +select to_char(c3, "YYYY-MM-DD HH:MI:SS", "NLS_DATE_LANGUAGE = zh_CN") from t_to_char1 where c0 = 1; +ERROR 42000: Incorrect parameter count in the call to native function 'to_char' +# +# oracle support format but mariadb does not support +# +select to_char(c3, 'DDD') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at D in function to_char. +select to_char(c3, 'D') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at D in function to_char. +select to_char(c3, 'DS') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at DS in function to_char. +select to_char(c3, 'IY') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at IY in function to_char. +select to_char(c3, 'IYYY') from t_to_char1 where c0 = 1; +ERROR HY000: Invalid argument error: date format not recognized at IYYY in function to_char. +# +# test for first argument data type +# +select to_char(1, 'yyyy'); +ERROR HY000: Invalid argument error: data type of first argument must be type date/datetime/time or string in function to_char. +select to_char(1.1, 'yyyy'); +ERROR HY000: Invalid argument error: data type of first argument must be type date/datetime/time or string in function to_char. +CREATE TABLE t_a(c1 int, c2 float, c3 decimal, c4 char(20), c5 varchar(20), c6 nchar(20), c7 nvarchar(20)); +insert into t_a VALUES (1, 3.2, 2002.02, '2000-11-11', '2000-11-11', '2000-11-11', '2000-11-11'); +Warnings: +Note 1265 Data truncated for column 'c3' at row 1 +SELECT TO_CHAR(c1, 'YYYY') from t_a; +ERROR HY000: Invalid argument error: data type of first argument must be type date/datetime/time or string in function to_char. +SELECT TO_CHAR(c2, 'YYYY') from t_a; +ERROR HY000: Invalid argument error: data type of first argument must be type date/datetime/time or string in function to_char. +SELECT TO_CHAR(c3, 'YYYY') from t_a; +ERROR HY000: Invalid argument error: data type of first argument must be type date/datetime/time or string in function to_char. +SELECT TO_CHAR(c4, 'YYYY') from t_a; +TO_CHAR(c4, 'YYYY') +2000 +SELECT TO_CHAR(c5, 'YYYY') from t_a; +TO_CHAR(c5, 'YYYY') +2000 +SELECT TO_CHAR(c6, 'YYYY') from t_a; +TO_CHAR(c6, 'YYYY') +2000 +SELECT TO_CHAR(c7, 'YYYY') from t_a; +TO_CHAR(c7, 'YYYY') +2000 +DROP TABLE t_a; +CREATE TABLE t_b(c0 int, c1 char(20), c2 varchar(20), c3 nchar(20), c4 nvarchar(20)); +INSERT INTO t_b VALUES (1111, 'YYYY-MM-DD', 'YYYY-MM-DD', 'YYYY-MM-DD', 'YYYY-MM-DD'); +SELECT TO_CHAR('2000-11-11', c0) FROM t_b; +TO_CHAR('2000-11-11', c0) +NULL +Warnings: +Warning 3047 Invalid argument error: date format not recognized at 1111 in function to_char. +SELECT TO_CHAR('2000-11-11', c1) FROM t_b; +TO_CHAR('2000-11-11', c1) +2000-11-11 +SELECT TO_CHAR('2000-11-11', c2) FROM t_b; +TO_CHAR('2000-11-11', c2) +2000-11-11 +SELECT TO_CHAR('2000-11-11', c3) FROM t_b; +TO_CHAR('2000-11-11', c3) +2000-11-11 +SELECT TO_CHAR('2000-11-11', c4) FROM t_b; +TO_CHAR('2000-11-11', c4) +2000-11-11 +DROP TABLE t_b; +EXPLAIN EXTENDED SELECT TO_CHAR(c1, 'YYYY-MM-DD') FROM t_to_char1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t_to_char1 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 select to_char(`test`.`t_to_char1`.`c1`,'YYYY-MM-DD') AS `TO_CHAR(c1, 'YYYY-MM-DD')` from `test`.`t_to_char1` +# +# test for time type with date format string +# +SELECT TO_CHAR(c2, 'YYYY-MM-DD HH:MI:SS') from t_to_char1; +TO_CHAR(c2, 'YYYY-MM-DD HH:MI:SS') +0000-00-00 12:00:00 +0000-00-00 11:59:59 +0000-00-00 08:30:00 +0000-00-00 06:30:00 +SELECT TO_CHAR(c2, 'YYYY-MON-DY HH:MI:SS') from t_to_char1; +TO_CHAR(c2, 'YYYY-MON-DY HH:MI:SS') +0000-00-00 12:00:00 +0000-00-00 11:59:59 +0000-00-00 08:30:00 +0000-00-00 06:30:00 +SELECT TO_CHAR(c2, 'MON-YYYY-DY HH:MI:SS') from t_to_char1; +TO_CHAR(c2, 'MON-YYYY-DY HH:MI:SS') +00-0000-00 12:00:00 +00-0000-00 11:59:59 +00-0000-00 08:30:00 +00-0000-00 06:30:00 +SELECT TO_CHAR(c2, 'YYYY-MONTH-DAY HH:MI:SS') from t_to_char1; +TO_CHAR(c2, 'YYYY-MONTH-DAY HH:MI:SS') +0000-00-00 12:00:00 +0000-00-00 11:59:59 +0000-00-00 08:30:00 +0000-00-00 06:30:00 +DROP TABLE t_to_char1; +DROP TABLE t_to_char2; +# +# Test strict mode +# +create table t1 (a datetime, b int, f varchar(30)) engine=myisam; +insert into t1 values ("2021-01-24 19:22:10", 2014, "YYYY-MM-DD"); +insert into t1 values ("2021-01-24 19:22:10", 2014, "YYYY-MQ-DD"); +create table t2 (a varchar(30)) engine=myisam; +insert into t2 select to_char(a,f) from t1; +Warnings: +Warning 3047 Invalid argument error: date format not recognized at MQ-DD in function to_char. +set @@sql_mode="STRICT_ALL_TABLES"; +insert into t2 select to_char(a,f) from t1; +ERROR HY000: Invalid argument error: date format not recognized at MQ-DD in function to_char. +select * from t2; +a +2021-01-24 +NULL +2021-01-24 +drop table t1,t2; +set @local.sql_mode=@sql_mode; +# +# MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument +# +SELECT TO_CHAR((VALUES('2022-12-12','2020-10-10'))); +ERROR HY000: Illegal parameter data type row for operation 'to_char' +SELECT TO_CHAR((STR_TO_DATE('2023-01-01', '%d-%m-%Y'), 'YYYY-MM-DD') ); +ERROR HY000: Illegal parameter data type row for operation 'to_char' diff --git a/mysql-test/suite/compat/oracle/r/func_trim.result b/mysql-test/suite/compat/oracle/r/func_trim.result new file mode 100644 index 00000000..bed8dadf --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/func_trim.result @@ -0,0 +1,170 @@ +SET sql_mode=ORACLE; +# +# MDEV-15664 sql_mode=ORACLE: Make TRIM return NULL instead of empty string +# +SELECT TRIM('abc'), TRIM('abc ')||'.', '.'||TRIM(' abc ')||'.', TRIM(' '), TRIM(NULL), TRIM(SPACE(0)),TRIM(SPACE(10)) FROM dual; +TRIM('abc') TRIM('abc ')||'.' '.'||TRIM(' abc ')||'.' TRIM(' ') TRIM(NULL) TRIM(SPACE(0)) TRIM(SPACE(10)) +abc abc. .abc. NULL NULL NULL NULL +SELECT TRIM(TRAILING 'abc' FROM 'abc'); +TRIM(TRAILING 'abc' FROM 'abc') +NULL +SELECT TRIM(TRAILING 'abc' FROM 'abc '); +TRIM(TRAILING 'abc' FROM 'abc ') +abc +SELECT TRIM(TRAILING 'abc' FROM ' abc'); +TRIM(TRAILING 'abc' FROM ' abc') + +SELECT TRIM(LEADING 'abc' FROM 'abc'); +TRIM(LEADING 'abc' FROM 'abc') +NULL +SELECT TRIM(LEADING 'abc' FROM 'abc '); +TRIM(LEADING 'abc' FROM 'abc ') + +SELECT TRIM(LEADING 'abc' FROM ' abc'); +TRIM(LEADING 'abc' FROM ' abc') + abc +SELECT TRIM(BOTH 'abc' FROM 'abc'); +TRIM(BOTH 'abc' FROM 'abc') +NULL +SELECT TRIM(BOTH 'abc' FROM 'abc '); +TRIM(BOTH 'abc' FROM 'abc ') + +SELECT TRIM(BOTH 'abc' FROM ' abc'); +TRIM(BOTH 'abc' FROM ' abc') + +SELECT RTRIM('abc'), RTRIM('abc ')||'.', RTRIM(' abc ')||'.', RTRIM(' '), RTRIM(NULL), RTRIM(SPACE(0)),RTRIM(SPACE(10)) FROM dual; +RTRIM('abc') RTRIM('abc ')||'.' RTRIM(' abc ')||'.' RTRIM(' ') RTRIM(NULL) RTRIM(SPACE(0)) RTRIM(SPACE(10)) +abc abc. abc. NULL NULL NULL NULL +SELECT LTRIM('abc'), LTRIM('abc '), LTRIM(' abc '), LTRIM(' '), LTRIM(NULL), LTRIM(SPACE(0)),LTRIM(SPACE(10)) FROM dual; +LTRIM('abc') LTRIM('abc ') LTRIM(' abc ') LTRIM(' ') LTRIM(NULL) LTRIM(SPACE(0)) LTRIM(SPACE(10)) +abc abc abc NULL NULL NULL NULL +CREATE TABLE t1 (c1 VARCHAR(10),ord INTEGER); +INSERT INTO t1 VALUES ('abc',1); +INSERT INTO t1 VALUES (SPACE(0),2); +INSERT INTO t1 VALUES ('',3); +INSERT INTO t1 VALUES (' ',4); +INSERT INTO t1 VALUES (' ',5); +INSERT INTO t1 VALUES (' a ',6); +INSERT INTO t1 VALUES ('aa',7); +INSERT INTO t1 VALUES ('aabb',8); +INSERT INTO t1 VALUES ('bbaa',9); +INSERT INTO t1 VALUES ('aabbaa',10); +SELECT ord,'['||c1||']','.'||COALESCE(TRIM(LEADING 'a' FROM c1),'NULL')||'.' FROM t1 ORDER BY ord; +ord '['||c1||']' '.'||COALESCE(TRIM(LEADING 'a' FROM c1),'NULL')||'.' +1 [abc] .bc. +2 [] .NULL. +3 [] .NULL. +4 [ ] . . +5 [ ] . . +6 [ a ] . a . +7 [aa] .NULL. +8 [aabb] .bb. +9 [bbaa] .bbaa. +10 [aabbaa] .bbaa. +SELECT ord,'['||c1||']','.'||COALESCE(TRIM(TRAILING 'a' FROM c1),'NULL')||'.' FROM t1 ORDER BY ord; +ord '['||c1||']' '.'||COALESCE(TRIM(TRAILING 'a' FROM c1),'NULL')||'.' +1 [abc] .abc. +2 [] .NULL. +3 [] .NULL. +4 [ ] . . +5 [ ] . . +6 [ a ] . a . +7 [aa] .NULL. +8 [aabb] .aabb. +9 [bbaa] .bb. +10 [aabbaa] .aabb. +SELECT ord,'['||c1||']','.'||COALESCE(TRIM(BOTH 'a' FROM c1),'NULL')||'.' FROM t1 ORDER BY ord; +ord '['||c1||']' '.'||COALESCE(TRIM(BOTH 'a' FROM c1),'NULL')||'.' +1 [abc] .bc. +2 [] .NULL. +3 [] .NULL. +4 [ ] . . +5 [ ] . . +6 [ a ] . a . +7 [aa] .NULL. +8 [aabb] .bb. +9 [bbaa] .bb. +10 [aabbaa] .bb. +SELECT ord,'['||c1||']',COALESCE(LTRIM(c1),'NULL') FROM t1 ORDER BY ord; +ord '['||c1||']' COALESCE(LTRIM(c1),'NULL') +1 [abc] abc +2 [] NULL +3 [] NULL +4 [ ] NULL +5 [ ] NULL +6 [ a ] a +7 [aa] aa +8 [aabb] aabb +9 [bbaa] bbaa +10 [aabbaa] aabbaa +SELECT ord,'['||c1||']',COALESCE(RTRIM(c1),'NULL')||'.' FROM t1 ORDER BY ord; +ord '['||c1||']' COALESCE(RTRIM(c1),'NULL')||'.' +1 [abc] abc. +2 [] NULL. +3 [] NULL. +4 [ ] NULL. +5 [ ] NULL. +6 [ a ] a. +7 [aa] aa. +8 [aabb] aabb. +9 [bbaa] bbaa. +10 [aabbaa] aabbaa. +EXPLAIN EXTENDED SELECT TRIM('abc'), +TRIM(BOTH 'a' FROM 'abc'), +TRIM(LEADING 'a' FROM 'abc'), +TRIM(TRAILING 'a' FROM 'abc') ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select trim_oracle('abc') AS "TRIM('abc')",trim_oracle(both 'a' from 'abc') AS "TRIM(BOTH 'a' FROM 'abc')",trim_oracle(leading 'a' from 'abc') AS "TRIM(LEADING 'a' FROM 'abc')",trim_oracle(trailing 'a' from 'abc') AS "TRIM(TRAILING 'a' FROM 'abc')" +EXPLAIN EXTENDED SELECT RTRIM('abc'), +LTRIM('abc'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select rtrim_oracle('abc') AS "RTRIM('abc')",ltrim_oracle('abc') AS "LTRIM('abc')" +CREATE VIEW v1 AS SELECT ord,TRIM('abc'),RTRIM('abc'),LTRIM('abc'), +'['||c1||']', +TRIM(LEADING 'a' FROM c1), +TRIM(TRAILING 'a' FROM c1), +TRIM(BOTH 'a' FROM c1), +LTRIM(c1), +RTRIM(c1) +FROM t1 ORDER BY ord ; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select "t1"."ord" AS "ord",trim_oracle('abc') AS "TRIM('abc')",rtrim_oracle('abc') AS "RTRIM('abc')",ltrim_oracle('abc') AS "LTRIM('abc')",concat_operator_oracle(concat_operator_oracle('[',"t1"."c1"),']') AS "'['||c1||']'",trim_oracle(leading 'a' from "t1"."c1") AS "TRIM(LEADING 'a' FROM c1)",trim_oracle(trailing 'a' from "t1"."c1") AS "TRIM(TRAILING 'a' FROM c1)",trim_oracle(both 'a' from "t1"."c1") AS "TRIM(BOTH 'a' FROM c1)",ltrim_oracle("t1"."c1") AS "LTRIM(c1)",rtrim_oracle("t1"."c1") AS "RTRIM(c1)" from "t1" order by "t1"."ord" latin1 latin1_swedish_ci +SELECT * FROM v1; +ord TRIM('abc') RTRIM('abc') LTRIM('abc') '['||c1||']' TRIM(LEADING 'a' FROM c1) TRIM(TRAILING 'a' FROM c1) TRIM(BOTH 'a' FROM c1) LTRIM(c1) RTRIM(c1) +1 abc abc abc [abc] bc abc bc abc abc +2 abc abc abc [] NULL NULL NULL NULL NULL +3 abc abc abc [] NULL NULL NULL NULL NULL +4 abc abc abc [ ] NULL NULL +5 abc abc abc [ ] NULL NULL +6 abc abc abc [ a ] a a a a a +7 abc abc abc [aa] NULL NULL NULL aa aa +8 abc abc abc [aabb] bb aabb bb aabb aabb +9 abc abc abc [bbaa] bbaa bb bb bbaa bbaa +10 abc abc abc [aabbaa] bbaa aabb bb aabbaa aabbaa +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (c1 VARCHAR(10) NOT NULL); +CREATE TABLE t2 AS SELECT TRIM(LEADING 'a' FROM c1) AS C1, +TRIM(TRAILING 'a' FROM c1) AS C2, +TRIM(BOTH 'a' FROM c1) AS C3, +LTRIM(c1) AS C4, +RTRIM(c1) AS C5 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE "t2" ( + "C1" varchar(10) DEFAULT NULL, + "C2" varchar(10) DEFAULT NULL, + "C3" varchar(10) DEFAULT NULL, + "C4" varchar(10) DEFAULT NULL, + "C5" varchar(10) DEFAULT NULL +) +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE trim_oracle (trim_oracle int); +DROP TABLE trim_oracle; diff --git a/mysql-test/suite/compat/oracle/r/gis-debug.result b/mysql-test/suite/compat/oracle/r/gis-debug.result new file mode 100644 index 00000000..9ab74e6e --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/gis-debug.result @@ -0,0 +1,24 @@ +SET sql_mode=ORACLE; +# +# Start of 10.5 tests +# +# +# MDEV-19994 Add class Function_collection +# +SET SESSION debug_dbug="+d,make_item_func_call_native_simulate_not_found"; +SELECT CONTAINS(POINT(1,1),POINT(1,1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(POINT(1,1),POINT(1,1))' at line 1 +SELECT WITHIN(POINT(1,1),POINT(1,1)); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(POINT(1,1),POINT(1,1))' at line 1 +SET SESSION debug_dbug="-d,make_item_func_call_native_simulate_not_found"; +# +# MDEV-20009 Add CAST(expr AS pluggable_type) +# +SET SESSION debug_dbug="+d,emulate_geometry_create_typecast_item"; +SELECT AsText(CAST('POINT(0 0)' AS GEOMETRY)); +AsText(CAST('POINT(0 0)' AS GEOMETRY)) +POINT(0 0) +SET SESSION debug_dbug="-d,emulate_geometry_create_typecast_item"; +# +# End of 10.5 tests +# diff --git a/mysql-test/suite/compat/oracle/r/gis.result b/mysql-test/suite/compat/oracle/r/gis.result new file mode 100644 index 00000000..113cb0ea --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/gis.result @@ -0,0 +1,69 @@ +SET sql_mode=ORACLE; +SELECT CONTAINS(POINT(1,1), POINT(1,1)); +CONTAINS(POINT(1,1), POINT(1,1)) +1 +SELECT CONTAINS(POINT(1,1), POINT(0,0)); +CONTAINS(POINT(1,1), POINT(0,0)) +0 +SELECT WITHIN(POINT(1,1), POINT(1,1)); +WITHIN(POINT(1,1), POINT(1,1)) +1 +SELECT WITHIN(POINT(1,1), POINT(0,0)); +WITHIN(POINT(1,1), POINT(0,0)) +0 +# +# Start of 10.5 tests +# +# +# MDEV-19994 Add class Function_collection +# +SELECT CONTAINS(); +ERROR 42000: Incorrect parameter count in the call to native function 'CONTAINS()' +SELECT CONTAINS(POINT(1,1)); +ERROR 42000: Incorrect parameter count in the call to native function 'CONTAINS(POINT(1,1))' +SELECT CONTAINS(POINT(1,1), POINT(1,1), POINT(1,1)); +ERROR 42000: Incorrect parameter count in the call to native function 'CONTAINS(POINT(1,1), POINT(1,1), POINT(1,1))' +SELECT WITHIN(); +ERROR 42000: Incorrect parameter count in the call to native function 'WITHIN()' +SELECT WITHIN(POINT(1,1)); +ERROR 42000: Incorrect parameter count in the call to native function 'WITHIN(POINT(1,1))' +SELECT WITHIN(POINT(1,1), POINT(1,1), POINT(1,1)); +ERROR 42000: Incorrect parameter count in the call to native function 'WITHIN(POINT(1,1), POINT(1,1), POINT(1,1))' +# +# MDEV-20009 Add CAST(expr AS pluggable_type) +# +SELECT CAST(1 AS GEOMETRY); +ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +SELECT CAST(1 AS GEOMETRYCOLLECTION); +ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +SELECT CAST(1 AS POINT); +ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +SELECT CAST(1 AS LINESTRING); +ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +SELECT CAST(1 AS POLYGON); +ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +SELECT CAST(1 AS MULTIPOINT); +ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +SELECT CAST(1 AS MULTILINESTRING); +ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +SELECT CAST(1 AS MULTIPOLYGON); +ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +SELECT CONVERT(1, GEOMETRY); +ERROR HY000: Operator does not exists: 'CAST(expr AS geometry)' +SELECT CONVERT(1, GEOMETRYCOLLECTION); +ERROR HY000: Operator does not exists: 'CAST(expr AS geometrycollection)' +SELECT CONVERT(1, POINT); +ERROR HY000: Operator does not exists: 'CAST(expr AS point)' +SELECT CONVERT(1, LINESTRING); +ERROR HY000: Operator does not exists: 'CAST(expr AS linestring)' +SELECT CONVERT(1, POLYGON); +ERROR HY000: Operator does not exists: 'CAST(expr AS polygon)' +SELECT CONVERT(1, MULTIPOINT); +ERROR HY000: Operator does not exists: 'CAST(expr AS multipoint)' +SELECT CONVERT(1, MULTILINESTRING); +ERROR HY000: Operator does not exists: 'CAST(expr AS multilinestring)' +SELECT CONVERT(1, MULTIPOLYGON); +ERROR HY000: Operator does not exists: 'CAST(expr AS multipolygon)' +# +# End of 10.5 tests +# diff --git a/mysql-test/suite/compat/oracle/r/information_schema_parameters.result b/mysql-test/suite/compat/oracle/r/information_schema_parameters.result new file mode 100644 index 00000000..f7e9bfca --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/information_schema_parameters.result @@ -0,0 +1,854 @@ +# +# MDEV-15416 Crash when reading I_S.PARAMETERS +# +# Create in sql_mode=ORACLE, display in sql_mode=ORACLE and sql_mode=DEFAULT +SET sql_mode=ORACLE; +CREATE PROCEDURE p1(a0 t1.a%TYPE, +a1 test.t1.a%TYPE, +b0 t1%ROWTYPE, +b1 test.t1%ROWTYPE, +d ROW(a INT,b DOUBLE)) +AS +BEGIN +NULL; +END; +$$ +SET sql_mode=ORACLE; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='p1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"."a"%TYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"."a"%TYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"%ROWTYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"%ROWTYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE PROCEDURE +-------- -------- +SET sql_mode=DEFAULT; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='p1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"."a"%TYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"."a"%TYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"%ROWTYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"%ROWTYPE +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE PROCEDURE +-------- -------- +DROP PROCEDURE p1; +SET sql_mode=ORACLE; +CREATE FUNCTION f1(a0 t1.a%TYPE, +a1 test.t1.a%TYPE, +b0 t1%ROWTYPE, +b1 test.t1%ROWTYPE, +d ROW(a INT,b DOUBLE)) +RETURN INT +AS +BEGIN +RETURN 0; +END; +$$ +SET sql_mode=ORACLE; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='f1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 0 +PARAMETER_MODE NULL +PARAMETER_NAME NULL +DATA_TYPE int +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 10 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER int(11) +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"."a"%TYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"."a"%TYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"%ROWTYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"%ROWTYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE FUNCTION +-------- -------- +SET sql_mode=DEFAULT; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='f1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 0 +PARAMETER_MODE NULL +PARAMETER_NAME NULL +DATA_TYPE int +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 10 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER int(11) +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"."a"%TYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"."a"%TYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "t1"%ROWTYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER "test"."t1"%ROWTYPE +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE FUNCTION +-------- -------- +DROP FUNCTION f1; +# Create in sql_mode=DEFAULT, display in sql_mode=DEFAULT and sql_mode=ORACLE +SET sql_mode=DEFAULT; +CREATE PROCEDURE p1(a0 TYPE OF t1.a, +a1 TYPE OF test.t1.a, +b0 ROW TYPE OF t1, +b1 ROW TYPE OF test.t1, +d ROW(a INT,b DOUBLE)) +BEGIN +END; +$$ +SET sql_mode=DEFAULT; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='p1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `t1`.`a` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `test`.`t1`.`a` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `t1` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `test`.`t1` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE PROCEDURE +-------- -------- +SET sql_mode=ORACLE; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='p1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `t1`.`a` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `test`.`t1`.`a` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `t1` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `test`.`t1` +ROUTINE_TYPE PROCEDURE +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME p1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE PROCEDURE +-------- -------- +DROP PROCEDURE p1; +SET sql_mode=DEFAULT; +CREATE FUNCTION f1(a0 TYPE OF t1.a, +a1 TYPE OF test.t1.a, +b0 ROW TYPE OF t1, +b1 ROW TYPE OF test.t1, +d ROW(a INT,b DOUBLE)) +RETURNS INT +BEGIN +RETURN 0; +END; +$$ +SET sql_mode=DEFAULT; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='f1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 0 +PARAMETER_MODE NULL +PARAMETER_NAME NULL +DATA_TYPE int +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 10 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER int(11) +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `t1`.`a` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `test`.`t1`.`a` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `t1` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `test`.`t1` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE FUNCTION +-------- -------- +SET sql_mode=ORACLE; +SELECT *, '--------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME='f1'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 0 +PARAMETER_MODE NULL +PARAMETER_NAME NULL +DATA_TYPE int +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 10 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER int(11) +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a0 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `t1`.`a` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 2 +PARAMETER_MODE IN +PARAMETER_NAME a1 +DATA_TYPE TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER TYPE OF `test`.`t1`.`a` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 3 +PARAMETER_MODE IN +PARAMETER_NAME b0 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `t1` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 4 +PARAMETER_MODE IN +PARAMETER_NAME b1 +DATA_TYPE ROW TYPE OF +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW TYPE OF `test`.`t1` +ROUTINE_TYPE FUNCTION +-------- -------- +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA test +SPECIFIC_NAME f1 +ORDINAL_POSITION 5 +PARAMETER_MODE IN +PARAMETER_NAME d +DATA_TYPE ROW +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER ROW +ROUTINE_TYPE FUNCTION +-------- -------- +DROP FUNCTION f1; +# +# MDEV 18092 Query with the table I_S.PARAMETERS stop working +# after a package is created +# +SET sql_mode=ORACLE; +CREATE DATABASE db1_mdev18092; +USE db1_mdev18092; +CREATE PROCEDURE p1(a INT) +AS BEGIN +NULL; +END; +$$ +CREATE OR REPLACE PACKAGE employee_tools AS +FUNCTION getSalary(eid INT) RETURN DECIMAL(10,2); +PROCEDURE raiseSalary(eid INT, amount DECIMAL(10,2)); +PROCEDURE raiseSalaryStd(eid INT); +PROCEDURE hire(ename TEXT, esalary DECIMAL(10,2)); +END; +$$ +SELECT *, '---------------' FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_SCHEMA='db1_mdev18092'; +SPECIFIC_CATALOG def +SPECIFIC_SCHEMA db1_mdev18092 +SPECIFIC_NAME p1 +ORDINAL_POSITION 1 +PARAMETER_MODE IN +PARAMETER_NAME a +DATA_TYPE int +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 10 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER int(11) +ROUTINE_TYPE PROCEDURE +--------------- --------------- +DROP DATABASE db1_mdev18092; diff --git a/mysql-test/suite/compat/oracle/r/keywords.result b/mysql-test/suite/compat/oracle/r/keywords.result new file mode 100644 index 00000000..bc9d3d9b --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/keywords.result @@ -0,0 +1,26 @@ +SET sql_mode=ORACLE; +# +# MDEV-17363 Compressed columns cannot be restored from dump +# In sql_mode=ORACLE, COMPRESSED is still valid both as an SP label +# and an SP variable name. +# +BEGIN +IF TRUE THEN +GOTO compressed; +END IF; +SELECT 'This should not be reached' AS warn; +<> +BEGIN +SELECT 1 AS a; +END; +END +$$ +a +1 +DECLARE compressed INT DEFAULT 1; +BEGIN +SELECT compressed; +END +$$ +compressed +1 diff --git a/mysql-test/suite/compat/oracle/r/minus.result b/mysql-test/suite/compat/oracle/r/minus.result new file mode 100644 index 00000000..67b7e534 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/minus.result @@ -0,0 +1,48 @@ +CREATE TABLE tx1 (c1 int, c2 varchar(30)); +CREATE TABLE tx2 (c1 int, c2 varchar(30)); +CREATE TABLE tx3 (c1 int, c2 varchar(30)); +INSERT INTO tx1 VALUES (1, 'jim'); +INSERT INTO tx1 VALUES (2, 'menny'); +INSERT INTO tx1 VALUES (3, 'linda'); +INSERT INTO tx2 VALUES (1, 'jim'); +INSERT INTO tx2 VALUES (2, 'kris'); +INSERT INTO tx2 VALUES (3, 'shory'); +INSERT INTO tx3 VALUES (1, 'jim'); +INSERT INTO tx3 VALUES (2, 'kris'); +INSERT INTO tx3 VALUES (3, 'linda'); +# +# test when sql_mode is not oracle +# +SELECT c2 FROM tx1 EXCEPT SELECT c2 from tx2; +c2 +menny +linda +SELECT c2 FROM tx1 MINUS SELECT c2 from tx2; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT c2 from tx2' at line 1 +create table MINUS (a int); +drop table MINUS; +# +# test when sql_mode is oracle +# +SET sql_mode=ORACLE; +SELECT c2 FROM tx1 MINUS SELECT c2 from tx2; +c2 +menny +linda +SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 MINUS SELECT c2 from tx3; +c2 +menny +SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 EXCEPT SELECT c2 from tx3; +c2 +menny +SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 UNION SELECT c2 from tx3; +c2 +jim +menny +linda +kris +create table MINUS (a int); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'MINUS (a int)' at line 1 +DROP TABLE tx1; +DROP TABLE tx2; +DROP TABLE tx3; diff --git a/mysql-test/suite/compat/oracle/r/misc.result b/mysql-test/suite/compat/oracle/r/misc.result new file mode 100644 index 00000000..fed7e26c --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/misc.result @@ -0,0 +1,35 @@ +SET sql_mode=ORACLE; +# +# Start of 10.2 tests +# +# +# MDEV-27690 Crash on `CHARACTER SET csname COLLATE DEFAULT` in column definition +# +CREATE TABLE t1 (a CHAR(10) CHARACTER SET latin1 COLLATE DEFAULT); +DROP TABLE t1; +SELECT CAST('a' AS CHAR(10) CHARACTER SET latin1 COLLATE DEFAULT); +CAST('a' AS CHAR(10) CHARACTER SET latin1 COLLATE DEFAULT) +a +SELECT COLUMN_GET(COLUMN_CREATE(0, 'string'),0 AS CHAR CHARACTER SET latin1 COLLATE DEFAULT) AS c1; +c1 +string +# +# End of 10.2 tests +# +# +# Start of 10.3 tests +# +# +# MDEV-12086 sql_mode=ORACLE: allow SELECT UNIQUE as a synonym for SELECT DISTINCT +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(20),(30),(30),(30); +SELECT UNIQUE a FROM t1; +a +10 +20 +30 +DROP TABLE t1; +# +# End of 10.3 tests +# diff --git a/mysql-test/suite/compat/oracle/r/mysqldump_restore.result b/mysql-test/suite/compat/oracle/r/mysqldump_restore.result new file mode 100644 index 00000000..f73fa3a3 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/mysqldump_restore.result @@ -0,0 +1,38 @@ +SET sql_mode=ORACLE; +# +# Start of 10.3 tests +# +# +# MDEV-17363 Compressed columns cannot be restored from dump +# +CREATE TABLE t1 (a VARCHAR(1000) COMPRESSED CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL); +INSERT INTO `t1` VALUES (REPEAT('a', 256)); +# Begin testing mysqldump output + restore +# Create 'original table name - _orig +SET @orig_table_name = CONCAT('test.t1', '_orig'); +# Rename original table +ALTER TABLE test.t1 RENAME to test.t1_orig; +# Recreate table from mysqldump output +# Compare original and recreated tables +# Recreated table: test.t1 +# Original table: test.t1_orig +include/diff_tables.inc [test.t1, test.t1_orig] +# Cleanup +DROP TABLE test.t1, test.t1_orig; +CREATE TABLE t1 (a LONGTEXT COMPRESSED CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL); +INSERT INTO `t1` VALUES (REPEAT('a', 256)); +# Begin testing mysqldump output + restore +# Create 'original table name -
_orig +SET @orig_table_name = CONCAT('test.t1', '_orig'); +# Rename original table +ALTER TABLE test.t1 RENAME to test.t1_orig; +# Recreate table from mysqldump output +# Compare original and recreated tables +# Recreated table: test.t1 +# Original table: test.t1_orig +include/diff_tables.inc [test.t1, test.t1_orig] +# Cleanup +DROP TABLE test.t1, test.t1_orig; +# +# End of 10.3 tests +# diff --git a/mysql-test/suite/compat/oracle/r/parser.result b/mysql-test/suite/compat/oracle/r/parser.result new file mode 100644 index 00000000..32ea444e --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/parser.result @@ -0,0 +1,870 @@ +SET sql_mode=ORACLE; +# +# MDEV-15620 Crash when using "SET @@NEW.a=expr" inside a trigger +# +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @@NEW.a=0; +ERROR HY000: Unknown structured system variable or ROW routine variable 'NEW' +DROP TABLE t1; +# +# MDEV-15615 Unexpected syntax error instead of "Unknown system variable" inside an SP +# +DECLARE +a INT; +BEGIN +SET GLOBAL a=10; +END; +$$ +ERROR HY000: Unknown system variable 'a' +# +# MDEV-16202 Latest changes made erroneously some keywords reserved in sql_mode=ORACLE +# +CREATE PROCEDURE p1(name VARCHAR(64), pattern TEXT) AS +query TEXT DEFAULT REPLACE(pattern, 'name', name); +BEGIN +SELECT query AS ''; +EXECUTE IMMEDIATE query; +EXCEPTION +WHEN OTHERS THEN +BEGIN +SHOW ERRORS; +END; +END; +$$ +CREATE PROCEDURE p2(name VARCHAR(64)) AS +BEGIN +CALL p1(name, 'DECLARE name INT; BEGIN name:=10; SELECT name; END'); +EXECUTE IMMEDIATE REPLACE('CREATE TABLE t1 (name INT)', 'name', name); +CALL p1(name, 'SELECT name FROM t1'); +CALL p1(name, 'SELECT name ''alias'' FROM t1'); +CALL p1(name, 'SELECT name()'); +CALL p1(name, 'SELECT name.name()'); +CALL p1(name, 'SELECT name DATE FROM t1'); +CALL p1(name, 'SELECT name HISTORY FROM t1'); +CALL p1(name, 'SELECT name NEXT FROM t1'); +CALL p1(name, 'SELECT name PERIOD FROM t1'); +CALL p1(name, 'SELECT name PREVIOUS FROM t1'); +CALL p1(name, 'SELECT name SYSTEM FROM t1'); +CALL p1(name, 'SELECT name SYSTEM_TIME FROM t1'); +CALL p1(name, 'SELECT name TIME FROM t1'); +CALL p1(name, 'SELECT name TIMESTAMP FROM t1'); +CALL p1(name, 'SELECT name TRANSACTION FROM t1'); +CALL p1(name, 'SELECT name VALUE FROM t1'); +CALL p1(name, 'SELECT name VERSIONING FROM t1'); +CALL p1(name, 'SELECT name WITHOUT FROM t1'); +DROP TABLE t1; +END; +$$ +CALL p2('date'); +DECLARE date INT; BEGIN date:=10; SELECT date; END +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INT; BEGIN date:=10; SELECT date; END' at line 1 +SELECT date FROM t1 +SELECT date 'alias' FROM t1 +Error 1525 Incorrect DATE value: 'alias' +SELECT date() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +SELECT date.date() +Error 1630 FUNCTION date.date does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT date DATE FROM t1 +SELECT date HISTORY FROM t1 +SELECT date NEXT FROM t1 +SELECT date PERIOD FROM t1 +SELECT date PREVIOUS FROM t1 +SELECT date SYSTEM FROM t1 +SELECT date SYSTEM_TIME FROM t1 +SELECT date TIME FROM t1 +SELECT date TIMESTAMP FROM t1 +SELECT date TRANSACTION FROM t1 +SELECT date VALUE FROM t1 +SELECT date VERSIONING FROM t1 +SELECT date WITHOUT FROM t1 +CALL p2('history'); +DECLARE history INT; BEGIN history:=10; SELECT history; END +10 +SELECT history FROM t1 +SELECT history 'alias' FROM t1 +SELECT history() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT history.history() +Error 1630 FUNCTION history.history does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT history DATE FROM t1 +SELECT history HISTORY FROM t1 +SELECT history NEXT FROM t1 +SELECT history PERIOD FROM t1 +SELECT history PREVIOUS FROM t1 +SELECT history SYSTEM FROM t1 +SELECT history SYSTEM_TIME FROM t1 +SELECT history TIME FROM t1 +SELECT history TIMESTAMP FROM t1 +SELECT history TRANSACTION FROM t1 +SELECT history VALUE FROM t1 +SELECT history VERSIONING FROM t1 +SELECT history WITHOUT FROM t1 +CALL p2('next'); +DECLARE next INT; BEGIN next:=10; SELECT next; END +10 +SELECT next FROM t1 +SELECT next 'alias' FROM t1 +SELECT next() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT next.next() +Error 1630 FUNCTION next.next does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT next DATE FROM t1 +SELECT next HISTORY FROM t1 +SELECT next NEXT FROM t1 +SELECT next PERIOD FROM t1 +SELECT next PREVIOUS FROM t1 +SELECT next SYSTEM FROM t1 +SELECT next SYSTEM_TIME FROM t1 +SELECT next TIME FROM t1 +SELECT next TIMESTAMP FROM t1 +SELECT next TRANSACTION FROM t1 +SELECT next VALUE FROM t1 +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM t1' at line 1 +SELECT next VERSIONING FROM t1 +SELECT next WITHOUT FROM t1 +CALL p2('period'); +DECLARE period INT; BEGIN period:=10; SELECT period; END +10 +SELECT period FROM t1 +SELECT period 'alias' FROM t1 +SELECT period() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT period.period() +Error 1630 FUNCTION period.period does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT period DATE FROM t1 +SELECT period HISTORY FROM t1 +SELECT period NEXT FROM t1 +SELECT period PERIOD FROM t1 +SELECT period PREVIOUS FROM t1 +SELECT period SYSTEM FROM t1 +SELECT period SYSTEM_TIME FROM t1 +SELECT period TIME FROM t1 +SELECT period TIMESTAMP FROM t1 +SELECT period TRANSACTION FROM t1 +SELECT period VALUE FROM t1 +SELECT period VERSIONING FROM t1 +SELECT period WITHOUT FROM t1 +CALL p2('previous'); +DECLARE previous INT; BEGIN previous:=10; SELECT previous; END +10 +SELECT previous FROM t1 +SELECT previous 'alias' FROM t1 +SELECT previous() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT previous.previous() +Error 1630 FUNCTION previous.previous does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT previous DATE FROM t1 +SELECT previous HISTORY FROM t1 +SELECT previous NEXT FROM t1 +SELECT previous PERIOD FROM t1 +SELECT previous PREVIOUS FROM t1 +SELECT previous SYSTEM FROM t1 +SELECT previous SYSTEM_TIME FROM t1 +SELECT previous TIME FROM t1 +SELECT previous TIMESTAMP FROM t1 +SELECT previous TRANSACTION FROM t1 +SELECT previous VALUE FROM t1 +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM t1' at line 1 +SELECT previous VERSIONING FROM t1 +SELECT previous WITHOUT FROM t1 +CALL p2('system'); +DECLARE system INT; BEGIN system:=10; SELECT system; END +10 +SELECT system FROM t1 +SELECT system 'alias' FROM t1 +SELECT system() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT system.system() +Error 1630 FUNCTION system.system does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT system DATE FROM t1 +SELECT system HISTORY FROM t1 +SELECT system NEXT FROM t1 +SELECT system PERIOD FROM t1 +SELECT system PREVIOUS FROM t1 +SELECT system SYSTEM FROM t1 +SELECT system SYSTEM_TIME FROM t1 +SELECT system TIME FROM t1 +SELECT system TIMESTAMP FROM t1 +SELECT system TRANSACTION FROM t1 +SELECT system VALUE FROM t1 +SELECT system VERSIONING FROM t1 +SELECT system WITHOUT FROM t1 +CALL p2('system_time'); +DECLARE system_time INT; BEGIN system_time:=10; SELECT system_time; END +10 +SELECT system_time FROM t1 +SELECT system_time 'alias' FROM t1 +SELECT system_time() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT system_time.system_time() +Error 1630 FUNCTION system_time.system_time does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT system_time DATE FROM t1 +SELECT system_time HISTORY FROM t1 +SELECT system_time NEXT FROM t1 +SELECT system_time PERIOD FROM t1 +SELECT system_time PREVIOUS FROM t1 +SELECT system_time SYSTEM FROM t1 +SELECT system_time SYSTEM_TIME FROM t1 +SELECT system_time TIME FROM t1 +SELECT system_time TIMESTAMP FROM t1 +SELECT system_time TRANSACTION FROM t1 +SELECT system_time VALUE FROM t1 +SELECT system_time VERSIONING FROM t1 +SELECT system_time WITHOUT FROM t1 +CALL p2('time'); +DECLARE time INT; BEGIN time:=10; SELECT time; END +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INT; BEGIN time:=10; SELECT time; END' at line 1 +SELECT time FROM t1 +SELECT time 'alias' FROM t1 +Error 1525 Incorrect TIME value: 'alias' +SELECT time() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +SELECT time.time() +Error 1630 FUNCTION time.time does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT time DATE FROM t1 +SELECT time HISTORY FROM t1 +SELECT time NEXT FROM t1 +SELECT time PERIOD FROM t1 +SELECT time PREVIOUS FROM t1 +SELECT time SYSTEM FROM t1 +SELECT time SYSTEM_TIME FROM t1 +SELECT time TIME FROM t1 +SELECT time TIMESTAMP FROM t1 +SELECT time TRANSACTION FROM t1 +SELECT time VALUE FROM t1 +SELECT time VERSIONING FROM t1 +SELECT time WITHOUT FROM t1 +CALL p2('timestamp'); +DECLARE timestamp INT; BEGIN timestamp:=10; SELECT timestamp; END +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INT; BEGIN timestamp:=10; SELECT timestamp; END' at line 1 +SELECT timestamp FROM t1 +SELECT timestamp 'alias' FROM t1 +Error 1525 Incorrect DATETIME value: 'alias' +SELECT timestamp() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +SELECT timestamp.timestamp() +Error 1630 FUNCTION timestamp.timestamp does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT timestamp DATE FROM t1 +SELECT timestamp HISTORY FROM t1 +SELECT timestamp NEXT FROM t1 +SELECT timestamp PERIOD FROM t1 +SELECT timestamp PREVIOUS FROM t1 +SELECT timestamp SYSTEM FROM t1 +SELECT timestamp SYSTEM_TIME FROM t1 +SELECT timestamp TIME FROM t1 +SELECT timestamp TIMESTAMP FROM t1 +SELECT timestamp TRANSACTION FROM t1 +SELECT timestamp VALUE FROM t1 +SELECT timestamp VERSIONING FROM t1 +SELECT timestamp WITHOUT FROM t1 +CALL p2('transaction'); +DECLARE transaction INT; BEGIN transaction:=10; SELECT transaction; END +10 +SELECT transaction FROM t1 +SELECT transaction 'alias' FROM t1 +SELECT transaction() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT transaction.transaction() +Error 1630 FUNCTION transaction.transaction does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT transaction DATE FROM t1 +SELECT transaction HISTORY FROM t1 +SELECT transaction NEXT FROM t1 +SELECT transaction PERIOD FROM t1 +SELECT transaction PREVIOUS FROM t1 +SELECT transaction SYSTEM FROM t1 +SELECT transaction SYSTEM_TIME FROM t1 +SELECT transaction TIME FROM t1 +SELECT transaction TIMESTAMP FROM t1 +SELECT transaction TRANSACTION FROM t1 +SELECT transaction VALUE FROM t1 +SELECT transaction VERSIONING FROM t1 +SELECT transaction WITHOUT FROM t1 +CALL p2('value'); +DECLARE value INT; BEGIN value:=10; SELECT value; END +10 +SELECT value FROM t1 +SELECT value 'alias' FROM t1 +SELECT value() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 +SELECT value.value() +Error 1630 FUNCTION value.value does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT value DATE FROM t1 +SELECT value HISTORY FROM t1 +SELECT value NEXT FROM t1 +SELECT value PERIOD FROM t1 +SELECT value PREVIOUS FROM t1 +SELECT value SYSTEM FROM t1 +SELECT value SYSTEM_TIME FROM t1 +SELECT value TIME FROM t1 +SELECT value TIMESTAMP FROM t1 +SELECT value TRANSACTION FROM t1 +SELECT value VALUE FROM t1 +SELECT value VERSIONING FROM t1 +SELECT value WITHOUT FROM t1 +CALL p2('versioning'); +DECLARE versioning INT; BEGIN versioning:=10; SELECT versioning; END +10 +SELECT versioning FROM t1 +SELECT versioning 'alias' FROM t1 +SELECT versioning() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT versioning.versioning() +Error 1630 FUNCTION versioning.versioning does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT versioning DATE FROM t1 +SELECT versioning HISTORY FROM t1 +SELECT versioning NEXT FROM t1 +SELECT versioning PERIOD FROM t1 +SELECT versioning PREVIOUS FROM t1 +SELECT versioning SYSTEM FROM t1 +SELECT versioning SYSTEM_TIME FROM t1 +SELECT versioning TIME FROM t1 +SELECT versioning TIMESTAMP FROM t1 +SELECT versioning TRANSACTION FROM t1 +SELECT versioning VALUE FROM t1 +SELECT versioning VERSIONING FROM t1 +SELECT versioning WITHOUT FROM t1 +CALL p2('without'); +DECLARE without INT; BEGIN without:=10; SELECT without; END +10 +SELECT without FROM t1 +SELECT without 'alias' FROM t1 +SELECT without() +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '()' at line 1 +SELECT without.without() +Error 1630 FUNCTION without.without does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual +SELECT without DATE FROM t1 +SELECT without HISTORY FROM t1 +SELECT without NEXT FROM t1 +SELECT without PERIOD FROM t1 +SELECT without PREVIOUS FROM t1 +SELECT without SYSTEM FROM t1 +SELECT without SYSTEM_TIME FROM t1 +SELECT without TIME FROM t1 +SELECT without TIMESTAMP FROM t1 +SELECT without TRANSACTION FROM t1 +SELECT without VALUE FROM t1 +SELECT without VERSIONING FROM t1 +SELECT without WITHOUT FROM t1 +DROP PROCEDURE p2; +DROP PROCEDURE p1; +# +# MDEV-16244 sql_mode=ORACLE: Some keywords do not work in variable declarations +# +SET sql_mode=ORACLE; +DECLARE +do INT; +BEGIN +SELECT do INTO do FROM DUAL; +END; +/ +DECLARE +handler INT; +BEGIN +SELECT handler INTO handler FROM DUAL; +END; +/ +DECLARE +repair INT; +BEGIN +SELECT repair INTO repair FROM DUAL; +END; +/ +DECLARE +shutdown INT; +BEGIN +SELECT shutdown INTO shutdown FROM DUAL; +END; +/ +DECLARE +truncate INT; +BEGIN +SELECT truncate INTO truncate FROM DUAL; +END; +/ +DECLARE +close INT; +BEGIN +SELECT close INTO close FROM DUAL; +END; +/ +DECLARE +commit INT; +BEGIN +SELECT commit INTO commit FROM DUAL; +END; +/ +DECLARE +open INT; +BEGIN +SELECT open INTO open FROM DUAL; +END; +/ +DECLARE +rollback INT; +BEGIN +SELECT rollback INTO rollback FROM DUAL; +END; +/ +DECLARE +savepoint INT; +BEGIN +SELECT savepoint INTO savepoint FROM DUAL; +END; +/ +DECLARE +contains INT; +BEGIN +SELECT contains INTO contains FROM DUAL; +END; +/ +DECLARE +language INT; +BEGIN +SELECT language INTO language FROM DUAL; +END; +/ +DECLARE +no INT; +BEGIN +SELECT no INTO no FROM DUAL; +END; +/ +DECLARE +charset INT; +BEGIN +SELECT charset INTO charset FROM DUAL; +END; +/ +DECLARE +follows INT; +BEGIN +SELECT follows INTO follows FROM DUAL; +END; +/ +DECLARE +precedes INT; +BEGIN +SELECT precedes INTO precedes FROM DUAL; +END; +/ +# +# MDEV-16464 Oracle Comp.: Sql-Error on "SELECT name, comment FROM mysql.proc" +# +SET sql_mode=ORACLE; +SELECT name, comment FROM mysql.proc WHERE db='test'; +name comment +CREATE TABLE comment (comment INT); +SELECT comment FROM comment; +comment +SELECT comment comment FROM comment comment; +comment +SELECT comment AS comment FROM comment AS comment; +comment +DROP TABLE comment; +DECLARE +comment INT; +BEGIN +SELECT comment INTO comment FROM DUAL; +END; +/ +CREATE PROCEDURE comment COMMENT 'test' AS +BEGIN +SELECT 1; +END; +/ +BEGIN +comment; +END; +/ +1 +1 +CALL comment(); +1 +1 +CALL comment; +1 +1 +DROP PROCEDURE comment; +CREATE FUNCTION comment RETURN INT COMMENT 'test' AS +BEGIN +RETURN 1; +END; +/ +Warnings: +Note 1585 This function 'comment' has the same name as a native function +SELECT test.comment() FROM DUAL; +test.comment() +1 +Warnings: +Note 1585 This function 'comment' has the same name as a native function +DROP FUNCTION comment; +# +# MDEV-17660 sql_mode=ORACLE: Some keywords do not work as label names: history, system, versioning, without +# +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +BEGIN +<> +NULL; +END; +/ +# +# MDEV-17666 sql_mode=ORACLE: Keyword ELSEIF should not be reserved +# +DECLARE +ELSEIF INT; +BEGIN +ELSEIF:=1; +END; +/ +BEGIN +<> +NULL; +END; +/ +# +# MDEV-17693 Shift/reduce conflicts for NAMES,ROLE,PASSWORD in the option_value_no_option_type grammar +# +CREATE TABLE names (names INT); +SELECT names FROM names AS names; +names +DROP TABLE names; +CREATE TABLE password (password INT); +SELECT password FROM password AS password; +password +DROP TABLE password; +CREATE TABLE role (role INT); +SELECT role FROM role AS role; +role +DROP TABLE role; +DECLARE +names VARCHAR(32) DEFAULT '[names]'; +password VARCHAR(32) DEFAULT '[password]'; +role VARCHAR(32) DEFAULT '[role]'; +BEGIN +<> +SELECT names; +<> +SELECT password; +<> +SELECT role; +END; +$$ +names +[names] +password +[password] +role +[role] +DECLARE +names VARCHAR(32); +BEGIN +SET names='[names]'; +END; +$$ +ERROR 42000: Variable 'names' must be quoted with `...`, or renamed +DECLARE +password VARCHAR(32); +BEGIN +SET password='[password]'; +END; +$$ +ERROR 42000: Variable 'password' must be quoted with `...`, or renamed +DECLARE +role VARCHAR(32); +BEGIN +SET role='[role]'; +END; +$$ +SELECT @@GLOBAL.names; +ERROR HY000: Unknown system variable 'names' +SELECT @@GLOBAL.password; +ERROR HY000: Unknown system variable 'password' +SELECT @@GLOBAL.role; +ERROR HY000: Unknown system variable 'role' +# +# MDEV-22822 sql_mode="oracle" cannot declare without variable errors +# +# It's OK to have no declarations between DECLARE and BEGIN. +# +BEGIN +DECLARE +BEGIN +NULL; +END; +EXCEPTION +WHEN OTHERS THEN +NULL; +END; +// +DECLARE +BEGIN +NULL; +EXCEPTION +WHEN OTHERS THEN +NULL; +END; +// +BEGIN +<> +DECLARE +BEGIN +NULL; +END; +EXCEPTION +WHEN OTHERS THEN +NULL; +END; +// +# +# End of 10.3 tests +# +# +# MDEV-21998: Server crashes in st_select_lex::add_table_to_list +# upon mix of KILL and sequences +# +KILL ( SELECT 1 ) + LASTVAL(s); +ERROR 42000: KILL does not support subqueries or stored functions +KILL LASTVAL(s); +ERROR 42000: KILL does not support subqueries or stored functions +# +# MDEV-23094: Multiple calls to a Stored Procedure from another +# Stored Procedure crashes server +# +create table t1 (id1 int primary key, data1 int); +create table t2 (id2 int primary key, data2 int); +create procedure p1(id int,dt int) as +begin +if (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +then +select 1; +end if; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +case (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +when 1 then +select 1; +else +select 0; +end case; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +declare wcont int default 1; +begin +while (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and wcont +loop +select 1; +set wcont=0; +end loop; +end; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +declare count int default 1; +begin +repeat +select 1; +set count=count+1; +until (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and +count < 3 +end repeat; +end; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +loop +select 1; +end loop; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +set sql_mode=ORACLE; +create or replace procedure p1(id int, dt int) as +begin +while (1) +loop +exit when (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)); +end loop; +end; +// +call p1(1,2); +call p1(1,2); +drop procedure p1; +drop table t1,t2; +# End of 10.4 tests +# +# Start of 10.5 tests +# +# +# MDEV-20734 Allow reserved keywords as user defined type names +# +CREATE TABLE t1 (a DUAL); +ERROR HY000: Unknown data type: 'DUAL' +SELECT CAST(1 AS DUAL); +ERROR HY000: Unknown data type: 'DUAL' +# +# MDEV-20735 Allow non-reserved keywords as user defined type names +# +CREATE TABLE t1 (a ASCII); +ERROR HY000: Unknown data type: 'ASCII' +SELECT CAST(1 AS ASCII); +ERROR HY000: Unknown data type: 'ASCII' +CREATE TABLE t1 (a LANGUAGE); +ERROR HY000: Unknown data type: 'LANGUAGE' +SELECT CAST(1 AS LANGUAGE); +ERROR HY000: Unknown data type: 'LANGUAGE' +CREATE TABLE t1 (a CLOSE); +ERROR HY000: Unknown data type: 'CLOSE' +SELECT CAST(1 AS CLOSE); +ERROR HY000: Unknown data type: 'CLOSE' +CREATE TABLE t1 (a NAMES); +ERROR HY000: Unknown data type: 'NAMES' +SELECT CAST(1 AS NAMES); +ERROR HY000: Unknown data type: 'NAMES' +CREATE TABLE t1 (a END); +ERROR HY000: Unknown data type: 'END' +SELECT CAST(1 AS END); +ERROR HY000: Unknown data type: 'END' +CREATE TABLE t1 (a GLOBAL); +ERROR HY000: Unknown data type: 'GLOBAL' +SELECT CAST(1 AS GLOBAL); +ERROR HY000: Unknown data type: 'GLOBAL' +CREATE TABLE t1 (a ACTION); +ERROR HY000: Unknown data type: 'ACTION' +SELECT CAST(1 AS ACTION); +ERROR HY000: Unknown data type: 'ACTION' +CREATE TABLE t1 (a BEGIN); +ERROR HY000: Unknown data type: 'BEGIN' +SELECT CAST(1 AS BEGIN); +ERROR HY000: Unknown data type: 'BEGIN' +# +# End of 10.5 tests +# +# +# Start of 10.6 tests +# +# +# MDEV-19682 sql_mode="oracle" does not support sysdate +# +SELECT sysdate LIKE '____-__-__ __:__:__'; +sysdate LIKE '____-__-__ __:__:__' +1 +SELECT sysdate = sysdate(); +sysdate = sysdate() +1 +SELECT sysdate = sysdate(0); +sysdate = sysdate(0) +1 +CREATE DATABASE sysdate; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate' at line 1 +CREATE TABLE sysdate (a INT); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate (a INT)' at line 1 +CREATE TABLE t1 (sysdate INT); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate INT)' at line 1 +CREATE TABLE t1 (a sysdate); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate)' at line 1 +CREATE FUNCTION sysdate RETURN INT AS +BEGIN +RETURN 1; +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate RETURN INT AS +BEGIN +RETURN 1; +END' at line 1 +CREATE FUNCTION sysdate() RETURN INT AS +BEGIN +RETURN 1; +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate() RETURN INT AS +BEGIN +RETURN 1; +END' at line 1 +DECLARE +sysdate INT := 10; +BEGIN +NULL; +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate INT := 10; +BEGIN +NULL; +END' at line 2 +BEGIN +<> +NULL; +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sysdate>> +NULL; +END' at line 2 +# +# End of 10.6 tests +# diff --git a/mysql-test/suite/compat/oracle/r/plugin.result b/mysql-test/suite/compat/oracle/r/plugin.result new file mode 100644 index 00000000..c885c03e --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/plugin.result @@ -0,0 +1,48 @@ +SET sql_mode=ORACLE; +# +# MDEV-16294: INSTALL PLUGIN IF NOT EXISTS / UNINSTALL PLUGIN IF EXISTS +# +# INSTALL IF NOT EXISTS PLUGIN name SONAME library / +# UNINSTALL IF EXISTS PLUGIN|SONAME name +# +select PLUGIN_NAME,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where plugin_library like 'ha_example%'; +PLUGIN_NAME PLUGIN_STATUS PLUGIN_TYPE +INSTALL PLUGIN IF NOT EXISTS example SONAME 'ha_example'; +select PLUGIN_NAME,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where plugin_library like 'ha_example%'; +PLUGIN_NAME PLUGIN_STATUS PLUGIN_TYPE +EXAMPLE ACTIVE STORAGE ENGINE +INSTALL PLUGIN example SONAME 'ha_example'; +ERROR HY000: Plugin 'example' already installed +INSTALL PLUGIN IF NOT EXISTS example SONAME 'ha_example'; +Warnings: +Note 1968 Plugin 'example' already installed +SHOW WARNINGS; +Level Code Message +Note 1968 Plugin 'example' already installed +UNINSTALL PLUGIN IF EXISTS example; +select PLUGIN_NAME,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where plugin_library like 'ha_example%'; +PLUGIN_NAME PLUGIN_STATUS PLUGIN_TYPE +UNINSTALL PLUGIN IF EXISTS example; +Warnings: +Note 1305 PLUGIN example does not exist +SHOW WARNINGS; +Level Code Message +Note 1305 PLUGIN example does not exist +UNINSTALL PLUGIN example; +ERROR 42000: PLUGIN example does not exist +INSTALL SONAME 'ha_example'; +select PLUGIN_NAME,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where plugin_library like 'ha_example%'; +PLUGIN_NAME PLUGIN_STATUS PLUGIN_TYPE +EXAMPLE ACTIVE STORAGE ENGINE +UNUSABLE ACTIVE DAEMON +UNINSTALL SONAME IF EXISTS 'ha_example'; +UNINSTALL SONAME IF EXISTS 'ha_example'; +Warnings: +Note 1305 SONAME ha_example.so does not exist +SHOW WARNINGS; +Level Code Message +Note 1305 SONAME ha_example.so does not exist +select PLUGIN_NAME,PLUGIN_STATUS,PLUGIN_TYPE from information_schema.plugins where plugin_library like 'ha_example%'; +PLUGIN_NAME PLUGIN_STATUS PLUGIN_TYPE +UNINSTALL SONAME 'ha_example'; +ERROR 42000: SONAME ha_example.so does not exist diff --git a/mysql-test/suite/compat/oracle/r/ps.result b/mysql-test/suite/compat/oracle/r/ps.result new file mode 100644 index 00000000..818c97b0 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/ps.result @@ -0,0 +1,264 @@ +SET sql_mode=ORACLE; +# +# MDEV-10801 sql_mode: dynamic SQL placeholders +# +SET @a=10, @b=20; +PREPARE stmt FROM 'SELECT ?,?'; +EXECUTE stmt USING @a, @b; +? ? +10 20 +PREPARE stmt FROM 'SELECT :a,:b'; +EXECUTE stmt USING @a, @b; +:a :b +10 20 +PREPARE stmt FROM 'SELECT :aaa,:bbb'; +EXECUTE stmt USING @a, @b; +:aaa :bbb +10 20 +PREPARE stmt FROM 'SELECT :"a",:"b"'; +EXECUTE stmt USING @a, @b; +:"a" :"b" +10 20 +PREPARE stmt FROM 'SELECT :"aaa",:"bbb"'; +EXECUTE stmt USING @a, @b; +:"aaa" :"bbb" +10 20 +PREPARE stmt FROM 'SELECT :1,:2'; +EXECUTE stmt USING @a, @b; +:1 :2 +10 20 +PREPARE stmt FROM 'SELECT :222,:111'; +EXECUTE stmt USING @a, @b; +:222 :111 +10 20 +PREPARE stmt FROM 'SELECT :0,:65535'; +EXECUTE stmt USING @a, @b; +:0 :65535 +10 20 +PREPARE stmt FROM 'SELECT :65535,:0'; +EXECUTE stmt USING @a, @b; +:65535 :0 +10 20 +# +# MDEV-10709 Expressions as parameters to Dynamic SQL +# +# +# Testing disallowed expressions in USING +# +PREPARE stmt FROM 'SELECT :1 FROM DUAL'; +EXECUTE stmt USING (SELECT 1); +ERROR 42000: EXECUTE..USING does not support subqueries or stored functions +DEALLOCATE PREPARE stmt; +CREATE FUNCTION f1() RETURN VARCHAR +AS +BEGIN +RETURN 'test'; +END; +$$ +PREPARE stmt FROM 'SELECT ? FROM DUAL'; +EXECUTE stmt USING f1(); +ERROR 42000: EXECUTE..USING does not support subqueries or stored functions +DEALLOCATE PREPARE stmt; +DROP FUNCTION f1; +# +# Using a user variable as a EXECUTE..USING out parameter +# +CREATE PROCEDURE p1(a OUT INT) +AS +BEGIN +a:= 10; +END; +/ +SET @a=1; +CALL p1(@a); +SELECT @a; +@a +10 +SET @a=2; +PREPARE stmt FROM 'CALL p1(?)'; +EXECUTE stmt USING @a; +SELECT @a; +@a +10 +DROP PROCEDURE p1; +# +# Using an SP variable as a EXECUTE..USING out parameter +# +CREATE PROCEDURE p1 (a OUT INT) +AS +BEGIN +a:=10; +END; +/ +CREATE PROCEDURE p2 (a OUT INT) +AS +BEGIN +PREPARE stmt FROM 'CALL p1(?)'; +EXECUTE stmt USING a; +END; +/ +SET @a= 1; +CALL p2(@a); +SELECT @a; +@a +10 +DROP PROCEDURE p2; +DROP PROCEDURE p1; +# +# Using a trigger field as a EXECUTE..USING out parameter +# +CREATE PROCEDURE p1 (a OUT INT) +AS +BEGIN +a:= 10; +END; +/ +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW CALL p1(:NEW.a); +INSERT INTO t1 VALUES (1); +SELECT * FROM t1; +a +10 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Testing re-prepare on a table metadata update between PREPARE and EXECUTE +# +CREATE TABLE t1 (a INT); +CREATE PROCEDURE p1(a IN INT) +AS +BEGIN +INSERT INTO t1 VALUES (a); +END; +/ +PREPARE stmt FROM 'CALL p1(?)'; +EXECUTE stmt USING 10; +SELECT * FROM t1; +a +10 +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW NEW.a:=NEW.a+1; +EXECUTE stmt USING 20; +SELECT * FROM t1; +a +10 +21 +DEALLOCATE PREPARE stmt; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# End of MDEV-10709 Expressions as parameters to Dynamic SQL +# +# +# MDEV-10585 EXECUTE IMMEDIATE statement +# +# +# Testing disallowed expressions in USING +# +EXECUTE IMMEDIATE 'SELECT :1 FROM DUAL' USING (SELECT 1); +ERROR 42000: EXECUTE..USING does not support subqueries or stored functions +CREATE FUNCTION f1() RETURN VARCHAR +AS +BEGIN +RETURN 'test'; +END; +$$ +EXECUTE IMMEDIATE 'SELECT ? FROM DUAL' USING f1(); +ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions +DROP FUNCTION f1; +# +# Testing simple expressions +# +EXECUTE IMMEDIATE 'SELECT :1 FROM DUAL' USING 10; +:1 +10 +# +# MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions +# +# +# Testing erroneous and diallowed prepare source +# +EXECUTE IMMEDIATE _latin1'SELECT 1 AS c FROM ' || _latin2 'DUAL'; +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat_operator_oracle' +PREPARE stmt FROM _latin1'SELECT 1 AS c FROM ' || _latin2 'DUAL'; +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat_operator_oracle' +EXECUTE IMMEDIATE (SELECT 'SELECT 1'); +ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions +PREPARE stmt FROM (SELECT 'SELECT 1'); +ERROR 42000: PREPARE..FROM does not support subqueries or stored functions +EXECUTE IMMEDIATE a; +ERROR 42S22: Unknown column 'a' in 'field list' +PREPARE stmt FROM a; +ERROR 42S22: Unknown column 'a' in 'field list' +EXECUTE IMMEDIATE NULL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1 +PREPARE stmt FROM NULL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1 +EXECUTE IMMEDIATE COALESCE(NULL); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1 +PREPARE stmt FROM COALESCE(NULL); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1 +CREATE FUNCTION f1() RETURN VARCHAR +AS +BEGIN +RETURN 't1'; +END; +$$ +EXECUTE IMMEDIATE f1(); +ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions +PREPARE stmt FROM f1(); +ERROR 42000: PREPARE..FROM does not support subqueries or stored functions +DROP FUNCTION f1; +# +# Testing user variables in prepare source +# +SET @table_name='DUAL'; +EXECUTE IMMEDIATE 'SELECT 1 AS a FROM ' || @table_name; +a +1 +PREPARE stmt FROM 'SELECT 1 AS a FROM ' || @table_name; +EXECUTE stmt; +a +1 +DEALLOCATE PREPARE stmt; +# +# Testing SP parameters and variables in prepare source +# +CREATE PROCEDURE p1(table_name VARCHAR) +AS +BEGIN +EXECUTE IMMEDIATE 'SELECT 1 AS c FROM '|| table_name; +END; +$$ +CALL p1('DUAL'); +c +1 +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +table_name VARCHAR(64):='DUAL'; +BEGIN +EXECUTE IMMEDIATE 'SELECT 1 AS c FROM ' || table_name; +END; +$$ +CALL p1(); +c +1 +DROP PROCEDURE p1; +# +# End of MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions +# +# +# MDEV-12846 sql_mode=ORACLE: using Oracle-style placeholders in direct query execution makes the server crash +# +SELECT ? FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? FROM DUAL' at line 1 +SELECT :a FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':a FROM DUAL' at line 1 +SELECT :1 FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':1 FROM DUAL' at line 1 +SELECT 1+? FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? FROM DUAL' at line 1 +SELECT 1+:a FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':a FROM DUAL' at line 1 +SELECT 1+:1 FROM DUAL; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':1 FROM DUAL' at line 1 diff --git a/mysql-test/suite/compat/oracle/r/rpl_mariadb_date.result b/mysql-test/suite/compat/oracle/r/rpl_mariadb_date.result new file mode 100644 index 00000000..55da2b74 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/rpl_mariadb_date.result @@ -0,0 +1,86 @@ +include/master-slave.inc +[connection master] +SET SQL_MODE=DEFAULT; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES (NULL); +INSERT INTO t1 VALUES ('2001-01-01'); +SET SQL_MODE= ORACLE; +CREATE TABLE t2 SELECT * FROM t1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a DATE) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES (NULL) +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Annotate_rows # # INSERT INTO t1 VALUES ('2001-01-01') +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE "t2" ( + "a" mariadb_schema.date DEFAULT NULL +) +master-bin.000001 # Annotate_rows # # CREATE TABLE t2 SELECT * FROM t1 +master-bin.000001 # Table_map # # table_id: # (test.t2) +master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +master-bin.000001 # Query # # COMMIT +SET SQL_MODE= DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SET SQL_MODE= ORACLE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mariadb_schema.date DEFAULT NULL +) +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE "t2" ( + "a" mariadb_schema.date DEFAULT NULL +) +connection slave; +SELECT * FROM t1; +a +NULL +2001-01-01 +SELECT * FROM t2; +a +NULL +2001-01-01 +SET SQL_MODE= DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SET SQL_MODE= ORACLE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" mariadb_schema.date DEFAULT NULL +) +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE "t2" ( + "a" mariadb_schema.date DEFAULT NULL +) +connection master; +DROP TABLE t1, t2; +include/rpl_end.inc diff --git a/mysql-test/suite/compat/oracle/r/rpl_sp_package.result b/mysql-test/suite/compat/oracle/r/rpl_sp_package.result new file mode 100644 index 00000000..4c499526 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/rpl_sp_package.result @@ -0,0 +1,195 @@ +include/master-slave.inc +[connection master] +connection master; +SET sql_mode=ORACLE; +CREATE PACKAGE pack AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pack AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +PROCEDURE p1 AS +BEGIN +SELECT f1(); +END; +END pack; +$$ +connection slave; +connection slave; +SELECT * FROM mysql.proc WHERE db='test' AND name='pack'; +db test +name pack +type PACKAGE +specific_name pack +language SQL +sql_data_access CONTAINS_SQL +is_deterministic NO +security_type DEFINER +param_list +returns +body AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +definer root@localhost +created # +modified # +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +comment +character_set_client latin1 +collation_connection latin1_swedish_ci +db_collation latin1_swedish_ci +body_utf8 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +aggregate NONE +db test +name pack +type PACKAGE BODY +specific_name pack +language SQL +sql_data_access CONTAINS_SQL +is_deterministic NO +security_type DEFINER +param_list +returns +body AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +PROCEDURE p1 AS +BEGIN +SELECT f1(); +END; +END +definer root@localhost +created # +modified # +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +comment +character_set_client latin1 +collation_connection latin1_swedish_ci +db_collation latin1_swedish_ci +body_utf8 AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +PROCEDURE p1 AS +BEGIN +SELECT f1(); +END; +END +aggregate NONE +SELECT * FROM mysql.proc WHERE db='test' AND name LIKE 'pack.%'; +SET @@sql_mode=ORACLE; +SELECT pack.f1(); +pack.f1() +10 +CALL pack.p1(); +f1() +10 +SET @@sql_mode=DEFAULT; +connection master; +DROP PACKAGE pack; +connection slave; +connection slave; +SELECT COUNT(*) FROM mysql.proc WHERE db='test' AND name='pack'; +COUNT(*) +0 +# +# Creating a package with a COMMENT +# +connection master; +CREATE PACKAGE p1 COMMENT 'package-p1-comment' AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 COMMENT 'package-body-p1-comment' AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +SELECT definer, name, security_type, type, `comment` FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type comment +root@localhost p1 DEFINER PACKAGE package-p1-comment +root@localhost p1 DEFINER PACKAGE BODY package-body-p1-comment +connection slave; +SELECT definer, name, security_type, type, `comment` FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type comment +root@localhost p1 DEFINER PACKAGE package-p1-comment +root@localhost p1 DEFINER PACKAGE BODY package-body-p1-comment +connection master; +DROP PACKAGE p1; +connection slave; +# +# Creating a package with a different DEFINER +# +connection master; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 DEFINER PACKAGE +xxx@localhost p1 DEFINER PACKAGE BODY +connection slave; +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 DEFINER PACKAGE +xxx@localhost p1 DEFINER PACKAGE BODY +connection master; +DROP PACKAGE p1; +connection slave; +# +# Creating a package with a different DEFINER + SQL SECURITY INVOKER +# +connection master; +CREATE DEFINER=xxx@localhost PACKAGE p1 SQL SECURITY INVOKER AS +PROCEDURE p1; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +Warnings: +Note 1449 The user specified as a definer ('xxx'@'localhost') does not exist +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 INVOKER PACKAGE +xxx@localhost p1 INVOKER PACKAGE BODY +connection slave; +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 INVOKER PACKAGE +xxx@localhost p1 INVOKER PACKAGE BODY +connection master; +DROP PACKAGE p1; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/compat/oracle/r/rpl_sp_package_variables.result b/mysql-test/suite/compat/oracle/r/rpl_sp_package_variables.result new file mode 100644 index 00000000..764686e4 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/rpl_sp_package_variables.result @@ -0,0 +1,38 @@ +include/master-slave.inc +[connection master] +connection master; +SET sql_mode=ORACLE; +# +# MDEV-13139 Package-wide variables in CREATE PACKAGE +# +connection master; +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +va INT:=10; +PROCEDURE p1 AS +BEGIN +INSERT INTO t1 VALUES (va); +END; +BEGIN +CREATE OR REPLACE TABLE t1 (a INT); +END; +$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT * FROM t1; +a +10 +10 +connection slave; +SELECT * FROM t1; +a +10 +10 +connection master; +DROP PACKAGE p1; +DROP TABLE t1; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/compat/oracle/r/sequence.result b/mysql-test/suite/compat/oracle/r/sequence.result new file mode 100644 index 00000000..dbbabc36 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sequence.result @@ -0,0 +1,77 @@ +SET sql_mode=ORACLE; +CREATE SEQUENCE s1; +SHOW CREATE SEQUENCE s1; +Table Create Table +s1 CREATE SEQUENCE "s1" start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle +SELECT s1.currval; +s1.currval +NULL +SELECT s1.nextval; +s1.nextval +1 +SELECT s1.nextval; +s1.nextval +2 +SELECT s1.nextval; +s1.nextval +3 +EXPLAIN EXTENDED SELECT s1.nextval; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select nextval("test"."s1") AS "s1.nextval" +SELECT nextval(s1); +nextval(s1) +4 +EXPLAIN EXTENDED SELECT s1.currval; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select lastval("test"."s1") AS "s1.currval" +SELECT lastval(s1); +lastval(s1) +4 +DROP SEQUENCE s1; +CREATE SEQUENCE s1; +CREATE VIEW v1 AS SELECT s1.nextval AS a; +SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1'; +VIEW_DEFINITION +select nextval(`test`.`s1`) AS `a` +SELECT * FROM v1; +a +1 +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select nextval("test"."s1") AS "a" latin1 latin1_swedish_ci +DROP VIEW v1; +DROP SEQUENCE s1; +CREATE SEQUENCE s1; +CREATE VIEW v1 AS SELECT s1.currval AS a; +SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME='v1'; +VIEW_DEFINITION +select lastval(`test`.`s1`) AS `a` +SELECT * FROM v1; +a +NULL +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW "v1" AS select lastval("test"."s1") AS "a" latin1 latin1_swedish_ci +DROP VIEW v1; +DROP SEQUENCE s1; +# +# MDEV-12533 sql_mode=ORACLE: Add support for database qualified sequence names in NEXTVAL and CURRVAL +# +CREATE SEQUENCE s1; +SELECT test.s1.nextval; +test.s1.nextval +1 +SELECT test.s1.currval; +test.s1.currval +1 +SELECT .s1.nextval; +.s1.nextval +2 +SELECT .s1.currval; +.s1.currval +2 +DROP SEQUENCE s1; diff --git a/mysql-test/suite/compat/oracle/r/sp-anchor-row-type-table.result b/mysql-test/suite/compat/oracle/r/sp-anchor-row-type-table.result new file mode 100644 index 00000000..b8780421 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-anchor-row-type-table.result @@ -0,0 +1,131 @@ +SET sql_mode=ORACLE; +# +# MDEV-13581 ROW TYPE OF t1 and t1%ROWTYPE for routine parameters +# +CREATE TABLE t1 (a INT, b TEXT, c ENUM('a','b','c')); +CREATE PROCEDURE p1 (a t1%ROWTYPE) AS +BEGIN +CREATE TABLE t2 AS SELECT a.a AS a, a.b AS b, a.c AS c; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +CREATE PROCEDURE p2 AS +a t1%ROWTYPE; +BEGIN +CALL p1(a); +END; +$$ +CALL p2(); +Table Create Table +t2 CREATE TABLE "t2" ( + "a" int(11) DEFAULT NULL, + "b" text DEFAULT NULL, + "c" varchar(1) DEFAULT NULL +) +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT, b TEXT); +CREATE PROCEDURE p1 (a OUT t1%ROWTYPE) AS +BEGIN +SET a.a=10; +SET a.b='text'; +END; +$$ +CREATE PROCEDURE p2 AS +a t1%ROWTYPE; +BEGIN +CALL p1(a); +SELECT a.a, a.b; +END; +$$ +CREATE FUNCTION f1(a t1%ROWTYPE) RETURN TEXT AS +BEGIN +RETURN CONCAT(a.a, ' ', a.b); +END; +$$ +CREATE FUNCTION f2 RETURN TEXT AS +a t1%ROWTYPE; +BEGIN +CALL p1(a); +RETURN f1(a); +END; +$$ +CALL p2(); +a.a a.b +10 text +SELECT f2(); +f2() +10 text +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP FUNCTION f2; +DROP FUNCTION f1; +DROP TABLE t1; +CREATE DATABASE db1; +CREATE TABLE db1.t1 (a INT, b TEXT); +CREATE PROCEDURE p1 (a OUT db1.t1%ROWTYPE) AS +BEGIN +SET a.a=10; +SET a.b='text'; +END; +$$ +CREATE PROCEDURE p2 AS +a db1.t1%ROWTYPE; +BEGIN +CALL p1(a); +SELECT a.a, a.b; +END; +$$ +CREATE FUNCTION f1(a db1.t1%ROWTYPE) RETURN TEXT AS +BEGIN +RETURN CONCAT(a.a, ' ', a.b); +END; +$$ +CREATE FUNCTION f2() RETURN TEXT AS +a db1.t1%ROWTYPE; +BEGIN +CALL p1(a); +RETURN f1(a); +END; +$$ +CALL p2(); +a.a a.b +10 text +SELECT f2(); +f2() +10 text +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP FUNCTION f2; +DROP FUNCTION f1; +DROP DATABASE db1; +# +# MDEV-14139 Anchored data types for variables +# +CREATE TABLE t1 (int11 INT, text0 TEXT); +DECLARE +row1 t1%ROWTYPE; +a_row1 row1%TYPE; +aa_row1 a_row1%TYPE; +BEGIN +CREATE TABLE t2 AS SELECT a_row1.int11 AS int11, a_row1.text0 AS text0; +SHOW CREATE TABLE t2; +DROP TABLE t2; +CREATE TABLE t2 AS SELECT aa_row1.int11 AS int11, aa_row1.text0 AS text0; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +Table Create Table +t2 CREATE TABLE "t2" ( + "int11" int(11) DEFAULT NULL, + "text0" text DEFAULT NULL +) +Table Create Table +t2 CREATE TABLE "t2" ( + "int11" int(11) DEFAULT NULL, + "text0" text DEFAULT NULL +) +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/sp-anonymous.result b/mysql-test/suite/compat/oracle/r/sp-anonymous.result new file mode 100644 index 00000000..26bce0f4 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-anonymous.result @@ -0,0 +1,220 @@ +SET sql_mode=ORACLE; +# +# MDEV-10655 Anonymous blocks +# +# Testing BEGIN NOT ATOMIC with no declarations +BEGIN NOT ATOMIC +SELECT 1 AS a; +END +/ +a +1 +# Testing BEGIN NOT ATOMIC with declarations +# DECLARE starts a new block and thus must be followed by BEGIN .. END +BEGIN NOT ATOMIC +DECLARE +i INT DEFAULT 5; +x INT DEFAULT 10; +BEGIN +<
SET = FUNCTION(a IN) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a IN INT) RETURN INT +AS +BEGIN +RETURN a * 10; +END; +END; +$$ +set @a = 5; +UPDATE Persons SET Age = pkg2.func(@a) WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Call function from UPDATE query +# UPDATE
SET = FUNCTION(a OUT) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +a := 5; +RETURN 80; +END; +END; +$$ +set @a = 0; +UPDATE Persons SET Age = pkg2.func(@a) WHERE ID = 1; +ERROR HY000: OUT or INOUT argument 1 for function pkg2.func is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Call function from INSERT query +# INSERT INTO
SELECT , , FUNCTION(a IN) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a IN INT) RETURN INT +AS +BEGIN +RETURN a * 10; +END; +END; +$$ +set @a = 4; +INSERT INTO Persons SELECT 4, 'DDD', PKG2.func(@a); +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Call function from INSERT query +# INSERT INTO
SELECT , , FUNCTION(a OUT) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +a := 45; +RETURN 40; +END; +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +set @a = 0; +INSERT INTO Persons SELECT 5, 'EEE', PKG2.func(@a); +ERROR HY000: OUT or INOUT argument 1 for function PKG2.func is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Call function from DELETE query +# DELETE FROM
WHERE = FUNCTION(a IN) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a IN INT) RETURN INT +AS +BEGIN +RETURN a; +END; +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 4; +DELETE FROM Persons WHERE ID = PKG2.func(@a); +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Call function from DELETE query +# DELETE FROM
WHERE = FUNCTION(a OUT) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +a := 40; +RETURN 4; +END; +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 0; +DELETE FROM Persons WHERE ID = PKG2.func(@a); +ERROR HY000: OUT or INOUT argument 1 for function PKG2.func is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# SELECT query inside function +# FUNCTION(a IN) > SELECT … FROM
+# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +c INT; +BEGIN +SELECT AGE INTO c FROM Persons WHERE ID = a; +RETURN c; +END; +END; +$$ +set @a = 3; +select pkg2.func_main(@a); +pkg2.func_main(@a) +30 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# SELECT query inside function +# FUNCTION(a OUT) > SELECT … FROM
+# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a OUT INT) RETURN INT +AS +BEGIN +SELECT AGE INTO a FROM Persons WHERE ID = 3; +RETURN 0; +END; +END; +$$ +set @a = 0; +select pkg2.func_main(@a); +ERROR HY000: OUT or INOUT argument 1 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# SELECT query inside function +# FUNCTION(a INOUT) > SELECT … FROM
+# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a INOUT INT) RETURN INT +AS +BEGIN +SELECT AGE INTO a FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +set @a = 1; +select pkg2.func_main(@a); +ERROR HY000: OUT or INOUT argument 1 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# SELECT query inside function +# FUNCTION(a IN) > FUNCTION(a IN, b OUT) > SELECT … FROM
+# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +b INT; +res INT; +BEGIN +res := func_sub(a, b); +RETURN b; +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +set @a = 2; +select pkg2.func_main(@a); +pkg2.func_main(@a) +20 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# UPDATE query inside function +# FUNCTION(a IN) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +c INT; +BEGIN +UPDATE Persons SET AGE = 50 WHERE ID = a; +SELECT AGE INTO c FROM Persons WHERE ID = a; +RETURN c; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +set @a = 5; +select pkg2.func_main(@a); +pkg2.func_main(@a) +50 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 50 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# UPDATE query inside function +# FUNCTION(a IN, b OUT) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +UPDATE Persons SET AGE = 60 WHERE ID = a; +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +set @a = 5; +set @b = 0; +select pkg2.func_main(@a, @b); +ERROR HY000: OUT or INOUT argument 2 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# UPDATE query inside function +# FUNCTION(a IN, b INOUT) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT +AS +BEGIN +UPDATE Persons SET AGE = 60 WHERE ID = a; +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +set @a = 5; +set @b = 0; +select pkg2.func_main(@a, @b); +ERROR HY000: OUT or INOUT argument 2 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# UPDATE query inside function +# FUNCTION(a IN) > FUNCTION(a IN, b OUT) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 80); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +b INT; +res INT; +BEGIN +res := func_sub(a, b); +RETURN b; +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +UPDATE Persons SET AGE = 10 WHERE ID = a; +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 80 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +set @a = 1; +select pkg2.func_main(@a); +pkg2.func_main(@a) +10 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# INSERT query inside function +# FUNCTION(a IN) > INSERT INTO
VALUES … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 50); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +b INT; +BEGIN +INSERT INTO Persons VALUE (a, 'FFF', 60); +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN b; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 50 +set @a = 6; +select pkg2.func_main(@a); +pkg2.func_main(@a) +60 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 50 +6 FFF 60 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# INSERT query inside function +# FUNCTION(a IN, b OUT) > INSERT INTO
VALUES … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 50); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +INSERT INTO Persons VALUE (a, 'FFF', 60); +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 50 +set @a = 6; +set @b = 0; +select pkg2.func_main(@a, @b); +ERROR HY000: OUT or INOUT argument 2 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# INSERT query inside function +# FUNCTION(a IN, b INOUT) > INSERT INTO
VALUES … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT +AS +BEGIN +INSERT INTO Persons VALUE (a, 'FFF', 60); +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +set @a = 6; +set @b = 0; +select pkg2.func_main(@a, @b); +ERROR HY000: OUT or INOUT argument 2 for function pkg2.func_main is not allowed here +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# INSERT query inside function +# FUNCTION(a IN) > FUNCTION(a IN, b OUT) > INSERT INTO
VALUES … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func_main(a IN INT) RETURN INT +AS +b INT; +res INT; +BEGIN +res := func_sub(a, b); +RETURN b; +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +INSERT INTO Persons VALUE (a, 'FFF', 60); +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +set @a = 6; +select pkg2.func_main(@a); +pkg2.func_main(@a) +60 +select * from Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 EEE 40 +6 FFF 60 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(IN) > SELECT FROM
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +BEGIN +b := func_sub(a); +END; +FUNCTION func_sub(a IN INT) RETURN INT +AS +b INT; +BEGIN +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN b; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 2; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +@b +20 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(OUT) > SELECT FROM
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +res INT; +BEGIN +res := func_sub(a, b); +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +SELECT AGE INTO b FROM Persons WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 1; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +@b +50 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(INOUT) > SELECT FROM
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +c INT; +res INT; +BEGIN +c := 5; +res := func_sub(a, c); +b := c; +END; +FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT +AS +res INT; +BEGIN +SELECT AGE INTO res FROM Persons WHERE ID = a; +c := c * 100; +RETURN res; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 2; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +@b +500 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(IN) > INSESRT INTO
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +BEGIN +b := func_sub(a); +END; +FUNCTION func_sub(a IN INT) RETURN INT +AS +BEGIN +INSERT INTO Persons VALUE (a, 'FFF', 50); +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +set @a = 5; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(OUT) > INSESRT INTO
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +res INT; +BEGIN +res := func_sub(a, b); +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +INSERT INTO Persons VALUE (a, 'GGG', 60); +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +set @a = 6; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +6 GGG 60 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(INOUT) > INSESRT INTO
… +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); +INSERT INTO Persons VALUES (6, 'GGG', 60); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +c INT; +res INT; +BEGIN +c := 5; +res := func_sub(a, c); +b := c; +END; +FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT +AS +res INT; +BEGIN +INSERT INTO Persons VALUE (a, 'HHH', 70); +c := c * 100; +RETURN res; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +6 GGG 60 +set @a = 7; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +6 GGG 60 +7 HHH 70 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(IN) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); +INSERT INTO Persons VALUES (6, 'GGG', 60); +INSERT INTO Persons VALUES (7, 'HHH', 70); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +BEGIN +b := func_sub(a); +END; +FUNCTION func_sub(a IN INT) RETURN INT +AS +BEGIN +UPDATE Persons SET AGE = 100 WHERE ID = a; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 50 +6 GGG 60 +7 HHH 70 +set @a = 5; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 100 +6 GGG 60 +7 HHH 70 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 100); +INSERT INTO Persons VALUES (6, 'GGG', 60); +INSERT INTO Persons VALUES (7, 'HHH', 70); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +res INT; +BEGIN +res := func_sub(a, b); +END; +FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT +AS +BEGIN +UPDATE Persons SET AGE = 100 WHERE ID = a; +b := 1; +RETURN 0; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 100 +6 GGG 60 +7 HHH 70 +set @a = 6; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 100 +6 GGG 100 +7 HHH 70 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# PROCEDURE > FUNCTION > SQL query +# PROCEDURE(OUT) > FUNCTION(INOUT) > UPDATE
SET … +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 100); +INSERT INTO Persons VALUES (6, 'GGG', 100); +INSERT INTO Persons VALUES (7, 'HHH', 70); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT); +FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc_main(a IN INT, b OUT INT) +AS +c INT; +res INT; +BEGIN +c := 5; +res := func_sub(a, c); +b := c; +END; +FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT +AS +res INT; +BEGIN +UPDATE Persons SET AGE = 100 WHERE ID = a; +c := c * 100; +RETURN res; +END; +END; +$$ +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 100 +6 GGG 100 +7 HHH 70 +set @a = 7; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +4 DDD 40 +5 FFF 100 +6 GGG 100 +7 HHH 100 +DROP TABLE Persons; +DROP PACKAGE pkg2; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 20 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 20 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(IN) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a IN INT) RETURN INT +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE +a INT; +res INT; +BEGIN +a := 10; +res := 0; +res := pkg2.func(a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 30 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 30 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(OUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 40); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +a := 100; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE +a INT; +res INT; +BEGIN +a := 10; +res := 0; +res := pkg2.func(a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 40 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(INOUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +FUNCTION func(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +FUNCTION func(a INOUT INT) RETURN INT +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +a := 100; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE +a INT; +res INT; +BEGIN +a := 10; +res := 0; +res := pkg2.func(a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 60 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 60 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(IN) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a IN INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a IN INT) +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 30 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 30 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a OUT INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a OUT INT) +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(INOUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a INOUT INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a INOUT INT) +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +a := 100; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +set @a = 2; +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 50 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(IN) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a OUT INT); +FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a OUT INT) +AS +res INT; +BEGIN +a := 100; +res := func(a); +END; +FUNCTION func(a IN INT) RETURN INT +AS +BEGIN +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 60 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 60 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a OUT INT); +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a OUT INT) +AS +res INT; +BEGIN +a := 100; +res := func(a); +END; +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +a := 200; +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 80 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 80 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(INOUT) > UPDATE TABLE2 +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a OUT INT); +FUNCTION func(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a OUT INT) +AS +res INT; +BEGIN +a := 100; +res := func(a); +END; +FUNCTION func(a INOUT INT) RETURN INT +AS +BEGIN +a := 200; +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 90 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 90 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +1 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Trigger +# TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE TABLE2 with OUT argument (to check if OUT is returning by reference) +# +CREATE TABLE Persons ( +ID int, +Name varchar(255), +Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +CREATE TABLE PersonsLog ( +UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); +CREATE OR REPLACE PACKAGE pkg2 +AS +PROCEDURE proc(a OUT INT); +FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS +PROCEDURE proc(a OUT INT) +AS +res INT; +BEGIN +res := func(a); +UPDATE PersonsLog SET UpdateCount = a; +END; +FUNCTION func(a OUT INT) RETURN INT +AS +BEGIN +a := 111; +UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +RETURN 0; +END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN +call pkg2.proc(@a); +END; +$$ +SELECT * FROM Persons; +ID Name Age +1 AAA 10 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +0 +UPDATE Persons SET Age = 80 WHERE ID = 1; +SELECT * FROM Persons; +ID Name Age +1 AAA 80 +2 BBB 20 +3 CCC 30 +SELECT * FROM PersonsLog; +UpdateCount +111 +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; +# +# Package BODY variables as OUT parameters +# +CREATE PACKAGE pkg1 AS +FUNCTION f1(b IN OUT INT) RETURN INT; +FUNCTION show_private_variables() RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +pa INT:= 0; +pb INT:= 10; +FUNCTION f1(b IN OUT INT) RETURN INT AS +BEGIN +b:= b + 100; +RETURN 500+b-100; +END; +FUNCTION show_private_variables() RETURN TEXT AS +BEGIN +RETURN 'Private variables: pa=' || pa || ' pb=' || pb; +END; +BEGIN +SET pa=f1(pb); +END; +$$ +SELECT pkg1.show_private_variables(); +pkg1.show_private_variables() +Private variables: pa=510 pb=110 +DROP PACKAGE pkg1; diff --git a/mysql-test/suite/compat/oracle/r/sp-memory-leak.result b/mysql-test/suite/compat/oracle/r/sp-memory-leak.result new file mode 100644 index 00000000..109a9f84 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-memory-leak.result @@ -0,0 +1,27 @@ +# +# Start of 10.5 tests +# +# +# MDEV-26186 280 Bytes lost in mysys/array.c, mysys/hash.c, sql/sp.cc, sql/sp.cc, sql/item_create.cc, sql/item_create.cc, sql/sql_yacc.yy:10748 when using oracle sql_mode +# +SET sql_mode= 'oracle'; +BEGIN CONTINUE WHEN f0(); +ERROR 42000: CONTINUE with no matching label: +SET sql_mode= 'oracle'; +BEGIN CONTINUE label WHEN f0(); +ERROR 42000: CONTINUE with no matching label: label +SET sql_mode= 'oracle'; +BEGIN EXIT WHEN f0(); +ERROR 42000: EXIT with no matching label: +SET sql_mode= 'oracle'; +BEGIN EXIT label WHEN f0(); +ERROR 42000: EXIT with no matching label: label +SET sql_mode= 'oracle'; +WHILE f(8)<1 DO SELECT 1;; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DO SELECT 1' at line 1 +SET sql_mode= 'oracle'; +BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f0(); +ERROR 42000: RETURN is only allowed in a FUNCTION +# +# End of 10.5 tests +# diff --git a/mysql-test/suite/compat/oracle/r/sp-package-code.result b/mysql-test/suite/compat/oracle/r/sp-package-code.result new file mode 100644 index 00000000..0dea72db --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-code.result @@ -0,0 +1,245 @@ +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +PROCEDURE p2show; +PROCEDURE p2public; +FUNCTION f2public RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +a INT:=10; +PROCEDURE p1 AS +b INT:=20; +BEGIN +b:=a; +b:=a+1; +a:=b; +a:=b+1; +a:=a+1; +SET @a:=@a+2; +SELECT f1() FROM DUAL; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN a; +END; +PROCEDURE p2private AS +BEGIN +SELECT 'This is p2private'; +END; +PROCEDURE p2public AS +BEGIN +SELECT 'This is p2public'; +END; +FUNCTION f2private RETURN TEXT AS +BEGIN +RETURN 'This is f2private'; +END; +FUNCTION f2public RETURN TEXT AS +BEGIN +RETURN 'This is f2public'; +END; +PROCEDURE p2show AS +BEGIN +SHOW FUNCTION CODE f2public; +SHOW FUNCTION CODE f2private; +SHOW PROCEDURE CODE p2public; +SHOW PROCEDURE CODE p2private; +SHOW PROCEDURE CODE p2show; +END; +BEGIN +a:=a+1; +DECLARE +b INT; +BEGIN +b:=a; +b:=a+1; +a:=b; +a:=b+1; +END; +END; +$$ +SHOW PROCEDURE CODE pkg1.p1; +Pos Instruction +0 set b@0 20 +1 set b@0 PACKAGE_BODY.a@0 +2 set b@0 PACKAGE_BODY.a@0 + 1 +3 set PACKAGE_BODY.a@0 b@0 +4 set PACKAGE_BODY.a@0 b@0 + 1 +5 set PACKAGE_BODY.a@0 PACKAGE_BODY.a@0 + 1 +6 stmt 31 "SET @a:=@a+2" +7 stmt 0 "SELECT f1() FROM DUAL" +SHOW FUNCTION CODE pkg1.f1; +Pos Instruction +0 freturn int PACKAGE_BODY.a@0 +SHOW PACKAGE BODY CODE pkg1; +Pos Instruction +0 set a@0 10 +1 set a@0 a@0 + 1 +2 set b@1 NULL +3 set b@1 a@0 +4 set b@1 a@0 + 1 +5 set a@0 b@1 +6 set a@0 b@1 + 1 +7 jump 11 +CALL pkg1.p2show; +Pos Instruction +0 freturn blob 'This is f2public' +Pos Instruction +0 freturn blob 'This is f2private' +Pos Instruction +0 stmt 0 "SELECT 'This is p2public'" +Pos Instruction +0 stmt 0 "SELECT 'This is p2private'" +Pos Instruction +0 stmt 110 "SHOW FUNCTION CODE f2public" +1 stmt 110 "SHOW FUNCTION CODE f2private" +2 stmt 109 "SHOW PROCEDURE CODE p2public" +3 stmt 109 "SHOW PROCEDURE CODE p2private" +4 stmt 109 "SHOW PROCEDURE CODE p2show" +DROP PACKAGE pkg1; +CREATE TABLE t1 (a INT); +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +a t1.a%TYPE:=10; +PROCEDURE p1 AS +b t1.a%TYPE:=20; +BEGIN +b:=a; +b:=a+1; +b:=b+1; +a:=b; +a:=b+1; +a:=a+1; +END; +BEGIN +a:=a+1; +DECLARE +b t1.a%TYPE; +BEGIN +b:=a; +b:=a+1; +a:=b; +a:=b+1; +END; +END; +$$ +SHOW PROCEDURE CODE pkg1.p1; +Pos Instruction +0 set b@0 20 +1 set b@0 PACKAGE_BODY.a@0 +2 set b@0 PACKAGE_BODY.a@0 + 1 +3 set b@0 b@0 + 1 +4 set PACKAGE_BODY.a@0 b@0 +5 set PACKAGE_BODY.a@0 b@0 + 1 +6 set PACKAGE_BODY.a@0 PACKAGE_BODY.a@0 + 1 +SHOW PACKAGE BODY CODE pkg1; +Pos Instruction +0 set a@0 10 +1 set a@0 a@0 + 1 +2 set b@1 NULL +3 set b@1 a@0 +4 set b@1 a@0 + 1 +5 set a@0 b@1 +6 set a@0 b@1 + 1 +7 jump 11 +DROP PACKAGE pkg1; +DROP TABLE t1; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +a ROW(a INT,b TEXT):=ROW(10,'x10'); +PROCEDURE p1 AS +b ROW(a INT,b TEXT):=ROW(20,'x20'); +BEGIN +b:=a; +a:=b; +b.a:=a.a+1; +a.a:=b.a+1; +a.a:=a.a+1; +END; +BEGIN +a.a:=a.a+1; +DECLARE +b ROW(a INT,b TEXT):=ROW(30,'x30'); +BEGIN +b:=a; +b.a:=a.a+1; +a:=b; +a.a:=b.a+1; +END; +END; +$$ +SHOW PROCEDURE CODE pkg1.p1; +Pos Instruction +0 set b@0 (20,'x20') +1 set b@0 PACKAGE_BODY.a@0 +2 set PACKAGE_BODY.a@0 b@0 +3 set b.a@0[0] PACKAGE_BODY.a.a@0[0] + 1 +4 set PACKAGE_BODY.a.a@0[0] b.a@0[0] + 1 +5 set PACKAGE_BODY.a.a@0[0] PACKAGE_BODY.a.a@0[0] + 1 +SHOW PACKAGE BODY CODE pkg1; +Pos Instruction +0 set a@0 (10,'x10') +1 set a.a@0[0] a.a@0[0] + 1 +2 set b@1 (30,'x30') +3 set b@1 a@0 +4 set b.a@1[0] a.a@0[0] + 1 +5 set a@0 b@1 +6 set a.a@0[0] b.a@1[0] + 1 +7 jump 11 +DROP PACKAGE pkg1; +CREATE TABLE t1 (a INT, b TEXT); +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +a t1%ROWTYPE:=ROW(10,'x10'); +PROCEDURE p1 AS +b t1%ROWTYPE:=ROW(20,'x20'); +BEGIN +b:=a; +a:=b; +b.a:=a.a+1; +a.a:=b.a+1; +a.a:=a.a+1; +END; +BEGIN +a.a:=a.a+1; +DECLARE +b t1%ROWTYPE:=ROW(30,'x30'); +BEGIN +b:=a; +b.a:=a.a+1; +a:=b; +a.a:=b.a+1; +END; +END; +$$ +SHOW PROCEDURE CODE pkg1.p1; +Pos Instruction +0 set b@0 (20,'x20') +1 set b@0 PACKAGE_BODY.a@0 +2 set PACKAGE_BODY.a@0 b@0 +3 set b.a@0["a"] PACKAGE_BODY.a.a@0["a"] + 1 +4 set PACKAGE_BODY.a.a@0["a"] b.a@0["a"] + 1 +5 set PACKAGE_BODY.a.a@0["a"] PACKAGE_BODY.a.a@0["a"] + 1 +SHOW PACKAGE BODY CODE pkg1; +Pos Instruction +0 set a@0 (10,'x10') +1 set a.a@0["a"] a.a@0["a"] + 1 +2 set b@1 (30,'x30') +3 set b@1 a@0 +4 set b.a@1["a"] a.a@0["a"] + 1 +5 set a@0 b@1 +6 set a.a@0["a"] b.a@1["a"] + 1 +7 jump 11 +DROP PACKAGE pkg1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-db.result b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-db.result new file mode 100644 index 00000000..95f45c25 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-db.result @@ -0,0 +1,43 @@ +# +# MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +# +SET @object_type='db'; +# +# Start of sp-package-concurrent-dml.inc +# +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p2 AS +BEGIN +SELECT 'This is p2' AS msg; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +DO GET_LOCK('mdev15070',120); +CALL p2(); +DO RELEASE_LOCK('mdev15070'); +END; +END; +$$ +connect con2,localhost,root; +connection con2; +DO GET_LOCK('mdev15070', 120); +connection default; +CALL pkg1.p1; +connection con2; +CREATE DATABASE test1; +CREATE FUNCTION test1.f1() RETURNS INT RETURN 10; +DROP DATABASE test1; +DO RELEASE_LOCK('mdev15070'); +disconnect con2; +connection default; +msg +This is p1 +msg +This is p2 +DROP PACKAGE IF EXISTS pkg1; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-package.result b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-package.result new file mode 100644 index 00000000..eb7d38a8 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-package.result @@ -0,0 +1,96 @@ +# +# MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +# +SET @object_type='package_replace_pkg1'; +# +# Start of sp-package-concurrent-dml.inc +# +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p2 AS +BEGIN +SELECT 'This is p2' AS msg; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +DO GET_LOCK('mdev15070',120); +CALL p2(); +DO RELEASE_LOCK('mdev15070'); +END; +END; +$$ +connect con2,localhost,root; +connection con2; +DO GET_LOCK('mdev15070', 120); +connection default; +CALL pkg1.p1; +connection con2; +SET sql_mode=ORACLE; +CREATE OR REPLACE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +DROP PACKAGE pkg1; +DO RELEASE_LOCK('mdev15070'); +disconnect con2; +connection default; +msg +This is p1 +msg +This is p2 +DROP PACKAGE IF EXISTS pkg1; +Warnings: +Note 1305 PACKAGE test.pkg1 does not exist +SET @object_type='package_body_replace_pkg1'; +# +# Start of sp-package-concurrent-dml.inc +# +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p2 AS +BEGIN +SELECT 'This is p2' AS msg; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +DO GET_LOCK('mdev15070',120); +CALL p2(); +DO RELEASE_LOCK('mdev15070'); +END; +END; +$$ +connect con2,localhost,root; +connection con2; +DO GET_LOCK('mdev15070', 120); +connection default; +CALL pkg1.p1; +connection con2; +SET sql_mode=ORACLE; +CREATE OR REPLACE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1 version 2' AS msg; +END; +END; +$$ +DROP PACKAGE pkg1; +DO RELEASE_LOCK('mdev15070'); +disconnect con2; +connection default; +msg +This is p1 +msg +This is p2 +DROP PACKAGE IF EXISTS pkg1; +Warnings: +Note 1305 PACKAGE test.pkg1 does not exist diff --git a/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-trigger.result b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-trigger.result new file mode 100644 index 00000000..8181714f --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-trigger.result @@ -0,0 +1,44 @@ +# +# MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +# +SET @object_type='trigger'; +# +# Start of sp-package-concurrent-dml.inc +# +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p2 AS +BEGIN +SELECT 'This is p2' AS msg; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +DO GET_LOCK('mdev15070',120); +CALL p2(); +DO RELEASE_LOCK('mdev15070'); +END; +END; +$$ +connect con2,localhost,root; +connection con2; +DO GET_LOCK('mdev15070', 120); +connection default; +CALL pkg1.p1; +connection con2; +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=1; +DROP TRIGGER tr1; +DROP TABLE t1; +DO RELEASE_LOCK('mdev15070'); +disconnect con2; +connection default; +msg +This is p1 +msg +This is p2 +DROP PACKAGE IF EXISTS pkg1; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-view.result b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-view.result new file mode 100644 index 00000000..b0ceec60 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-concurrent-dml-view.result @@ -0,0 +1,42 @@ +# +# MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +# +SET @object_type='view'; +# +# Start of sp-package-concurrent-dml.inc +# +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p2 AS +BEGIN +SELECT 'This is p2' AS msg; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +DO GET_LOCK('mdev15070',120); +CALL p2(); +DO RELEASE_LOCK('mdev15070'); +END; +END; +$$ +connect con2,localhost,root; +connection con2; +DO GET_LOCK('mdev15070', 120); +connection default; +CALL pkg1.p1; +connection con2; +CREATE VIEW v1 AS SELECT 1 AS c; +DROP VIEW v1; +DO RELEASE_LOCK('mdev15070'); +disconnect con2; +connection default; +msg +This is p1 +msg +This is p2 +DROP PACKAGE IF EXISTS pkg1; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-i_s.result b/mysql-test/suite/compat/oracle/r/sp-package-i_s.result new file mode 100644 index 00000000..2f4201f7 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-i_s.result @@ -0,0 +1,75 @@ +# +# Start of 10.5 tests +# +# +# MDEV-30662 SQL/PL package body does not appear in I_S.ROUTINES.ROUTINE_DEFINITION +# +SET sql_mode=ORACLE; +CREATE OR REPLACE PACKAGE pkg1 AS +FUNCTION f1() RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +FUNCTION f1() RETURN INT AS +BEGIN +RETURN 1; +END; +END; +$$ +SELECT routine_name, routine_type, routine_definition +FROM information_schema.routines +WHERE routine_type LIKE 'PACKAGE%' +ORDER BY routine_type; +routine_name pkg1 +routine_type PACKAGE +routine_definition AS +FUNCTION f1() RETURN INT; +END +routine_name pkg1 +routine_type PACKAGE BODY +routine_definition AS +FUNCTION f1() RETURN INT AS +BEGIN +RETURN 1; +END; +END +DROP PACKAGE pkg1; +SET sql_mode=ORACLE; +CREATE OR REPLACE PACKAGE pkg1 AS +FUNCTION f1() RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +FUNCTION f1() RETURN INT AS +BEGIN +RETURN 1; +END; +BEGIN +SET @a=10; +SET @a=f1(); +END; +$$ +SELECT routine_name, routine_type, routine_definition +FROM information_schema.routines +WHERE routine_type LIKE 'PACKAGE%' +ORDER BY routine_type; +routine_name pkg1 +routine_type PACKAGE +routine_definition AS +FUNCTION f1() RETURN INT; +END +routine_name pkg1 +routine_type PACKAGE BODY +routine_definition AS +FUNCTION f1() RETURN INT AS +BEGIN +RETURN 1; +END; +BEGIN +SET @a=10; +SET @a=f1(); +END +DROP PACKAGE pkg1; +# +# End of 10.5 tests +# diff --git a/mysql-test/suite/compat/oracle/r/sp-package-innodb.result b/mysql-test/suite/compat/oracle/r/sp-package-innodb.result new file mode 100644 index 00000000..0ac357df --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-innodb.result @@ -0,0 +1,77 @@ +SET default_storage_engine=InnoDB; +SET sql_mode=ORACLE; +CREATE TABLE t1 (a INT, routine TEXT); +SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES +WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'; +ENGINE +InnoDB +INSERT INTO t1 VALUES (10,'none'); +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +a INT; +PROCEDURE p1 AS +BEGIN +a:=a+1; +INSERT INTO t1 VALUES (a,'p1'); +END; +BEGIN +SELECT MAX(t1.a) FROM t1 INTO a; +a:=a+1; +INSERT INTO t1 VALUES (a,'pkg1 initialization'); +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +a routine +10 none +11 pkg1 initialization +12 p1 +DELETE FROM t1; +# sp-cache-invalidate +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +a routine +NULL pkg1 initialization +NULL p1 +ROLLBACK; +SELECT * FROM t1 ORDER BY a; +a routine +DELETE FROM t1; +# sp-cache-invalidate +INSERT INTO t1 VALUES (20,'none'); +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +a routine +20 none +21 pkg1 initialization +22 p1 +COMMIT; +SELECT * FROM t1 ORDER BY a; +a routine +20 none +21 pkg1 initialization +22 p1 +DELETE FROM t1; +# sp-cache-invalidate +INSERT INTO t1 VALUES (20,'none'); +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +a routine +20 none +21 pkg1 initialization +22 p1 +ROLLBACK; +SELECT * FROM t1 ORDER BY a; +a routine +20 none +DELETE FROM t1; +DROP PACKAGE pkg1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-mdl.result b/mysql-test/suite/compat/oracle/r/sp-package-mdl.result new file mode 100644 index 00000000..bb46341f --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-mdl.result @@ -0,0 +1,80 @@ +SET sql_mode=ORACLE; +DO GET_LOCK('lock',300); +connect conn1,localhost,root,,; +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +DO GET_LOCK('lock',300); +END; +FUNCTION f1 RETURN INT AS +BEGIN +CALL p1; +RETURN 1; +END; +END; +$$ +SELECT pkg1.f1(); +connection default; +connect conn2,localhost,root,,; +SET sql_mode=ORACLE; +DROP PACKAGE pkg1; +connection default; +SELECT ID-CONNECTION_ID() AS CONN,INFO,STATE,LOCK_MODE,LOCK_TYPE,TABLE_NAME +FROM INFORMATION_SCHEMA.PROCESSLIST +LEFT JOIN INFORMATION_SCHEMA.METADATA_LOCK_INFO +ON (ID=THREAD_ID) +ORDER BY ID,TABLE_NAME,LOCK_MODE,LOCK_TYPE; +CONN 0 +INFO SELECT ID-CONNECTION_ID() AS CONN,INFO,STATE,LOCK_MODE,LOCK_TYPE,TABLE_NAME +FROM INFORMATION_SCHEMA.PROCESSLIST +LEFT JOIN INFORMATION_SCHEMA.METADATA_LOCK_INFO +ON (ID=THREAD_ID) +ORDER BY ID,TABLE_NAME,LOCK_MODE,LOCK_TYPE +STATE Filling schema table +LOCK_MODE MDL_SHARED_NO_WRITE +LOCK_TYPE User lock +TABLE_NAME +CONN 1 +INFO DO GET_LOCK('lock',300) +STATE User lock +LOCK_MODE MDL_SHARED +LOCK_TYPE Stored package body metadata lock +TABLE_NAME pkg1 +CONN 1 +INFO DO GET_LOCK('lock',300) +STATE User lock +LOCK_MODE MDL_SHARED +LOCK_TYPE Stored function metadata lock +TABLE_NAME pkg1.f1 +CONN 1 +INFO DO GET_LOCK('lock',300) +STATE User lock +LOCK_MODE MDL_SHARED +LOCK_TYPE Stored procedure metadata lock +TABLE_NAME pkg1.p1 +CONN 2 +INFO DROP PACKAGE pkg1 +STATE Waiting for stored package body metadata lock +LOCK_MODE MDL_BACKUP_DDL +LOCK_TYPE Backup lock +TABLE_NAME +CONN 2 +INFO DROP PACKAGE pkg1 +STATE Waiting for stored package body metadata lock +LOCK_MODE MDL_INTENTION_EXCLUSIVE +LOCK_TYPE Schema metadata lock +TABLE_NAME +DO RELEASE_LOCK('lock'); +connection conn1; +pkg1.f1() +1 +disconnect conn1; +connection conn2; +disconnect conn2; +connection default; diff --git a/mysql-test/suite/compat/oracle/r/sp-package-mysqldump.result b/mysql-test/suite/compat/oracle/r/sp-package-mysqldump.result new file mode 100644 index 00000000..24211c63 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-mysqldump.result @@ -0,0 +1,261 @@ +SET sql_mode=ORACLE; +CREATE PROCEDURE p1 AS +BEGIN +SELECT pkg1.f1(); -- a standalone routine calls a package routine +END; +$$ +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +CALL test.p1; -- a package routine calls a standalone routine +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +END; +$$ +CALL p1; +pkg1.f1() +10 +CALL pkg1.p1; +pkg1.f1() +10 +SELECT pkg1.f1(); +pkg1.f1() +10 +CREATE PACKAGE pkg2 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `p1` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = latin1 */ ; +/*!50003 SET character_set_results = latin1 */ ; +/*!50003 SET collation_connection = latin1_swedish_ci */ ; +DELIMITER ;; +CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +BEGIN +SELECT pkg1.f1(); -- a standalone routine calls a package routine +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT' */ ; +/*!50003 DROP PACKAGE IF EXISTS `pkg1` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = latin1 */ ; +/*!50003 SET character_set_results = latin1 */ ; +/*!50003 SET collation_connection = latin1_swedish_ci */ ; +DELIMITER ;; +CREATE DEFINER="root"@"localhost" PACKAGE "pkg1" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT' */ ; +/*!50003 DROP PACKAGE IF EXISTS `pkg2` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = latin1 */ ; +/*!50003 SET character_set_results = latin1 */ ; +/*!50003 SET collation_connection = latin1_swedish_ci */ ; +DELIMITER ;; +CREATE DEFINER="root"@"localhost" PACKAGE "pkg2" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT' */ ; +/*!50003 DROP PACKAGE BODY IF EXISTS `pkg1` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = latin1 */ ; +/*!50003 SET character_set_results = latin1 */ ; +/*!50003 SET collation_connection = latin1_swedish_ci */ ; +DELIMITER ;; +CREATE DEFINER="root"@"localhost" PACKAGE BODY "pkg1" AS +PROCEDURE p1 AS +BEGIN +CALL test.p1; -- a package routine calls a standalone routine +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + + + + + + + + + + + + + + + + + + + + +DROP PACKAGE pkg1; +DROP PACKAGE pkg2; +DROP PROCEDURE p1; +SHOW PACKAGE STATUS; +Db test +Name pkg1 +Type PACKAGE +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +Db test +Name pkg2 +Type PACKAGE +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SHOW PACKAGE BODY STATUS; +Db test +Name pkg1 +Type PACKAGE BODY +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SHOW CREATE PACKAGE pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" PACKAGE "pkg1" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE pkg2; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg2 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" PACKAGE "pkg2" AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE BODY pkg1; +Package body sql_mode Create Package Body character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" PACKAGE BODY "pkg1" AS +PROCEDURE p1 AS +BEGIN +CALL test.p1; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END; +END latin1 latin1_swedish_ci latin1_swedish_ci +CALL p1; +pkg1.f1() +10 +CALL pkg1.p1; +pkg1.f1() +10 +SELECT pkg1.f1(); +pkg1.f1() +10 +DROP PACKAGE pkg1; +DROP PACKAGE pkg2; +DROP PROCEDURE p1; +# removing the dump file diff --git a/mysql-test/suite/compat/oracle/r/sp-package-security.result b/mysql-test/suite/compat/oracle/r/sp-package-security.result new file mode 100644 index 00000000..c08b78cb --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package-security.result @@ -0,0 +1,322 @@ +SET sql_mode=ORACLE; +CREATE DATABASE db1; +CREATE USER u1@localhost IDENTIFIED BY ''; +GRANT SELECT ON db1.* TO u1@localhost; +connect conn1,localhost,u1,,db1; +SELECT CURRENT_USER; +CURRENT_USER +u1@localhost +SET sql_mode=ORACLE; +# +# User u1 cannot drop PROCEDURE, PACKAGE, PACKAGE BODY by default +# +DROP PROCEDURE p1; +ERROR 42000: alter routine command denied to user 'u1'@'localhost' for routine 'db1.p1' +DROP PACKAGE pkg1; +ERROR 42000: alter routine command denied to user 'u1'@'localhost' for routine 'db1.pkg1' +DROP PACKAGE BODY pkg1; +ERROR 42000: alter routine command denied to user 'u1'@'localhost' for routine 'db1.pkg1' +# +# User u1 cannot create PROCEDURE, PACKAGE, PACKAGE BODY by default +# +CREATE PROCEDURE p1 AS +BEGIN +NULL; +END; +$$ +ERROR 42000: Access denied for user 'u1'@'localhost' to database 'db1' +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +ERROR 42000: Access denied for user 'u1'@'localhost' to database 'db1' +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +ERROR 42000: PACKAGE db1.pkg1 does not exist +# +# Now create a PACKAGE by root +# +connection default; +USE db1; +CREATE PROCEDURE p1root AS +BEGIN +SELECT 1; +END; +$$ +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +SHOW CREATE PACKAGE pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" PACKAGE "pkg1" AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END latin1 latin1_swedish_ci latin1_swedish_ci +# +# u1 cannot SHOW yet: +# - the standalone procedure earlier created by root +# - the package specifications earlier create by root +# +connection conn1; +SHOW CREATE PROCEDURE p1root; +ERROR 42000: PROCEDURE p1root does not exist +SHOW CREATE PACKAGE pkg1; +ERROR 42000: PACKAGE pkg1 does not exist +# +# User u1 still cannot create a PACKAGE BODY +# +connection conn1; +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS BEGIN NULL; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +END; +$$ +ERROR 42000: Access denied for user 'u1'@'localhost' to database 'db1' +# +# Now grant EXECUTE: +# - on the standalone procedure earlier created by root +# - on the package specification earlier created by root +# +connection default; +GRANT EXECUTE ON PROCEDURE db1.p1root TO u1@localhost; +GRANT EXECUTE ON PACKAGE db1.pkg1 TO u1@localhost; +# +# Now u1 can do SHOW for: +# - the standalone procedure earlier created by root +# - the package specification earlier created by root +# +disconnect conn1; +connect conn1,localhost,u1,,db1; +SET sql_mode=ORACLE; +SHOW CREATE PROCEDURE db1.p1root; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +p1root PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE db1.pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +# +# Now revoke EXECUTE and grant CREATE ROUTINE instead +# +connection default; +REVOKE EXECUTE ON PROCEDURE db1.p1root FROM u1@localhost; +REVOKE EXECUTE ON PACKAGE db1.pkg1 FROM u1@localhost; +GRANT CREATE ROUTINE ON db1.* TO u1@localhost; +# +# Reconnect u1 to make new grants have effect +# +disconnect conn1; +connect conn1,localhost,u1,,db1; +SET sql_mode=ORACLE; +# +# Now u1 can SHOW: +# - standalone routines earlier created by root +# - package specifications earlier created by root +# +SHOW CREATE PROCEDURE p1root; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +p1root PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +# +# Now u1 can CREATE, DROP and EXECUTE its own standalone procedures +# +CREATE PROCEDURE p1 AS +BEGIN +NULL; +END; +$$ +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +GRANT EXECUTE, ALTER ROUTINE ON PROCEDURE "db1"."p1" TO "u1"@"localhost" +CALL p1; +DROP PROCEDURE p1; +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +# +# Now u1 can also CREATE, DROP its own package specifications +# +CREATE PACKAGE pkg2 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +SHOW CREATE PACKAGE pkg2; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg2 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="u1"@"localhost" PACKAGE "pkg2" AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END latin1 latin1_swedish_ci latin1_swedish_ci +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +GRANT EXECUTE, ALTER ROUTINE ON PACKAGE "db1"."pkg2" TO "u1"@"localhost" +DROP PACKAGE pkg2; +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +# +# Now u1 can also CREATE, DROP package bodies and EXECUTE package body routines +# +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS BEGIN SELECT 'This is pkg1.p1' AS `comment`; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is pkg1.f1'; END; +END; +$$ +SHOW CREATE PACKAGE pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE BODY pkg1; +Package body sql_mode Create Package Body character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="u1"@"localhost" PACKAGE BODY "pkg1" AS +PROCEDURE p1 AS BEGIN SELECT 'This is pkg1.p1' AS `comment`; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is pkg1.f1'; END; +END latin1 latin1_swedish_ci latin1_swedish_ci +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +GRANT EXECUTE, ALTER ROUTINE ON PACKAGE BODY "db1"."pkg1" TO "u1"@"localhost" +CALL pkg1.p1; +comment +This is pkg1.p1 +SELECT pkg1.f1(); +pkg1.f1() +This is pkg1.f1 +DROP PACKAGE BODY pkg1; +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +# +# Now create a PACKAGE BODY by root. +# u1 does not have EXECUTE access by default. +# +connection default; +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS BEGIN SELECT 'This is pkg1.p1' AS `comment`; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is pkg1.f1'; END; +END; +$$ +connection conn1; +SHOW CREATE PACKAGE pkg1; +Package sql_mode Create Package character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +SHOW CREATE PACKAGE BODY pkg1; +Package body sql_mode Create Package Body character_set_client collation_connection Database Collation +pkg1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT NULL latin1 latin1_swedish_ci latin1_swedish_ci +CALL pkg1.p1; +ERROR 42000: execute command denied to user 'u1'@'localhost' for routine 'db1.pkg1' +SELECT pkg1.f1(); +ERROR 42000: execute command denied to user 'u1'@'localhost' for routine 'db1.pkg1' +# +# Now grant EXECUTE to u1 on the PACKAGE BODY created by root +# +connection default; +GRANT EXECUTE ON PACKAGE BODY db1.pkg1 TO u1@localhost; +disconnect conn1; +connect conn1,localhost,u1,,db1; +SELECT CURRENT_USER; +CURRENT_USER +u1@localhost +SET sql_mode=ORACLE; +SHOW GRANTS; +Grants for u1@localhost +GRANT USAGE ON *.* TO "u1"@"localhost" +GRANT SELECT, CREATE ROUTINE ON "db1".* TO "u1"@"localhost" +GRANT EXECUTE ON PACKAGE BODY "db1"."pkg1" TO "u1"@"localhost" +CALL pkg1.p1; +comment +This is pkg1.p1 +SELECT pkg1.f1(); +pkg1.f1() +This is pkg1.f1 +connection default; +DROP PACKAGE BODY pkg1; +# +# u1 still cannot DROP the package specification earlier created by root. +# +connection conn1; +DROP PACKAGE pkg1; +ERROR 42000: alter routine command denied to user 'u1'@'localhost' for routine 'db1.pkg1' +# +# Grant ALTER ROUTINE to u1 +# +connection default; +GRANT ALTER ROUTINE ON db1.* TO u1@localhost; +# +# Now u1 can DROP: +# - the standalone procedure earlier created by root +# - the package specification earlier created by root +# +disconnect conn1; +connect conn1,localhost,u1,,db1; +SET sql_mode=ORACLE; +DROP PACKAGE pkg1; +DROP PROCEDURE p1root; +disconnect conn1; +connection default; +DROP USER u1@localhost; +DROP DATABASE db1; +USE test; +# +# Creator=root, definer=xxx +# +CREATE USER xxx@localhost; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +SELECT SESSION_USER(), CURRENT_USER(), 'p1.p1' AS msg; +END; +BEGIN +SELECT SESSION_USER(), CURRENT_USER(), 'package body p1' AS msg; +END; +$$ +CALL p1.p1; +ERROR 42000: execute command denied to user 'xxx'@'localhost' for routine 'test.p1' +GRANT EXECUTE ON PACKAGE BODY test.p1 TO xxx@localhost; +CALL p1.p1; +SESSION_USER() CURRENT_USER() msg +root@localhost xxx@localhost package body p1 +SESSION_USER() CURRENT_USER() msg +root@localhost xxx@localhost p1.p1 +DROP PACKAGE p1; +DROP USER xxx@localhost; +# +# Creator=root, definer=xxx, SQL SECURITY INVOKER +# +CREATE USER xxx@localhost; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS +PROCEDURE p1 AS +BEGIN +SELECT SESSION_USER(), CURRENT_USER(), 'p1.p1' AS msg; +END; +BEGIN +SELECT SESSION_USER(), CURRENT_USER(), 'package body p1' AS msg; +END; +$$ +CALL p1.p1; +SESSION_USER() CURRENT_USER() msg +root@localhost root@localhost package body p1 +SESSION_USER() CURRENT_USER() msg +root@localhost root@localhost p1.p1 +DROP PACKAGE p1; +DROP USER xxx@localhost; diff --git a/mysql-test/suite/compat/oracle/r/sp-package.result b/mysql-test/suite/compat/oracle/r/sp-package.result new file mode 100644 index 00000000..ee17c048 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-package.result @@ -0,0 +1,3375 @@ +SET sql_mode=ORACLE; +# +# Creating a body of a non-existing package +# +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +ERROR 42000: PACKAGE test.test2 does not exist +# +# Dropping a non-existing package +# +DROP PACKAGE test2; +ERROR 42000: PACKAGE test.test2 does not exist +DROP PACKAGE IF EXISTS test2; +Warnings: +Note 1305 PACKAGE test.test2 does not exist +DROP PACKAGE BODY test2; +ERROR 42000: PACKAGE BODY test.test2 does not exist +# +# Bad combinations of OR REPLACE and IF EXISTS +# +CREATE OR REPLACE PACKAGE IF NOT EXISTS pkg AS +PROCEDURE p1; +END; +$$ +ERROR HY000: Incorrect usage of OR REPLACE and IF NOT EXISTS +CREATE OR REPLACE PACKAGE BODY IF NOT EXISTS pkg AS +PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +ERROR HY000: Incorrect usage of OR REPLACE and IF NOT EXISTS +# +# PACKAGE and PS +# +PREPARE stmt FROM 'CREATE PACKAGE test2 AS FUNCTION f1 RETURN INT; END test2'; +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +PREPARE stmt FROM 'CREATE PACKAGE BODY test2 AS' + ' FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END;' + 'END test2'; +DROP PACKAGE test2; +# +# Package and READ ONLY transactions +# +SET SESSION TRANSACTION READ ONLY; +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +$$ +ERROR 25006: Cannot execute statement in a READ ONLY transaction +SET SESSION TRANSACTION READ WRITE; +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f2 RETURN INT; +END; +$$ +SET SESSION TRANSACTION READ ONLY +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f2 RETURN INT AS BEGIN RETURN f1(); END; +PROCEDURE p1 AS +BEGIN +SELECT f2(); +END; +END; +$$ +ERROR 25006: Cannot execute statement in a READ ONLY transaction +SET SESSION TRANSACTION READ WRITE; +DROP PACKAGE test2; +SET SESSION TRANSACTION READ ONLY; +DROP PACKAGE test2; +ERROR 25006: Cannot execute statement in a READ ONLY transaction +DROP PACKAGE BODY test2; +ERROR 25006: Cannot execute statement in a READ ONLY transaction +SET SESSION TRANSACTION READ WRITE; +# +# Syntax error inside a CREATE PACKAGE, inside a routine definition +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f2 RETURN INT; +FUNCTION f3; +FUNCTION f4 RETURN INT; +END +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '; +FUNCTION f4 RETURN INT; +END' at line 4 +# +# Syntax error inside a CREATE PACKAGE, outside of a routine definition +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f2 RETURN INT; +FUNCTION f3 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f4 RETURN INT; +END +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS BEGIN RETURN 10; END; +FUNCTION f4 RETURN INT; +END' at line 4 +# +# Syntax error inside a CREATE PACKAGE BODY, inside a routine definition +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f2 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f2 RETURN INT SA BEGIN RETURN 10; END; -- Notice "SA" vs "AS" +END +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SA BEGIN RETURN 10; END; -- Notice "SA" vs "AS" +END' at line 3 +DROP PACKAGE test2; +# +# Syntax error inside a CREATE PACKAGE BODY, outside a routine definition +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f2 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +SOME SYNTAX ERROR; +FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END; +END +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SOME SYNTAX ERROR; +FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END; +END' at line 3 +DROP PACKAGE test2; +# +# Syntax error inside a CREATE PACKAGE BODY executable section +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +BEGIN +SOME SYNTAX ERROR; +END +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SYNTAX ERROR; +END' at line 4 +DROP PACKAGE test2; +# +# CREATE PROCEDURE inside a package PROCEDURE is not allowed +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS +BEGIN +CREATE PROCEDURE p1 AS BEGIN NULL; END; +END; +END; +$$ +ERROR 2F003: Can't create a PROCEDURE from within another stored routine +DROP PACKAGE test2; +# +# CREATE PACKAGE inside a package PROCEDURE is not allowed +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS +BEGIN +CREATE PACKAGE p1 AS PROCEDURE p1; END; +END; +END; +$$ +ERROR 2F003: Can't create a PACKAGE from within another stored routine +DROP PACKAGE test2; +# +# CREATE PROCEDURE inside a package executable section is not allowed +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +BEGIN +CREATE PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +ERROR 2F003: Can't create a PROCEDURE from within another stored routine +DROP PACKAGE test2; +# +# CREATE FUNCTION inside a package executable section is not allowed +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +BEGIN +CREATE FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +ERROR 2F003: Can't create a FUNCTION from within another stored routine +DROP PACKAGE test2; +# +# CREATE PACKAGE inside a package executable section is not allowed +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +BEGIN +CREATE PACKAGE p1 AS PROCEDURE p1; END; +END; +$$ +ERROR 2F003: Can't create a PACKAGE from within another stored routine +DROP PACKAGE test2; +# +# Broken CREATE PACKAGE at CREATE PACKAGE BODY time +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT +AS BEGIN +RETURN f2(); +END; +END; +$$ +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +DROP PACKAGE test2; +# +# Broken CREATE PACKAGE at a package function call time +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT +AS BEGIN +RETURN f2(); +END; +END; +$$ +SELECT test2.f1(); +ERROR 42000: FUNCTION test.f2 does not exist +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; +# sp-cache-invalidate +SELECT test2.f1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +SELECT test2.f1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +SELECT test2.f1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +DROP PACKAGE test2; +# +# Broken CREATE PACKAGE at a package procedure call time +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 +AS BEGIN +CALL p2; +END; +END; +$$ +CALL test2.f1(); +ERROR 42000: PROCEDURE test2.f1 does not exist +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; +# sp-cache-invalidate +CALL test2.p1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +CALL test2.p1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +CALL test2.p1(); +ERROR HY000: Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +show warnings; +Level Code Message +Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'garbage' at line 1 +Error 1457 Failed to load routine test.test2 (internal code -6). For more details, run SHOW WARNINGS +DROP PACKAGE test2; +# +# Bad routine names +# +CREATE PACKAGE p1 AS +PROCEDURE pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp1; +END; +$$ +ERROR 42000: Identifier name 'pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp1' is too long +CREATE PACKAGE p1 AS +FUNCTION fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1 +RETURN INT; +END; +$$ +ERROR 42000: Identifier name 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1' is too long +CREATE PACKAGE p1 AS +PROCEDURE "p1 "; +END; +$$ +ERROR 42000: Incorrect routine name 'p1 ' +CREATE PACKAGE p1 AS +FUNCTION "f1 " RETURN INT; +END; +$$ +ERROR 42000: Incorrect routine name 'f1 ' +CREATE PACKAGE p1 AS +PROCEDURE "p1.p1"; +END; +$$ +ERROR 42000: Incorrect routine name 'p1.p1' +CREATE PACKAGE p1 AS +FUNCTION "f1.f1" RETURN INT; +END; +$$ +ERROR 42000: Incorrect routine name 'f1.f1' +# +# Duplicate PROCEDURE in CREATE PACKAGE +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +PROCEDURE p1; +END; +$$ +ERROR 42000: PROCEDURE test2.p1 already exists +CREATE PACKAGE test2 AS +PROCEDURE p1; +PROCEDURE P1; +END; +$$ +ERROR 42000: PROCEDURE test2.P1 already exists +# +# Duplicate FUNCTION in CREATE PACKAGE +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION f1 RETURN INT; +END; +$$ +ERROR 42000: FUNCTION test2.f1 already exists +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +FUNCTION F1 RETURN INT; +END; +$$ +ERROR 42000: FUNCTION test2.F1 already exists +# +# Duplicate PROCEDURE in CREATE PACKAGE BODY +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +ERROR 42000: PROCEDURE test2.p1 already exists +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +PROCEDURE P1 AS BEGIN NULL; END; +END; +$$ +ERROR 42000: PROCEDURE test2.P1 already exists +DROP PACKAGE test2; +# +# Duplicate FUNCTION in CREATE PACKAGE BODY +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +ERROR 42000: FUNCTION test2.f1 already exists +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +FUNCTION F1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +ERROR 42000: FUNCTION test2.F1 already exists +DROP PACKAGE test2; +# +# Routines declared in CREATE PACKAGE missing in CREATE PACKAGE BODY +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p2 AS BEGIN NULL; END; +END; +$$ +ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body +DROP PACKAGE test2; +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +ERROR HY000: Subroutine 'test.test2.f1' is declared in the package specification but is not defined in the package body +DROP PACKAGE test2; +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION p1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body +DROP PACKAGE test2; +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1(a INT) AS BEGIN NULL; END; -- Notice different prototype +END; +$$ +ERROR HY000: Subroutine 'test.test2.p1' is declared in the package specification but is not defined in the package body +DROP PACKAGE test2; +# +# Forward declarations in CREATE PACKAGE BODY with missing implementations +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS BEGIN NULL; END; +PROCEDURE p2; +END; +$$ +ERROR HY000: Subroutine 'test.test2.p2' has a forward declaration but is not defined +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +ERROR HY000: Subroutine 'test.test2.f1' has a forward declaration but is not defined +DROP PACKAGE test2; +# +# Creating a new package +# +CREATE PACKAGE test2 COMMENT 'package-test2-comment' AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +$$ +Warnings: +Note 1585 This function 'concat' has the same name as a native function +SELECT * FROM mysql.proc WHERE db='test' AND name='test2'; +db test +name test2 +type PACKAGE +specific_name test2 +language SQL +sql_data_access CONTAINS_SQL +is_deterministic NO +security_type DEFINER +param_list +returns +body AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +definer root@localhost +created # +modified # +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +comment package-test2-comment +character_set_client latin1 +collation_connection latin1_swedish_ci +db_collation latin1_swedish_ci +body_utf8 AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +aggregate NONE +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME='test2'; +SPECIFIC_NAME test2 +ROUTINE_CATALOG def +ROUTINE_SCHEMA test +ROUTINE_NAME test2 +ROUTINE_TYPE PACKAGE +DATA_TYPE +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER NULL +ROUTINE_BODY SQL +ROUTINE_DEFINITION AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +EXTERNAL_NAME NULL +EXTERNAL_LANGUAGE NULL +PARAMETER_STYLE SQL +IS_DETERMINISTIC NO +SQL_DATA_ACCESS CONTAINS SQL +SQL_PATH NULL +SECURITY_TYPE DEFINER +CREATED # +LAST_ALTERED # +SQL_MODE PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +ROUTINE_COMMENT package-test2-comment +DEFINER root@localhost +CHARACTER_SET_CLIENT latin1 +COLLATION_CONNECTION latin1_swedish_ci +DATABASE_COLLATION latin1_swedish_ci +CREATE PACKAGE IF NOT EXISTS test2 AS +FUNCTION f1 RETURN INT; +END test2 +$$ +Warnings: +Note 1304 PACKAGE test2 already exists +CREATE PACKAGE BODY test2 COMMENT 'package-body-test2-comment' AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; +FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; +PROCEDURE p1 AS +BEGIN +SELECT f2(0); +END; +PROCEDURE p2(a INT) AS +BEGIN +SELECT f2(a); +END; +END; +$$ +Warnings: +Note 1585 This function 'concat' has the same name as a native function +Note 1585 This function 'concat' has the same name as a native function +CREATE PACKAGE BODY IF NOT EXISTS test2 AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 20; END; +FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; +FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; +PROCEDURE p1 AS +BEGIN +SELECT f2(0); +END; +PROCEDURE p2(a INT) AS +BEGIN +SELECT f2(a); +END; +END; +$$ +Warnings: +Note 1585 This function 'concat' has the same name as a native function +Note 1585 This function 'concat' has the same name as a native function +Note 1304 PACKAGE BODY test2 already exists +SELECT test2.f1(); +test2.f1() +10 +SELECT test2.f2(1); +test2.f2(1) +11 +CALL test2.p1(); +f2(0) +10 +CALL test2.p2(1); +f2(a) +11 +SELECT * FROM mysql.proc WHERE db='test' AND name LIKE 'test2.%'; +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME='test2'; +SPECIFIC_NAME test2 +ROUTINE_CATALOG def +ROUTINE_SCHEMA test +ROUTINE_NAME test2 +ROUTINE_TYPE PACKAGE +DATA_TYPE +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER NULL +ROUTINE_BODY SQL +ROUTINE_DEFINITION AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +EXTERNAL_NAME NULL +EXTERNAL_LANGUAGE NULL +PARAMETER_STYLE SQL +IS_DETERMINISTIC NO +SQL_DATA_ACCESS CONTAINS SQL +SQL_PATH NULL +SECURITY_TYPE DEFINER +CREATED # +LAST_ALTERED # +SQL_MODE PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +ROUTINE_COMMENT package-test2-comment +DEFINER root@localhost +CHARACTER_SET_CLIENT latin1 +COLLATION_CONNECTION latin1_swedish_ci +DATABASE_COLLATION latin1_swedish_ci +SPECIFIC_NAME test2 +ROUTINE_CATALOG def +ROUTINE_SCHEMA test +ROUTINE_NAME test2 +ROUTINE_TYPE PACKAGE BODY +DATA_TYPE +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +DTD_IDENTIFIER NULL +ROUTINE_BODY SQL +ROUTINE_DEFINITION AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; +FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; +PROCEDURE p1 AS +BEGIN +SELECT f2(0); +END; +PROCEDURE p2(a INT) AS +BEGIN +SELECT f2(a); +END; +END +EXTERNAL_NAME NULL +EXTERNAL_LANGUAGE NULL +PARAMETER_STYLE SQL +IS_DETERMINISTIC NO +SQL_DATA_ACCESS CONTAINS SQL +SQL_PATH NULL +SECURITY_TYPE DEFINER +CREATED # +LAST_ALTERED # +SQL_MODE PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +ROUTINE_COMMENT package-body-test2-comment +DEFINER root@localhost +CHARACTER_SET_CLIENT latin1 +COLLATION_CONNECTION latin1_swedish_ci +DATABASE_COLLATION latin1_swedish_ci +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME LIKE 'test2.%'; +SHOW PACKAGE STATUS; +Db test +Name test2 +Type PACKAGE +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment package-test2-comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SHOW PACKAGE BODY STATUS; +Db test +Name test2 +Type PACKAGE BODY +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment package-body-test2-comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SHOW CREATE PACKAGE test2; +Package test2 +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +Create Package CREATE DEFINER="root"@"localhost" PACKAGE "test2" COMMENT 'package-test2-comment' + AS +FUNCTION f1 RETURN INT DETERMINISTIC; +FUNCTION f2(a INT) RETURN INT; +FUNCTION concat RETURN INT; +PROCEDURE p1; +PROCEDURE p2(a INT); +END +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +Warnings: +Level Note +Code 1585 +Message This function 'concat' has the same name as a native function +SHOW CREATE PACKAGE BODY test2; +Package body test2 +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +Create Package Body CREATE DEFINER="root"@"localhost" PACKAGE BODY "test2" COMMENT 'package-body-test2-comment' + AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; +FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; +PROCEDURE p1 AS +BEGIN +SELECT f2(0); +END; +PROCEDURE p2(a INT) AS +BEGIN +SELECT f2(a); +END; +END +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +Warnings: +Level Note +Code 1585 +Message This function 'concat' has the same name as a native function +DROP PACKAGE BODY test2; +SELECT test2.f1(); +ERROR 42000: FUNCTION test.test2.f1 does not exist +SELECT test2.f2(); +ERROR 42000: FUNCTION test.test2.f2 does not exist +CALL test2.p1(); +ERROR 42000: PROCEDURE test.test2.p1 does not exist +DROP PACKAGE BODY IF EXISTS test2; +Warnings: +Note 1305 PACKAGE BODY test.test2 does not exist +DROP PACKAGE BODY test2; +ERROR 42000: PACKAGE BODY test.test2 does not exist +DROP PACKAGE test2; +# +# Creating a new package in a remote database +# +CREATE DATABASE test2; +CREATE PACKAGE test2.test2 COMMENT 'package-test2-comment' AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END +$$ +CREATE PACKAGE BODY test2.test2 COMMENT 'package-body-test2-comment' AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +PROCEDURE p1 AS BEGIN SELECT f1(); END; +END; +$$ +SHOW PACKAGE STATUS; +Db test2 +Name test2 +Type PACKAGE +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment package-test2-comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SHOW PACKAGE BODY STATUS; +Db test2 +Name test2 +Type PACKAGE BODY +Definer root@localhost +Modified 0000-00-00 00:00:00 +Created 0000-00-00 00:00:00 +Security_type DEFINER +Comment package-body-test2-comment +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +USE test2; +SELECT test2.f1(); +test2.f1() +10 +CALL test2.p1(); +f1() +10 +USE test; +DROP PACKAGE BODY test2.test2; +DROP PACKAGE test2.test2; +DROP DATABASE test2; +# +# Only public routines are available outside +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +-- Public routines +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is test2.f1'; +END; +PROCEDURE p1 AS +BEGIN +SELECT 'This is test2.p1'; +END; +-- Private routines +FUNCTION f2 RETURN TEXT AS +BEGIN +RETURN 'This is test2.f2'; +END; +PROCEDURE p2 AS +BEGIN +SELECT 'This is test2.p2'; +END; +END; +$$ +SELECT test2.f1(); +test2.f1() +This is test2.f1 +CALL test2.p1(); +This is test2.p1 +This is test2.p1 +SELECT test2.f2(); +ERROR 42000: FUNCTION test2.f2 does not exist +CALL test2.p2(); +ERROR 42000: PROCEDURE test2.p2 does not exist +DROP PACKAGE test2; +# +# PACKAGE BODY with forward declarations +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +-- Forward declarations +FUNCTION f2private RETURN TEXT; +PROCEDURE p2private; +-- Public routines +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN f2private(); +END; +PROCEDURE p1 AS +BEGIN +CALL p2private; +END; +-- Definitions for the forward declarations +FUNCTION f2private RETURN TEXT AS +BEGIN +RETURN 'This is f2private'; +END; +PROCEDURE p2private AS +BEGIN +SELECT 'This is p2private'; +END; +END; +$$ +SELECT test2.f1(); +test2.f1() +This is f2private +CALL test2.p1(); +This is p2private +This is p2private +DROP PACKAGE test2; +# +# Calling private routines with forward declarations, +# using qualified notation, e.g. "CALL pkg.proc" +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +-- Forward declarations +FUNCTION f2private RETURN TEXT; +PROCEDURE p2private; +-- Public routines +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN test2.f2private(); +END; +PROCEDURE p1 AS +BEGIN +CALL test2.p2private; +END; +-- Definitions for the forward declarations +FUNCTION f2private RETURN TEXT AS +BEGIN +RETURN 'This is f2private'; +END; +PROCEDURE p2private AS +BEGIN +SELECT 'This is p2private' AS msg; +END; +END; +$$ +SELECT test2.f1(); +test2.f1() +This is f2private +CALL test2.p1(); +msg +This is p2private +DROP PACKAGE test2; +# +# Calling private routines, using qualified notation, e.g. "pkg.proc" +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +-- Private routines +FUNCTION f2private RETURN TEXT AS +BEGIN +RETURN 'This is f2private'; +END; +PROCEDURE p2private AS +BEGIN +SELECT 'This is p2private' AS msg; +END; +-- Public routines +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN test2.f2private(); +END; +PROCEDURE p1 AS +BEGIN +CALL test2.p2private; +END; +END; +$$ +SELECT test2.f1(); +test2.f1() +This is f2private +CALL test2.p1(); +msg +This is p2private +DROP PACKAGE test2; +# +# Calling private routines from the package initialization section, +# using qualified notation, e.g. "pkg.proc" +# +CREATE PACKAGE test2 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS +-- Private routines +FUNCTION f2private RETURN TEXT AS +BEGIN +RETURN 'This is f2private'; +END; +PROCEDURE p2private AS +BEGIN +SELECT 'This is p2private' AS msg; +END; +-- Public routines +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +END; +BEGIN +SELECT test2.f2private(); +CALL test2.p2private(); +END; +$$ +CALL test2.p1(); +test2.f2private() +This is f2private +msg +This is p2private +msg +This is p1 +DROP PACKAGE test2; +# +# Testing OR REPLACE +# +CREATE OR REPLACE PACKAGE pkg AS +FUNCTION f0 RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE pkg AS +FUNCTION f1 RETURN INT; +END; +$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +name type body +pkg PACKAGE AS +FUNCTION f1 RETURN INT; +END +CREATE OR REPLACE PACKAGE BODY pkg AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +name type body +pkg PACKAGE AS +FUNCTION f1 RETURN INT; +END +pkg PACKAGE BODY AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +END +SELECT pkg.f1(); +pkg.f1() +10 +CREATE OR REPLACE PACKAGE BODY pkg AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 20; END; +END; +$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +name type body +pkg PACKAGE AS +FUNCTION f1 RETURN INT; +END +pkg PACKAGE BODY AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 20; END; +END +SELECT pkg.f1(); +pkg.f1() +20 +CREATE OR REPLACE PACKAGE pkg AS +FUNCTION f1 RETURN BIGINT; +END; +$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +name type body +pkg PACKAGE AS +FUNCTION f1 RETURN BIGINT; +END +SELECT pkg.f1(); +ERROR 42000: FUNCTION test.pkg.f1 does not exist +CREATE OR REPLACE PACKAGE BODY pkg AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 30; END; +END; +$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +name type body +pkg PACKAGE AS +FUNCTION f1 RETURN BIGINT; +END +pkg PACKAGE BODY AS +FUNCTION f1 RETURN INT AS BEGIN RETURN 30; END; +END +SELECT pkg.f1(); +pkg.f1() +30 +DROP PACKAGE pkg; +# +# Package routines accessing tables +# +CREATE TABLE t1 (a INT); +CREATE PACKAGE test2 AS +PROCEDURE p1(a INT); +END; +$$ +CREATE PACKAGE BODY test2 AS +PROCEDURE p1(a INT) AS +BEGIN +INSERT INTO t1 VALUES (10); +END; +END; +$$ +CALL test2.p1(10); +SELECT * FROM t1; +a +10 +DROP PACKAGE test2; +DROP TABLE t1; +# +# CREATE PACKAGE: Optional package name after the "END" keyword +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END test2.test2 +$$ +ERROR HY000: END identifier 'test2.test2' does not match 'test.test2' +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END test3 +$$ +ERROR HY000: END identifier 'test3' does not match 'test2' +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END test2 +$$ +DROP PACKAGE test2; +# +# MDEV-12089 sql_mode=ORACLE: Understand optional routine name after the END keyword +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN INT; +PROCEDURE p1; +END test2; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END f1.f1; +END test2; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.f1; +END test2' at line 5 +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END f2; +END test2; +$$ +ERROR HY000: END identifier 'f2' does not match 'f1' +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS +BEGIN +NULL; +END p1.p1; +END test2; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.p1; +END test2' at line 5 +CREATE PACKAGE BODY test2 AS +PROCEDURE p1 AS +BEGIN +NULL; +END p2; +END test2; +$$ +ERROR HY000: END identifier 'p2' does not match 'p1' +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN INT AS +BEGIN +RETURN 10; +END f1; +PROCEDURE p1 AS +BEGIN +NULL; +END p1; +END test2; +$$ +DROP PACKAGE test2; +# +# Package and package routine name and end name are case insensitive +# +CREATE PACKAGE test2 AS +FUNCTION f1 RETURN TEXT; +PROCEDURE p1; +END TEST2; +$$ +CREATE PACKAGE BODY test2 AS +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is f1'; +END F1; +PROCEDURE P1 AS +BEGIN +SELECT 'This is p1' AS msg; +END p1; +END TEST2; +$$ +SELECT TEST2.F1(); +TEST2.F1() +This is f1 +SELECT test2.f1(); +test2.f1() +This is f1 +CALL TEST2.p1(); +msg +This is p1 +CALL test2.P1(); +msg +This is p1 +DROP PACKAGE BODY TEST2; +DROP PACKAGE TEST2; +# +# Testing various qualified/non-qualified db/package SP call chains +# +CREATE FUNCTION f3() RETURN TEXT AS +BEGIN +SET @track= @track || ' ' || 'test.f3()'; +RETURN ''; +END; +$$ +CREATE PROCEDURE p3() AS +BEGIN +SET @track= @track || ' ' || 'test.p3()'; +END; +$$ +CREATE FUNCTION ff2(task TEXT) RETURN TEXT AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= @track || ' ' || 'test.ff2()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +RETURN ''; +END; +$$ +CREATE PROCEDURE pp2(task TEXT) AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= @track || ' ' || 'test.pp2()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +END; +$$ +CREATE PACKAGE pack AS +PROCEDURE p1(task TEXT); +PROCEDURE p2(task TEXT); +FUNCTION f1(task TEXT) RETURN TEXT; +FUNCTION f2(step2 TEXT) RETURN TEXT; +FUNCTION f3 RETURN TEXT; +PROCEDURE p3; +END; +$$ +CREATE PACKAGE BODY pack AS +PROCEDURE p1(task TEXT) AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= 'test.pack.p1()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p2' THEN CALL p2(tail); +WHEN 'f2' THEN rc:= f2(tail); +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'px' THEN CALL px(); +WHEN 'fx' THEN rc:= fx(); +WHEN 'pp2' THEN CALL pp2(tail); +WHEN 'ff2' THEN rc:= ff2(tail); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'pack.px' THEN CALL pack.px(); +WHEN 'pack.fx' THEN rc:= pack.fx(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +SELECT @track; +END; +FUNCTION f1(task TEXT) RETURN TEXT AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= 'test.pack.f1()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p2' THEN CALL p2(tail); +WHEN 'f2' THEN rc:= f2(tail); +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'px' THEN CALL px(); +WHEN 'fx' THEN rc:= fx(); +WHEN 'pp2' THEN CALL pp2(tail); +WHEN 'ff2' THEN rc:= ff2(tail); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'pack.px' THEN CALL pack.px(); +WHEN 'pack.fx' THEN rc:= pack.fx(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT=@track; +RETURN ''; +END; +PROCEDURE p2(task TEXT) AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= @track || ' ' || 'test.pack.p2()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p2' THEN CALL p2(tail); +WHEN 'f2' THEN rc:= f2(tail); +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'px' THEN CALL px(); +WHEN 'fx' THEN rc:= fx(); +WHEN 'pp2' THEN CALL pp2(tail); +WHEN 'ff2' THEN rc:= ff2(tail); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'pack.px' THEN CALL pack.px(); +WHEN 'pack.fx' THEN rc:= pack.fx(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +END; +FUNCTION f2(task TEXT) RETURN TEXT AS +step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); +tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); +rc TEXT; +BEGIN +SET @track= @track || ' ' || 'test.pack.f2()'; +CASE step +WHEN '' THEN NULL; +WHEN 'p2' THEN CALL p2(tail); +WHEN 'f2' THEN rc:= f2(tail); +WHEN 'p3' THEN CALL p3(); +WHEN 'f3' THEN rc:= f3(); +WHEN 'px' THEN CALL px(); +WHEN 'fx' THEN rc:= fx(); +WHEN 'pp2' THEN CALL pp2(tail); +WHEN 'ff2' THEN rc:= ff2(tail); +WHEN 'pack.p2' THEN CALL pack.p2(tail); +WHEN 'pack.f2' THEN rc:= pack.f2(tail); +WHEN 'pack.p3' THEN CALL pack.p3(); +WHEN 'pack.f3' THEN rc:= pack.f3(); +WHEN 'pack.px' THEN CALL pack.px(); +WHEN 'pack.fx' THEN rc:= pack.fx(); +WHEN 'test.p3' THEN CALL test.p3(); +WHEN 'test.f3' THEN rc:= test.f3(); +WHEN 'test.pp2' THEN CALL test.pp2(tail); +WHEN 'test.ff2' THEN rc:= test.ff2(tail); +ELSE SET @track= @track || ' ' || step || ' [unknown step]'; +END CASE; +RETURN ''; +END; +PROCEDURE p3 AS +BEGIN +SET @track= @track || ' ' || 'test.pack.p3()'; +END; +FUNCTION f3 RETURN TEXT AS +BEGIN +SET @track= @track || ' ' || 'test.pack.f3()'; +RETURN ''; +END; +END pack; +$$ +SET max_sp_recursion_depth=10; +# pack.routine -> * +CALL pack.p1('p2'); +@track +test.pack.p1() test.pack.p2() +CALL pack.p1('f2'); +@track +test.pack.p1() test.pack.f2() +CALL pack.p1('px'); +ERROR 42000: PROCEDURE test.px does not exist +CALL pack.p1('fx'); +ERROR 42000: FUNCTION test.fx does not exist +CALL pack.p1('pp2'); +@track +test.pack.p1() test.pp2() +CALL pack.p1('ff2'); +@track +test.pack.p1() test.ff2() +CALL pack.p1('pack.p2'); +@track +test.pack.p1() test.pack.p2() +CALL pack.p1('pack.f2'); +@track +test.pack.p1() test.pack.f2() +CALL pack.p1('pack.px'); +ERROR 42000: PROCEDURE pack.px does not exist +CALL pack.p1('pack.fx'); +ERROR 42000: FUNCTION pack.fx does not exist +CALL pack.p1('test.pp2'); +@track +test.pack.p1() test.pp2() +CALL pack.p1('test.ff2'); +@track +test.pack.p1() test.ff2() +DO pack.f1('p2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() +DO pack.f1('f2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() +DO pack.p1('px'); +ERROR 42000: FUNCTION pack.p1 does not exist +DO pack.p1('fx'); +ERROR 42000: FUNCTION pack.p1 does not exist +DO pack.f1('pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() +DO pack.f1('ff2'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() +DO pack.f1('pack.p2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() +DO pack.f1('pack.f2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() +SELECT pack.f1('pack.px'); +ERROR 42000: PROCEDURE pack.px does not exist +SELECT pack.f1('pack.fx'); +ERROR 42000: FUNCTION pack.fx does not exist +DO pack.f1('test.pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() +DO pack.f1('test.ff2'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() +# +# Qualified_package_routine -> Non_qualified_package_routine +# +# pack.routine -> [pack.]routine -> pack.routine +CALL pack.p1('p2 pack.p3'); +@track +test.pack.p1() test.pack.p2() test.pack.p3() +CALL pack.p1('p2 pack.f3'); +@track +test.pack.p1() test.pack.p2() test.pack.f3() +CALL pack.p1('f2 pack.p3'); +@track +test.pack.p1() test.pack.f2() test.pack.p3() +CALL pack.p1('f2 pack.f3'); +@track +test.pack.p1() test.pack.f2() test.pack.f3() +DO pack.f1('p2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.p3() +DO pack.f1('p2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.f3() +DO pack.f1('f2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.p3() +DO pack.f1('f2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.f3() +# pack.routine -> [pack.]routine -> [pack]routine +CALL pack.p1('p2 p3'); +@track +test.pack.p1() test.pack.p2() test.pack.p3() +CALL pack.p1('p2 f3'); +@track +test.pack.p1() test.pack.p2() test.pack.f3() +CALL pack.p1('f2 p3'); +@track +test.pack.p1() test.pack.f2() test.pack.p3() +CALL pack.p1('f2 f3'); +@track +test.pack.p1() test.pack.f2() test.pack.f3() +DO pack.f1('p2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.p3() +DO pack.f1('p2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.f3() +DO pack.f1('f2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.p3() +DO pack.f1('f2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.f3() +# pack.routine -> [pack.]routine -> test.routine +CALL pack.p1('p2 test.p3'); +@track +test.pack.p1() test.pack.p2() test.p3() +CALL pack.p1('p2 test.f3'); +@track +test.pack.p1() test.pack.p2() test.f3() +CALL pack.p1('f2 test.p3'); +@track +test.pack.p1() test.pack.f2() test.p3() +CALL pack.p1('f2 test.f3'); +@track +test.pack.p1() test.pack.f2() test.f3() +DO pack.f1('p2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.p3() +DO pack.f1('p2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.f3() +DO pack.f1('f2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.p3() +DO pack.f1('f2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.f3() +# pack.routine -> [pack.]routine -> [test.]routine +CALL pack.p1('p2 pp2'); +@track +test.pack.p1() test.pack.p2() test.pp2() +CALL pack.p1('p2 ff2'); +@track +test.pack.p1() test.pack.p2() test.ff2() +CALL pack.p1('f2 pp2'); +@track +test.pack.p1() test.pack.f2() test.pp2() +CALL pack.p1('f2 ff2'); +@track +test.pack.p1() test.pack.f2() test.ff2() +DO pack.f1('p2 pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pp2() +DO pack.f1('p2 ff2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.ff2() +DO pack.f1('f2 pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pp2() +DO pack.f1('f2 ff2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.ff2() +# +# Qualified_package_routine -> Non_qualified_database_routine +# +# pack.routine -> [test.]routine -> pack.routine +CALL pack.p1('pp2 pack.p3'); +@track +test.pack.p1() test.pp2() test.pack.p3() +CALL pack.p1('pp2 pack.f3'); +@track +test.pack.p1() test.pp2() test.pack.f3() +CALL pack.p1('ff2 pack.p3'); +@track +test.pack.p1() test.ff2() test.pack.p3() +CALL pack.p1('ff2 pack.f3'); +@track +test.pack.p1() test.ff2() test.pack.f3() +DO pack.f1('pp2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.pack.p3() +DO pack.f1('pp2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.pack.f3() +DO pack.f1('ff2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.pack.p3() +DO pack.f1('ff2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.pack.f3() +# pack.routine -> [test.]routine -> test.routine +CALL pack.p1('pp2 test.p3'); +@track +test.pack.p1() test.pp2() test.p3() +CALL pack.p1('pp2 test.f3'); +@track +test.pack.p1() test.pp2() test.f3() +CALL pack.p1('ff2 test.p3'); +@track +test.pack.p1() test.ff2() test.p3() +CALL pack.p1('ff2 test.f3'); +@track +test.pack.p1() test.ff2() test.f3() +DO pack.f1('pp2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.p3() +DO pack.f1('pp2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.f3() +DO pack.f1('ff2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.p3() +DO pack.f1('ff2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.f3() +# pack.routine -> [test.]routine -> [test.]routine +CALL pack.p1('pp2 p3'); +@track +test.pack.p1() test.pp2() test.p3() +CALL pack.p1('pp2 f3'); +@track +test.pack.p1() test.pp2() test.f3() +CALL pack.p1('ff2 p3'); +@track +test.pack.p1() test.ff2() test.p3() +CALL pack.p1('ff2 f3'); +@track +test.pack.p1() test.ff2() test.f3() +DO pack.f1('pp2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.p3() +DO pack.f1('pp2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.f3() +DO pack.f1('ff2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.p3() +DO pack.f1('ff2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.f3() +# +# Qualified_package_routine -> Qualified_package_routine +# +# pack.routine -> pack.routine -> pack.routine +CALL pack.p1('pack.p2 pack.p3'); +@track +test.pack.p1() test.pack.p2() test.pack.p3() +CALL pack.p1('pack.p2 pack.f3'); +@track +test.pack.p1() test.pack.p2() test.pack.f3() +CALL pack.p1('pack.f2 pack.p3'); +@track +test.pack.p1() test.pack.f2() test.pack.p3() +CALL pack.p1('pack.f2 pack.f3'); +@track +test.pack.p1() test.pack.f2() test.pack.f3() +DO pack.f1('pack.p2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.p3() +DO pack.f1('pack.p2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.f3() +DO pack.f1('pack.f2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.p3() +DO pack.f1('pack.f2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.f3() +# pack.routine -> pack.routine -> [pack.]routine +CALL pack.p1('pack.p2 p3'); +@track +test.pack.p1() test.pack.p2() test.pack.p3() +CALL pack.p1('pack.p2 f3'); +@track +test.pack.p1() test.pack.p2() test.pack.f3() +CALL pack.p1('pack.f2 p3'); +@track +test.pack.p1() test.pack.f2() test.pack.p3() +CALL pack.p1('pack.f2 f3'); +@track +test.pack.p1() test.pack.f2() test.pack.f3() +DO pack.f1('pack.p2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.p3() +DO pack.f1('pack.p2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pack.f3() +DO pack.f1('pack.f2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.p3() +DO pack.f1('pack.f2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pack.f3() +# pack.routine -> pack.routine -> test.routine +CALL pack.p1('pack.p2 test.p3'); +@track +test.pack.p1() test.pack.p2() test.p3() +CALL pack.p1('pack.p2 test.f3'); +@track +test.pack.p1() test.pack.p2() test.f3() +CALL pack.p1('pack.f2 test.p3'); +@track +test.pack.p1() test.pack.f2() test.p3() +CALL pack.p1('pack.f2 test.f3'); +@track +test.pack.p1() test.pack.f2() test.f3() +DO pack.f1('pack.p2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.p3() +DO pack.f1('pack.p2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.f3() +DO pack.f1('pack.f2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.p3() +DO pack.f1('pack.f2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.f3() +# pack.routine -> pack.routine -> [test.]routine +CALL pack.p1('pack.p2 pp2'); +@track +test.pack.p1() test.pack.p2() test.pp2() +CALL pack.p1('pack.p2 ff2'); +@track +test.pack.p1() test.pack.p2() test.ff2() +CALL pack.p1('pack.f2 pp2'); +@track +test.pack.p1() test.pack.f2() test.pp2() +CALL pack.p1('pack.f2 ff2'); +@track +test.pack.p1() test.pack.f2() test.ff2() +DO pack.f1('pack.p2 pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.pp2() +DO pack.f1('pack.p2 ff2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.p2() test.ff2() +DO pack.f1('pack.f2 pp2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.pp2() +DO pack.f1('pack.f2 ff2'); +Warnings: +Warning 1642 test.pack.f1() test.pack.f2() test.ff2() +# +# Qualified_package_routine -> Qualified_database_routine +# +pack.routine -> test.routine -> pack.routine +CALL pack.p1('test.pp2 pack.p3'); +@track +test.pack.p1() test.pp2() test.pack.p3() +CALL pack.p1('test.pp2 pack.f3'); +@track +test.pack.p1() test.pp2() test.pack.f3() +CALL pack.p1('test.ff2 pack.p3'); +@track +test.pack.p1() test.ff2() test.pack.p3() +CALL pack.p1('test.ff2 pack.f3'); +@track +test.pack.p1() test.ff2() test.pack.f3() +DO pack.f1('test.pp2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.pack.p3() +DO pack.f1('test.pp2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.pack.f3() +DO pack.f1('test.ff2 pack.p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.pack.p3() +DO pack.f1('test.ff2 pack.f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.pack.f3() +pack.routine -> test.routine -> test.routine +CALL pack.p1('test.pp2 test.p3'); +@track +test.pack.p1() test.pp2() test.p3() +CALL pack.p1('test.pp2 test.f3'); +@track +test.pack.p1() test.pp2() test.f3() +CALL pack.p1('test.ff2 test.p3'); +@track +test.pack.p1() test.ff2() test.p3() +CALL pack.p1('test.ff2 test.f3'); +@track +test.pack.p1() test.ff2() test.f3() +DO pack.f1('test.pp2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.p3() +DO pack.f1('test.pp2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.f3() +DO pack.f1('test.ff2 test.p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.p3() +DO pack.f1('test.ff2 test.f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.f3() +pack.routine -> test.routine -> [test.]routine +CALL pack.p1('test.pp2 p3'); +@track +test.pack.p1() test.pp2() test.p3() +CALL pack.p1('test.pp2 f3'); +@track +test.pack.p1() test.pp2() test.f3() +CALL pack.p1('test.ff2 p3'); +@track +test.pack.p1() test.ff2() test.p3() +CALL pack.p1('test.ff2 f3'); +@track +test.pack.p1() test.ff2() test.f3() +DO pack.f1('test.pp2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.p3() +DO pack.f1('test.pp2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.pp2() test.f3() +DO pack.f1('test.ff2 p3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.p3() +DO pack.f1('test.ff2 f3'); +Warnings: +Warning 1642 test.pack.f1() test.ff2() test.f3() +# Longer chains +CALL pack.p1('p2 f2 p2 test.pp2 test.ff2 pack.p3'); +@track +test.pack.p1() test.pack.p2() test.pack.f2() test.pack.p2() test.pp2() test.ff2() test.pack.p3() +CALL pack.p1('p2 test.pp2 pack.p2 pack.f2 test.ff2 pack.p3'); +@track +test.pack.p1() test.pack.p2() test.pp2() test.pack.p2() test.pack.f2() test.ff2() test.pack.p3() +DROP PACKAGE pack; +DROP FUNCTION f3; +DROP PROCEDURE p3; +DROP FUNCTION ff2; +DROP PROCEDURE pp2; +# +# Calling a standalone function from a non-current database, +# which calls a package routine from the same non-current database. +# +CREATE PROCEDURE p1 AS +BEGIN +CALL pkg1.p1; +END; +$$ +CREATE PACKAGE pkg1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +PROCEDURE p1 AS +BEGIN +SELECT database(); +END; +END; +$$ +CALL p1; +database() +test +CREATE DATABASE test2; +USE test2; +CALL test.p1; +database() +test +DROP DATABASE test2; +CALL test.p1; +database() +test +USE test; +DROP PACKAGE pkg1; +DROP PROCEDURE p1; +# +# Creating a package with a different DEFINER +# +CREATE USER xxx@localhost; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 DEFINER PACKAGE +xxx@localhost p1 DEFINER PACKAGE BODY +DROP PACKAGE p1; +DROP USER xxx@localhost; +# +# Creating a package with a different DEFINER, with SQL SECURITY INVOKER +# +CREATE USER xxx@localhost; +CREATE DEFINER=xxx@localhost PACKAGE p1 SQL SECURITY INVOKER AS +PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS +PROCEDURE p1 AS +BEGIN +NULL; +END; +END; +$$ +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +definer name security_type type +xxx@localhost p1 INVOKER PACKAGE +xxx@localhost p1 INVOKER PACKAGE BODY +DROP PACKAGE p1; +DROP USER xxx@localhost; +# +# A package with an initialization section +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; +FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN +SET @a:=10; +END; +$$ +CALL p1.p1(); +@a +11 +CALL p1.p1(); +@a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +@a +12 +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +@a +14 +DROP PACKAGE p1; +# +# A package with an initialization section calling +# routines from the same package, and standalone routines. +# +CREATE PROCEDURE init20 AS +BEGIN +SET @msg= @msg || '[init20]'; +END; +$$ +CREATE PACKAGE p1 AS +PROCEDURE init1; +PROCEDURE init2; +FUNCTION init3 RETURN INT; +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE init1 AS +BEGIN +SET @msg= @msg || '[p1.init1]'; +END; +PROCEDURE init2 AS +BEGIN +SET @msg= @msg || '[p1.init2]'; +END; +FUNCTION init3 RETURN INT AS +BEGIN +SET @msg= @msg || '[p1.init3]'; +RETURN 0; +END; +PROCEDURE p1 AS +BEGIN +SET @msg= @msg || '[p1.p1]'; +SELECT @msg; +END; +FUNCTION f1 RETURN TEXT AS +BEGIN +SET @msg= @msg || '[p1.f1]'; +RETURN @msg; +END; +BEGIN +SET @msg= ''; +init1(); +init2(); +DO init3(); +init20(); +END; +$$ +CALL p1.p1(); +@msg +[p1.init1][p1.init2][p1.init3][init20][p1.p1] +CALL p1.p1(); +@msg +[p1.init1][p1.init2][p1.init3][init20][p1.p1][p1.p1] +SELECT p1.f1(); +p1.f1() +[p1.init1][p1.init2][p1.init3][init20][p1.p1][p1.p1][p1.f1] +SELECT p1.f1(); +p1.f1() +[p1.init1][p1.init2][p1.init3][init20][p1.p1][p1.p1][p1.f1][p1.f1] +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +[p1.init1][p1.init2][p1.init3][init20][p1.f1] +CALL p1.p1(); +@msg +[p1.init1][p1.init2][p1.init3][init20][p1.f1][p1.p1] +SELECT p1.f1(); +p1.f1() +[p1.init1][p1.init2][p1.init3][init20][p1.f1][p1.p1][p1.f1] +CALL p1.p1(); +@msg +[p1.init1][p1.init2][p1.init3][init20][p1.f1][p1.p1][p1.f1][p1.p1] +DROP PACKAGE p1; +DROP PROCEDURE init20; +# +# EXECUTE IMMEDIATE in the package initialization section +# +SET @a=1000; +CREATE TABLE t1 AS SELECT 10 AS a; +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; +FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN +EXECUTE IMMEDIATE 'SELECT MAX(a) FROM t1 INTO @a'; +END; +$$ +CALL p1.p1(); +@a +11 +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1.p1(); +@a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +ERROR 0A000: Dynamic SQL is not allowed in stored function or trigger +DROP PACKAGE p1; +DROP TABLE t1; +# +# A package with an initialization section, loading table data into a user variable +# +SET @a=1000; +CREATE TABLE t1 AS SELECT 10 AS a; +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; +FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN +SELECT MAX(a) FROM t1 INTO @a; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1.p1(); +@a +11 +CALL p1.p1(); +@a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +DROP PACKAGE p1; +DROP TABLE t1; +# +# A package with an initialization section producing an error +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS BEGIN SELECT 'This is p1' AS msg; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +BEGIN +SELECT 1 FROM t1 INTO @a; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1.p1(); +ERROR 42S02: Table 'test.t1' doesn't exist +SELECT p1.f1(); +ERROR 42S02: Table 'test.t1' doesn't exist +# sp-cache-invalidate +SELECT p1.f1(); +ERROR 42S02: Table 'test.t1' doesn't exist +CALL p1.p1(); +ERROR 42S02: Table 'test.t1' doesn't exist +SELECT p1.f1(); +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 (a INT) AS SELECT 1; +CALL p1.p1(); +msg +This is p1 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +This is f1 +# sp-cache-invalidate +CALL p1.p1(); +msg +This is p1 +DROP TABLE t1; +DROP PACKAGE p1; +# +# A package with SF-unsafe statements in the initialization section +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS BEGIN SELECT 'This is p1' AS msg; END; +FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +BEGIN +CREATE TABLE IF NOT EXISTS t1 (a INT); +DROP TABLE IF EXISTS t1; +END; +$$ +CALL p1.p1(); +msg +This is p1 +SELECT p1.f1(); +p1.f1() +This is f1 +# sp-cache-invalidate +SELECT p1.f1(); +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger +CALL p1.p1(); +msg +This is p1 +SELECT p1.f1(); +p1.f1() +This is f1 +DROP PACKAGE p1; +# +# MDEV-13139 Package-wide variables in CREATE PACKAGE +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT; +a INT; +PROCEDURE p1 AS +BEGIN +CREATE VIEW v1 AS SELECT a; +END; +END; +$$ +ERROR 42000: Duplicate variable: a +CREATE PACKAGE BODY p1 AS +a INT; +PROCEDURE p1 AS +BEGIN +NULL; +END; +b INT; -- Variables cannot go after routine definitions +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b INT; -- Variables cannot go after routine definitions +END' at line 7 +CREATE PACKAGE BODY p1 AS +a INT; +PROCEDURE p1 AS +BEGIN +CREATE VIEW v1 AS SELECT a; +END; +END; +$$ +ERROR HY000: View's SELECT contains a variable or parameter +CREATE PACKAGE BODY p1 AS +a INT:=NULL; +PROCEDURE p1 AS +BEGIN +SELECT a; +a:=COALESCE(a,0)+100; +SET a=a+1; +END; +FUNCTION f1 RETURN INT AS +BEGIN +RETURN a; +END; +END; +$$ +CALL p1.p1; +a +NULL +CALL p1.p1; +a +101 +CALL p1.p1; +a +202 +SELECT p1.f1(); +p1.f1() +303 +DROP PACKAGE p1; +# +# One package variable with a default value +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT:=10; +PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; +FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +END; +$$ +CALL p1.p1(); +a +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +a +14 +DROP PACKAGE p1; +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a ROW (a INT, b TEXT):=ROW(10,'bbb'); +PROCEDURE p1 AS +BEGIN +a.a:= a.a+1; +a.b:= a.b || 'B'; +SELECT a.a, a.b; +END; +FUNCTION f1 RETURN INT AS BEGIN a.a:= a.a+1; RETURN a.a; END; +END; +$$ +CALL p1.p1(); +a.a a.b +11 bbbB +CALL p1.p1(); +a.a a.b +12 bbbBB +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +a.a a.b +12 bbbB +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +a.a a.b +14 bbbBB +DROP PACKAGE p1; +CREATE TABLE t1 (a INT); +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a t1.a%TYPE:=10; +PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; +FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +END; +$$ +CALL p1.p1(); +a +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +a +14 +DROP PACKAGE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INT, b TEXT); +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a t1%ROWTYPE:=ROW(10,'bbb'); +PROCEDURE p1 AS +BEGIN +a.a:= a.a+1; +a.b:= a.b || 'B'; +SELECT a.a, a.b; +END; +FUNCTION f1 RETURN INT AS BEGIN a.a:= a.a+1; RETURN a.a; END; +END; +$$ +CALL p1.p1(); +a.a a.b +11 bbbB +CALL p1.p1(); +a.a a.b +12 bbbBB +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +a.a a.b +12 bbbB +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +a.a a.b +14 bbbBB +DROP PACKAGE p1; +DROP TABLE t1; +# +# One package variable, set in the package initialization section +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT; +PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; +FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +BEGIN +a:=10; +END; +$$ +CALL p1.p1(); +a +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +CALL p1.p1(); +a +14 +DROP PACKAGE p1; +# +# A package with an initialization section, +# loading table data into a package variable +# +CREATE TABLE t1 AS SELECT 10 AS a; +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT; +PROCEDURE p1 AS BEGIN SET a=a+1; SELECT a; END; +FUNCTION f1 RETURN INT AS BEGIN SET a=a+1; RETURN a; END; +BEGIN +a:=(SELECT MAX(t1.a) FROM t1); +END; +$$ +CALL p1.p1(); +a +11 +CALL p1.p1(); +a +12 +SELECT p1.f1(); +p1.f1() +13 +SELECT p1.f1(); +p1.f1() +14 +# sp-cache-invalidate +SELECT p1.f1(); +p1.f1() +11 +DROP PACKAGE p1; +DROP TABLE t1; +# +# Package variables and XPath +# +CREATE PACKAGE p1 AS +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS +i INT:=0; +xml TEXT:= 'b1b2b3'; +FUNCTION f1 RETURN TEXT AS +BEGIN +SET i=i+1; +RETURN ExtractValue(xml, '/a/b[$i]'); +END; +END; +$$ +SELECT p1.f1(); +p1.f1() +b1 +SELECT p1.f1(); +p1.f1() +b2 +SELECT p1.f1(); +p1.f1() +b3 +DROP PACKAGE p1; +# +# Package variables as OUT routine parameter +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT; +b INT; +c INT:=10; +PROCEDURE p2(a OUT INT) AS +BEGIN +a:=c; +c:=c+1; +END; +PROCEDURE p1 AS +BEGIN +CALL p2(b); +SELECT a,b; +END; +BEGIN +CALL p2(a); +END; +$$ +CALL p1.p1; +a b +10 11 +DROP PACKAGE p1; +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a ROW(a INT, b TEXT); +b ROW(a INT, b TEXT); +c ROW(a INT, b TEXT):=ROW(1,'b'); +PROCEDURE p2(x OUT ROW(a INT,b TEXT)) AS +BEGIN +x:=c; +x.a:=c.a+100; +x.b:=c.b||'X'; +c.a:=c.a+1; +c.b:=c.b||'B'; +END; +PROCEDURE p1 AS +BEGIN +CALL p2(b); +SELECT a.a,a.b,b.a,b.b; +END; +BEGIN +CALL p2(a); +END; +$$ +CALL p1.p1; +a.a a.b b.a b.b +101 bX 102 bBX +DROP PACKAGE p1; +CREATE TABLE t1 (a INT,b TEXT); +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a t1%ROWTYPE; +b t1%ROWTYPE; +c t1%ROWTYPE:=ROW(1,'b'); +PROCEDURE p2(x OUT t1%ROWTYPE) AS +BEGIN +x:=c; +x.a:=c.a+100; +x.b:=c.b||'X'; +c.a:=c.a+1; +c.b:=c.b||'B'; +END; +PROCEDURE p1 AS +BEGIN +CALL p2(b); +SELECT a.a,a.b,b.a,b.b; +END; +BEGIN +CALL p2(a); +END; +$$ +CALL p1.p1; +a.a a.b b.a b.b +101 bX 102 bBX +DROP PACKAGE p1; +DROP TABLE t1; +# +# Package variable fields as OUT routine parameters +# +CREATE TABLE t1 (a INT,b TEXT); +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a t1%ROWTYPE; +x t1%ROWTYPE:=ROW(10,'b'); +PROCEDURE p2(a OUT INT,b OUT TEXT) AS +BEGIN +a:=x.a; +b:=x.b; +x.a:=x.a+1; +x.b:=x.b||'B'; +END; +PROCEDURE p1 AS +BEGIN +CALL p2(a.a, a.b); +SELECT a.a,a.b; +END; +BEGIN +CALL p2(a.a, a.b); +SELECT a.a, a.b; +END; +$$ +CALL p1.p1; +a.a a.b +10 b +a.a a.b +11 bB +DROP PACKAGE p1; +DROP TABLE t1; +# +# Package variables as SELECT INTO targets +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a INT; +b INT; +PROCEDURE p1 AS +BEGIN +SELECT 2 INTO b; +SELECT a,b; +END; +BEGIN +SELECT 1 INTO a; +END; +$$ +CALL p1.p1; +a b +1 2 +DROP PACKAGE p1; +CREATE TABLE t1 (a INT, b TEXT); +INSERT INTO t1 VALUES (10,'b'); +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a t1%ROWTYPE; +b t1%ROWTYPE; +PROCEDURE p1 AS +BEGIN +SELECT * FROM t1 INTO a; +SELECT a.a,a.b; +END; +BEGIN +SELECT * FROM t1 INTO b; +SELECT b.a, b.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +Warning 1287 ' INTO FROM...' instead +CALL p1.p1; +b.a b.b +10 b +a.a a.b +10 b +DROP PACKAGE p1; +DROP TABLE t1; +# +# Package variable fields as SELECT INTO targets +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS +a ROW(a INT, b TEXT); +b ROW(a INT, b TEXT); +PROCEDURE p1 AS +BEGIN +SELECT 20,'x2' INTO b.a,b.b; +SELECT a.a,a.b,b.a,b.b; +END; +BEGIN +SELECT 10,'x1' INTO a.a,a.b; +END; +$$ +CALL p1.p1; +a.a a.b b.a b.b +10 x1 20 x2 +DROP PACKAGE p1; +# +# Recursive package procedure calls +# Makes sure that the non-top sp_head instances created by +# sp_clone_and_link_routine() correctly reproduce the package context: +# package variables, package routines. +# +CREATE PACKAGE p1 AS +PROCEDURE p1(c INT); +END p1; +$$ +CREATE PACKAGE BODY p1 AS +pv1 INT:=10; +FUNCTION f1 RETURN INT AS BEGIN RETURN pv1+100; END; +PROCEDURE p1(c INT) AS +BEGIN +SELECT c, pv1, f1(); +IF c>0 THEN +pv1:=pv1+1; +CALL p1(c-1); +END IF; +END; +END; +$$ +SET max_sp_recursion_depth=5; +CALL p1.p1(5); +c pv1 f1() +5 10 110 +c pv1 f1() +4 11 111 +c pv1 f1() +3 12 112 +c pv1 f1() +2 13 113 +c pv1 f1() +1 14 114 +c pv1 f1() +0 15 115 +SET max_sp_recursion_depth=0; +CALL p1.p1(0); +c pv1 f1() +0 15 115 +CALL p1.p1(1); +c pv1 f1() +1 15 115 +ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine p1.p1 +DROP PACKAGE p1; +# +# Non-reserved keywords as package body variable names +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +END p1; +$$ +CREATE PACKAGE BODY p1 AS +ascii INT:=10; +action INT:=20; +PROCEDURE p1 AS +BEGIN +SELECT ascii, action; +END; +BEGIN +ascii := ascii + 1; +action := action + 1; +END; +$$ +CALL p1.p1; +ascii action +11 21 +DROP PACKAGE p1; +# +# Package routines calling routines of another package +# +CREATE PACKAGE p1 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE p2 AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1.p1' AS msg; +END; +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is p1.f1'; +END; +END; +$$ +CREATE PACKAGE BODY p2 AS +PROCEDURE p1 AS +BEGIN +CALL p1.p1; +END; +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN p1.f1(); +END; +END; +$$ +CALL p1.p1; +msg +This is p1.p1 +CALL p2.p1; +msg +This is p1.p1 +SELECT p1.f1(), p2.f1(); +p1.f1() p2.f1() +This is p1.f1 This is p1.f1 +DROP PACKAGE p2; +DROP PACKAGE p1; +# +# Package names with dot characters +# +CREATE PACKAGE "p1.p1" AS +PROCEDURE p1; +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY "p1.p1" AS +PROCEDURE p1 AS +BEGIN +SELECT 'This is p1' AS msg; +END; +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is f1'; +END; +END; +$$ +CALL "p1.p1"."p1"; +msg +This is p1 +SELECT "p1.p1"."f1"(); +"p1.p1"."f1"() +This is f1 +DROP PACKAGE "p1.p1"; +# +# MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +# +SET sql_mode=ORACLE; +CREATE OR REPLACE PACKAGE pkg1 AS +PROCEDURE p00(); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg1 AS +PROCEDURE p01() AS +BEGIN +SELECT 'This is p01' AS msg; +END; +PROCEDURE p00() AS +BEGIN +CREATE OR REPLACE VIEW v1 AS SELECT 1; +DROP VIEW v1; +CALL p01(); +END; +END; +$$ +CALL pkg1.p00; +msg +This is p01 +DROP PACKAGE pkg1; +CREATE OR REPLACE TABLE t1 (a INT); +CREATE OR REPLACE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=1; +CREATE OR REPLACE PACKAGE pkg1 AS +PROCEDURE p00(); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg1 AS +PROCEDURE p01() AS +BEGIN +SELECT 'This is p01' AS msg; +END; +PROCEDURE p00() AS +BEGIN +DROP TRIGGER tr1; +CALL p01(); +END; +END; +$$ +CALL pkg1.p00; +msg +This is p01 +DROP PACKAGE pkg1; +DROP TABLE t1; +# +# MDEV-17387 MariaDB Server giving wrong error while executing select query from procedure +# +CREATE TABLE t1 ( +CTR varchar(2) NOT NULL, +COR varchar(3) NOT NULL, +DATE datetime NOT NULL, +CHAN varchar(4) NOT NULL, +CNO varchar(20) NOT NULL, +JOBN varchar(18) NOT NULL, +C1 varchar(30) DEFAULT NULL, +C2 varchar(30) DEFAULT NULL, +TIME datetime DEFAULT NULL, +AMT decimal(12,2) DEFAULT NULL, +DT datetime NOT NULL, +pk int(11) NOT NULL, +PRIMARY KEY (pk), +KEY Indx1 (JOBN) +); +CREATE PACKAGE xyz IS +PROCEDURE xyz123(ctr IN VARCHAR2,Jn IN VARCHAR2,R OUT VARCHAR2); +END; +$$ +CREATE OR REPLACE PACKAGE BODY xyz IS +PROCEDURE xyz123( +ctr IN VARCHAR2, +Jn IN VARCHAR2, +R OUT VARCHAR2) +AS +lS NUMBER(10) :=0; +CURSOR cBPD IS +SELECT CTR, COR, DATE, CHAN, CNO, C1, C2, TIME, AMT +FROM t1 WHERE JOBN=Jn; +BEGIN +FOR lbpd IN cBPD +LOOP +lS:=lS+1; +END LOOP; +EXCEPTION +WHEN OTHERS THEN +BEGIN +SELECT SQLERRM; +END; +END; +END $$ +CALL xyz.xyz123(17,18,@R); +DROP PACKAGE xyz; +DROP TABLE t1; +# +# MDEV-28166 sql_mode=ORACLE: fully qualified package function calls do not work: db.pkg.func() +# +SELECT `db `.pkg.func(); +ERROR 42000: Incorrect database name 'db ' +SELECT db.`pkg `.func(); +ERROR 42000: Incorrect routine name 'pkg ' +SELECT db.pkg.`func `(); +ERROR 42000: Incorrect routine name 'func ' +CREATE DATABASE db1; +USE db1; +CREATE PACKAGE pkg1 AS +FUNCTION f1 RETURN TEXT; +FUNCTION f2_db1_pkg1_f1 RETURN TEXT; +FUNCTION f2_pkg1_f1 RETURN TEXT; +FUNCTION f2_f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 +AS +FUNCTION f1 RETURN TEXT IS +BEGIN +RETURN 'This is db1.pkg1.f1'; +END; +FUNCTION f2_db1_pkg1_f1 RETURN TEXT IS +BEGIN +RETURN db1.pkg1.f1(); +END; +FUNCTION f2_pkg1_f1 RETURN TEXT IS +BEGIN +RETURN pkg1.f1(); +END; +FUNCTION f2_f1 RETURN TEXT IS +BEGIN +RETURN f1(); +END; +END; +$$ +USE db1; +SELECT pkg1.f2_db1_pkg1_f1(); +pkg1.f2_db1_pkg1_f1() +This is db1.pkg1.f1 +SELECT pkg1.f2_pkg1_f1(); +pkg1.f2_pkg1_f1() +This is db1.pkg1.f1 +SELECT pkg1.f2_f1(); +pkg1.f2_f1() +This is db1.pkg1.f1 +SELECT db1.pkg1.f2_db1_pkg1_f1(); +db1.pkg1.f2_db1_pkg1_f1() +This is db1.pkg1.f1 +SELECT db1.pkg1.f2_pkg1_f1(); +db1.pkg1.f2_pkg1_f1() +This is db1.pkg1.f1 +SELECT db1.pkg1.f2_f1(); +db1.pkg1.f2_f1() +This is db1.pkg1.f1 +USE test; +SELECT db1.pkg1.f2_db1_pkg1_f1(); +db1.pkg1.f2_db1_pkg1_f1() +This is db1.pkg1.f1 +SELECT db1.pkg1.f2_pkg1_f1(); +db1.pkg1.f2_pkg1_f1() +This is db1.pkg1.f1 +SELECT db1.pkg1.f2_f1(); +db1.pkg1.f2_f1() +This is db1.pkg1.f1 +DROP DATABASE db1; +CREATE DATABASE db1; +CREATE DATABASE db2; +CREATE PACKAGE db1.pkg1 AS +FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY db1.pkg1 AS +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is db1.pkg1.f1'; +END; +END; +$$ +CREATE PACKAGE db2.pkg1 AS +FUNCTION f1 RETURN TEXT; +FUNCTION var1 RETURN TEXT; +FUNCTION var2 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY db2.pkg1 AS +m_var1 TEXT; +m_var2 TEXT; +FUNCTION f1 RETURN TEXT AS +BEGIN +RETURN 'This is db2.pkg1.f1'; +END; +FUNCTION var1 RETURN TEXT AS +BEGIN +RETURN m_var1; +END; +FUNCTION var2 RETURN TEXT AS +BEGIN +RETURN m_var2; +END; +BEGIN +m_var1:= db1.pkg1.f1(); +m_var2:= db2.pkg1.f1(); +END; +$$ +SELECT db2.pkg1.var1(), db2.pkg1.var2(); +db2.pkg1.var1() db2.pkg1.var2() +This is db1.pkg1.f1 This is db2.pkg1.f1 +DROP DATABASE db1; +DROP DATABASE db2; +CREATE PACKAGE pkg1 AS +FUNCTION f1(a TEXT) RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS +FUNCTION f1(a TEXT) RETURN TEXT AS +BEGIN +RETURN a; +END; +END; +$$ +SELECT test.pkg1.f1('xxx'); +test.pkg1.f1('xxx') +xxx +SELECT test.pkg1.f1('xxx' AS a); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS a)' at line 1 +DROP PACKAGE pkg1; +# +# MDEV-19328 sql_mode=ORACLE: Package function in VIEW +# +SET sql_mode=ORACLE; +CREATE PACKAGE test1 AS +FUNCTION f_test RETURN number; +END test1; +$$ +CREATE PACKAGE BODY test1 +AS +FUNCTION f_test RETURN NUMBER IS +BEGIN +RETURN 1; +END; +END test1; +$$ +SET sql_mode=ORACLE; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test1.f_test(); +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE VIEW "v_test" AS select 1 AS "c1" from DUAL where 1 = "test"."test1"."f_test"() +character_set_client latin1 +collation_connection latin1_swedish_ci +SET sql_mode=DEFAULT; +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_test` AS select 1 AS `c1` from DUAL where 1 = `test`.`test1`.`f_test`() +character_set_client latin1 +collation_connection latin1_swedish_ci +DROP VIEW v_test; +SET sql_mode=DEFAULT; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test1.f_test(); +ERROR 42000: FUNCTION test1.f_test does not exist +SET sql_mode=ORACLE; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test.test1.f_test(); +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE VIEW "v_test" AS select 1 AS "c1" from DUAL where 1 = "test"."test1"."f_test"() +character_set_client latin1 +collation_connection latin1_swedish_ci +SET sql_mode=DEFAULT; +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_test` AS select 1 AS `c1` from DUAL where 1 = `test`.`test1`.`f_test`() +character_set_client latin1 +collation_connection latin1_swedish_ci +DROP VIEW v_test; +SET sql_mode=DEFAULT; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test.test1.f_test(); +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_test` AS select 1 AS `c1` from DUAL where 1 = `test`.`test1`.`f_test`() +character_set_client latin1 +collation_connection latin1_swedish_ci +SET sql_mode=ORACLE; +SELECT * FROM v_test; +c1 +1 +SHOW CREATE VIEW v_test; +View v_test +Create View CREATE VIEW "v_test" AS select 1 AS "c1" from DUAL where 1 = "test"."test1"."f_test"() +character_set_client latin1 +collation_connection latin1_swedish_ci +DROP VIEW v_test; +SET sql_mode=ORACLE; +DROP PACKAGE test1; +# +# MDEV-19804 sql_mode=ORACLE: call procedure in packages +# +CALL `db1 `.pkg.p; +ERROR 42000: Incorrect database name 'db1 ' +CALL db1.`pkg `.p; +ERROR 42000: Incorrect routine name 'pkg ' +CALL db1.pkg.`p `; +ERROR 42000: Incorrect routine name 'p ' +SET sql_mode=ORACLE; +CREATE PACKAGE pkg1 as +PROCEDURE p1(); +END; +$$ +CREATE PACKAGE BODY pkg1 as +PROCEDURE p1() as +BEGIN +SELECT 'test-function' AS c1; +END; +END; +$$ +CALL pkg1.p1; +c1 +test-function +CALL test.pkg1.p1; +c1 +test-function +SET sql_mode=DEFAULT; +CALL test.pkg1.p1; +c1 +test-function +SET sql_mode=ORACLE; +BEGIN +CALL pkg1.p1; +CALL test.pkg1.p1; +END +$$ +c1 +test-function +c1 +test-function +BEGIN +pkg1.p1; +test.pkg1.p1; +END +$$ +c1 +test-function +c1 +test-function +DROP PACKAGE pkg1; +CREATE DATABASE db1; +CREATE PACKAGE db1.pkg1 AS +PROCEDURE p1(a OUT TEXT); +END; +$$ +CREATE PACKAGE BODY db1.pkg1 AS +PROCEDURE p1(a OUT TEXT) AS +BEGIN +a:= 'This is db1.pkg1.p1'; +END; +END; +$$ +CREATE DATABASE db2; +CREATE PACKAGE db2.pkg1 AS +FUNCTION var1 RETURN TEXT; +PROCEDURE p1(a OUT TEXT); +PROCEDURE p2_db1_pkg1_p1; +END; +$$ +CREATE PACKAGE BODY db2.pkg1 AS +m_var1 TEXT; +FUNCTION var1 RETURN TEXT AS +BEGIN +RETURN m_var1; +END; +PROCEDURE p1(a OUT TEXT) AS +BEGIN +a:= 'This is db2.pkg1.p1'; +END; +PROCEDURE p2_db1_pkg1_p1 AS +a TEXT; +BEGIN +db1.pkg1.p1(a); +SELECT a; +END; +BEGIN +db1.pkg1.p1(m_var1); +END; +$$ +SELECT db2.pkg1.var1(); +db2.pkg1.var1() +This is db1.pkg1.p1 +CALL db2.pkg1.p2_db1_pkg1_p1; +a +This is db1.pkg1.p1 +DROP DATABASE db1; +DROP DATABASE db2; +# +# MDEV-29370 Functions in packages are slow and seems to ignore deterministic +# +SET SQL_MODE=ORACLE; +CREATE TABLE t1 (c1 CHAR(1)); +CREATE FUNCTION f1_deterministic() +RETURN CHAR(1) +DETERMINISTIC +IS +BEGIN +RETURN 'X'; +END; +// +CREATE FUNCTION f2_not_deterministic() +RETURN CHAR(1) +IS +BEGIN +RETURN 'X'; +END; +// +CREATE PACKAGE pkg1 +IS +PROCEDURE t1_populate(numrows INTEGER); +FUNCTION f3_deterministic() RETURN CHAR(1) DETERMINISTIC; +FUNCTION f4_not_deterministic() RETURN CHAR(1); +END; +// +CREATE PACKAGE BODY pkg1 +IS +PROCEDURE t1_populate(numrounds INTEGER) +IS +i INTEGER; +BEGIN +INSERT INTO t1 VALUES('Y'); +FOR i IN 1..numrounds LOOP +INSERT INTO t1 SELECT * FROM t1; +END LOOP; +END; +FUNCTION f3_deterministic() RETURN CHAR(1) DETERMINISTIC COMMENT 'xxx' + IS +BEGIN +RETURN 'X'; +END; +FUNCTION f4_not_deterministic() RETURN CHAR(1) +IS +BEGIN +RETURN 'X'; +END; +END; +// +CALL pkg1.t1_populate(3); +EXPLAIN EXTENDED SELECT 'Deterministic function', COUNT(*) FROM t1 WHERE c1 = f1_deterministic(); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select 'Deterministic function' AS "Deterministic function",count(0) AS "COUNT(*)" from "test"."t1" where "test"."t1"."c1" = ("f1_deterministic"()) +EXPLAIN EXTENDED SELECT 'Non-deterministic function', COUNT(*) FROM t1 WHERE c1 = f2_not_deterministic(); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select 'Non-deterministic function' AS "Non-deterministic function",count(0) AS "COUNT(*)" from "test"."t1" where "test"."t1"."c1" = "f2_not_deterministic"() +EXPLAIN EXTENDED SELECT 'Deterministic package function', COUNT(*) FROM t1 WHERE c1 = pkg1.f3_deterministic(); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select 'Deterministic package function' AS "Deterministic package function",count(0) AS "COUNT(*)" from "test"."t1" where "test"."t1"."c1" = ("test"."pkg1"."f3_deterministic"()) +EXPLAIN EXTENDED SELECT 'Non-deterministic package function', COUNT(*) FROM t1 WHERE c1 = pkg1.f4_not_deterministic(); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select 'Non-deterministic package function' AS "Non-deterministic package function",count(0) AS "COUNT(*)" from "test"."t1" where "test"."t1"."c1" = "test"."pkg1"."f4_not_deterministic"() +DROP TABLE t1; +DROP FUNCTION f1_deterministic; +DROP FUNCTION f2_not_deterministic; +DROP PACKAGE pkg1; diff --git a/mysql-test/suite/compat/oracle/r/sp-param.result b/mysql-test/suite/compat/oracle/r/sp-param.result new file mode 100644 index 00000000..bb415bd7 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-param.result @@ -0,0 +1,423 @@ +SET sql_mode=ORACLE; +# +# MDEV-10596 Allow VARCHAR and VARCHAR2 without length as a data type of routine parameters and in RETURN clause +# +CREATE FUNCTION f1(param CHAR) RETURN CHAR AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param CHAR) RETURN varchar(2000) CHARSET latin1 COLLATE latin1_swedish_ci +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',2000)));; +LENGTH(f1(REPEAT('a',2000))) +2000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',2000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(2000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param NCHAR) RETURN NCHAR AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param NCHAR) RETURN varchar(2000) CHARSET utf8mb3 COLLATE utf8mb3_general_ci +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',2000)));; +LENGTH(f1(REPEAT('a',2000))) +2000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',2000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(2000) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param BINARY) RETURN BINARY AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param BINARY) RETURN varbinary(2000) +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',2000)));; +LENGTH(f1(REPEAT('a',2000))) +2000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',2000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(2000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param VARCHAR) RETURN VARCHAR AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param VARCHAR) RETURN varchar(4000) CHARSET latin1 COLLATE latin1_swedish_ci +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',4000)));; +LENGTH(f1(REPEAT('a',4000))) +4000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',4000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(4000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param VARCHAR2) RETURN VARCHAR2 AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param VARCHAR2) RETURN varchar(4000) CHARSET latin1 COLLATE latin1_swedish_ci +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',4000)));; +LENGTH(f1(REPEAT('a',4000))) +4000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',4000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(4000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param NVARCHAR) RETURN NVARCHAR AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param NVARCHAR) RETURN varchar(4000) CHARSET utf8mb3 COLLATE utf8mb3_general_ci +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',4000)));; +LENGTH(f1(REPEAT('a',4000))) +4000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',4000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varchar(4000) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param VARBINARY) RETURN VARBINARY AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param VARBINARY) RETURN varbinary(4000) +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',4000)));; +LENGTH(f1(REPEAT('a',4000))) +4000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',4000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(4000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; +CREATE FUNCTION f1(param RAW) RETURN RAW AS BEGIN RETURN param; END;; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT CREATE DEFINER="root"@"localhost" FUNCTION "f1"(param RAW) RETURN varbinary(4000) +AS BEGIN RETURN param; END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT LENGTH(f1(REPEAT('a',4000)));; +LENGTH(f1(REPEAT('a',4000))) +4000 +CREATE TABLE t1 AS SELECT f1(REPEAT('a',4000)) AS a;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "a" varbinary(4000) DEFAULT NULL +) +DROP TABLE t1; +DROP FUNCTION f1; + +MDEV-13919 sql_mode=ORACLE: Derive length of VARCHAR SP parameters with no length from actual parameters + +set sql_mode= 'oracle,strict_trans_tables'; +CREATE OR REPLACE PROCEDURE p1(pinout INOUT varchar, pin IN varchar) +AS +BEGIN +pinout:=pin; +END; +/ +call p1(@w,'0123456789') +/ +declare w varchar(10); +begin +call p1(w,'0123456789'); +end; +/ +declare w varchar(5); +begin +call p1(w,'0123456789'); +end; +/ +ERROR 22001: Data too long for column 'pinout' at row 0 +declare w varchar(20); +begin +w:='aaa'; +call p1(w,'0123456789'); +end; +/ +declare w varchar(8); +begin +w:='aaa'; +call p1(w,'0123456789'); +end; +/ +ERROR 22001: Data too long for column 'pinout' at row 0 +declare str varchar(6000); +pout varchar(6000); +begin +str:=lpad('x',6000,'y'); +call p1(pout,str); +select length(pout); +end; +/ +length(pout) +6000 +declare str varchar(6000); +pout varchar(4000); +begin +str:=lpad('x',6000,'y'); +call p1(pout,str); +select length(pout); +end; +/ +ERROR 22001: Data too long for column 'pinout' at row 0 +declare str varchar(40000); +pout varchar(60000); +begin +str:=lpad('x',40000,'y'); +call p1(pout,str); +select length(pout); +end; +/ +length(pout) +40000 +declare str text(80000); +pout text(80000); +begin +str:=lpad('x',80000,'y'); +call p1(pout,str); +select length(pout); +end; +/ +ERROR 22001: Data too long for column 'pin' at row 0 +declare str text(80000); +pout text(80000); +begin +str:=lpad('x',60000,'y'); +call p1(pout,str); +select length(pout); +end; +/ +length(pout) +60000 +drop procedure p1 +/ +SET sql_mode=ORACLE; +CREATE PROCEDURE p1(pinout INOUT varchar, pin IN varchar) +AS +BEGIN +pinout:=pin; +END; +/ +CREATE PROCEDURE p2(len INT) +AS +pinout VARCHAR(10); +pin VARCHAR(30); +BEGIN +pin:= REPEAT('x', len); +p1(pinout, pin); +SELECT LENGTH(pinout); +END; +/ +CALL p2(10); +LENGTH(pinout) +10 +CALL p2(11); +LENGTH(pinout) +10 +Warnings: +Warning 1265 Data truncated for column 'pinout' at row 0 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +SET sql_mode=ORACLE; +CREATE FUNCTION f1(pin VARCHAR, padlen INT) RETURN TEXT +AS +BEGIN +pin:=LPAD(pin, padlen); +RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT :='x'; +BEGIN +SELECT LENGTH(f1(str,padlen)); +END; +/ +CALL p2(65535); +LENGTH(f1(str,padlen)) +65532 +Warnings: +Warning 1265 Data truncated for column 'pin' at row 0 +CALL p2(65536); +LENGTH(f1(str,padlen)) +65532 +Warnings: +Warning 1265 Data truncated for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP FUNCTION f1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE PROCEDURE p1(pinout INOUT VARCHAR CHARACTER SET utf8, +pin IN VARCHAR CHARACTER SET utf8) +AS +BEGIN +pinout:=pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str VARCHAR(40000) CHARACTER SET latin1; +pout VARCHAR(60000) CHARACTER SET latin1; +BEGIN +str:=lpad('x',padlen,'y'); +p1(pout,str); +SELECT length(pout); +END; +/ +CALL p2(21844); +length(pout) +21844 +CALL p2(21845); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(21846); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP PROCEDURE p1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE PROCEDURE p1(pinout INOUT VARCHAR CHARACTER SET utf8, +pin IN VARCHAR CHARACTER SET utf8) +AS +BEGIN +pinout:=pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT CHARACTER SET utf8; +pout TEXT CHARACTER SET utf8; +BEGIN +str:=lpad('x',padlen,'y'); +p1(pout,str); +SELECT length(pout); +END; +/ +CALL p2(21844); +length(pout) +21844 +CALL p2(21845); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(21846); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP PROCEDURE p1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET latin1, padlen INT) RETURN TEXT +AS +BEGIN +pin:=LPAD(pin, padlen); +RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT CHARACTER SET latin1 :='x'; +BEGIN +SELECT LENGTH(f1(str,padlen)); +END; +/ +CALL p2(65532); +LENGTH(f1(str,padlen)) +65532 +CALL p2(65533); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65534); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65535); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65536); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP FUNCTION f1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET utf8, padlen INT) RETURN TEXT +AS +BEGIN +pin:=LPAD(pin, padlen); +RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT CHARACTER SET utf8 := 'x'; +BEGIN +SELECT LENGTH(f1(str,padlen)); +END; +/ +CALL p2(21844); +LENGTH(f1(str,padlen)) +21844 +CALL p2(21845); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(21846); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP FUNCTION f1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET utf8, padlen INT) RETURN TEXT +AS +BEGIN +pin:=LPAD(pin, padlen); +RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT CHARACTER SET latin1 := 'x'; +BEGIN +SELECT LENGTH(f1(str,padlen)); +END; +/ +CALL p2(21844); +LENGTH(f1(str,padlen)) +21844 +CALL p2(21845); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(21846); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP FUNCTION f1; +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET latin1, padlen INT) RETURN TEXT +AS +BEGIN +pin:=LPAD(pin, padlen); +RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS +str TEXT CHARACTER SET utf8 := 'x'; +BEGIN +SELECT LENGTH(f1(str,padlen)); +END; +/ +CALL p2(65532); +LENGTH(f1(str,padlen)) +65532 +CALL p2(65533); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65534); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65535); +ERROR 22001: Data too long for column 'pin' at row 0 +CALL p2(65536); +ERROR 22001: Data too long for column 'pin' at row 0 +DROP PROCEDURE p2; +DROP FUNCTION f1; diff --git a/mysql-test/suite/compat/oracle/r/sp-row.result b/mysql-test/suite/compat/oracle/r/sp-row.result new file mode 100644 index 00000000..0b23f303 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-row.result @@ -0,0 +1,3129 @@ +SET sql_mode=ORACLE; +# +# MDEV-10914 ROW data type for stored routine variables +# +# +# ROW of ROWs is not supported yet +# +CREATE PROCEDURE p1() +AS +a ROW(a ROW(a INT)); +BEGIN +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ROW(a INT)); +BEGIN +END' at line 3 +# +# Returning the entire ROW parameter from a function +# +CREATE FUNCTION f1(a ROW(a INT, b INT)) RETURN INT +AS +BEGIN +RETURN a; +END; +$$ +SELECT f1(ROW(10,20)); +ERROR HY000: Cannot cast 'row' as 'int' in assignment of `f1(ROW(10,20))` +DROP FUNCTION f1; +# +# ROW as an SP parameter +# +CREATE FUNCTION f1(a ROW(a INT,b INT)) RETURN INT +AS +BEGIN +RETURN a.b; +END; +$$ +CREATE PROCEDURE p1() +AS +a ROW(a INT,b INT):=(11,21); +BEGIN +SELECT f1(a); +END; +$$ +SELECT f1(ROW(10,20)); +f1(ROW(10,20)) +20 +SELECT f1(10); +ERROR 21000: Operand should contain 2 column(s) +SELECT f1(ROW(10,20,30)); +ERROR 21000: Operand should contain 2 column(s) +CALL p1(); +f1(a) +21 +DROP PROCEDURE p1; +DROP FUNCTION f1; +CREATE PROCEDURE p1(a ROW(a INT,b INT)) +AS +BEGIN +SELECT a.a, a.b; +END; +$$ +CALL p1(ROW(10,20)); +a.a a.b +10 20 +CALL p1(10); +ERROR 21000: Operand should contain 2 column(s) +CALL p1(ROW(10,20,30)); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +# +# ROW as an SP OUT parameter +# +CREATE PROCEDURE p1(a OUT ROW(a INT,b INT)) +AS +BEGIN +a.a:=10; +a.b:=20; +END; +$$ +CREATE PROCEDURE p2 +AS +a ROW(a INT,b INT):=(11,21); +BEGIN +CALL p1(a); +SELECT a.a,a.b; +END; +$$ +CALL p2(); +a.a a.b +10 20 +DROP PROCEDURE p2; +DROP PROCEDURE p1; +# +# ROW as an SP return value is not supported yet +# +CREATE FUNCTION p1() RETURN ROW(a INT) +AS +BEGIN +RETURN NULL; +END; +$$ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ROW(a INT) +AS +BEGIN +RETURN NULL; +END' at line 1 +# +# Diplicate row field +# +CREATE PROCEDURE p1() +AS +a ROW (a INT, a DOUBLE); +BEGIN +SELECT a.a; +END; +$$ +ERROR 42S21: Duplicate column name 'a' +# +# Bad scalar default value +# +CREATE PROCEDURE p1() +AS +a ROW (a INT, b DOUBLE):= 1; +BEGIN +SELECT a.a; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +# +# Bad ROW default value with a wrong number of fields +# +CREATE PROCEDURE p1() +AS +a ROW (a INT, b DOUBLE):= ROW(1,2,3); +BEGIN +SELECT a.a; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +# +# Scalar variable vs table alias cause no ambiguity +# +CREATE PROCEDURE p1() +AS +a INT; +BEGIN +-- a.x is a table column here (not a row variable field) +SELECT a.x FROM a; +SELECT a.x FROM t1 a; +END; +$$ +DROP PROCEDURE p1; +# +# Using the entire ROW variable in select list +# +CREATE PROCEDURE p1() +AS +a ROW (a INT); +BEGIN +SELECT a; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT a; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +# +# Using the entire ROW variable in functions +# +CREATE PROCEDURE p1() +AS +a ROW (a INT); +BEGIN +SELECT COALESCE(a); +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT COALESCE(a); +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a ROW (a INT); +BEGIN +SELECT a+1; +END; +$$ +CALL p1(); +ERROR HY000: Illegal parameter data types row and int for operation '+' +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT a+1; +END; +$$ +CALL p1(); +ERROR HY000: Illegal parameter data types row and int for operation '+' +DROP PROCEDURE p1; +# +# Comparing the entire ROW to a scalar value +# +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT a=1; +END; +$$ +CALL p1(); +ERROR HY000: Illegal parameter data types row and int for operation '=' +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT 1=a; +END; +$$ +CALL p1(); +ERROR HY000: Illegal parameter data types int and row for operation '=' +DROP PROCEDURE p1; +# +# Passing the entire ROW to a stored function +# +CREATE FUNCTION f1(a INT) RETURN INT +AS +BEGIN +RETURN a; +END; +$$ +CREATE PROCEDURE p1() +AS +a ROW (a INT,b INT); +BEGIN +SELECT f1(a); +END; +$$ +CALL p1(); +ERROR HY000: Cannot cast 'row' as 'int' in assignment of `a` +DROP PROCEDURE p1; +DROP FUNCTION f1; +CREATE FUNCTION f1(a INT) RETURN INT +AS +BEGIN +RETURN a; +END; +$$ +CREATE PROCEDURE p1() +AS +a ROW (a INT); +BEGIN +SELECT f1(a); +END; +$$ +CALL p1(); +ERROR HY000: Cannot cast 'row' as 'int' in assignment of `a` +DROP PROCEDURE p1; +DROP FUNCTION f1; +# +# Assigning a scalar value to a ROW variable with 1 column +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec ROW(a INT); +BEGIN +rec:=1; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +# +# Assigning a scalar value to a ROW variable with 2 columns +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +rec:=1; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +# +# Assigning a ROW value to a ROW variable with different number of columns +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +rec:=ROW(1,2,3); +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +# +# Returning the entire ROW from a function is not supported yet +# This syntax would be needed: SELECT f1().x FROM DUAL; +# +CREATE FUNCTION f1(a INT) RETURN INT +AS +rec ROW(a INT); +BEGIN +RETURN rec; +END; +$$ +SELECT f1(10); +ERROR HY000: Cannot cast 'row' as 'int' in assignment of `f1(10)` +DROP FUNCTION f1; +# +# Using the entire ROW in SELECT..CREATE +# +CREATE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +CREATE TABLE t1 AS SELECT rec; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 1 column(s) +DROP PROCEDURE p1; +# +# Using the entire ROW in LIMIT +# +CREATE PROCEDURE p1() +AS +rec ROW(a INT); +BEGIN +rec.a:= '10'; +SELECT * FROM t1 LIMIT rec; +END; +$$ +ERROR HY000: A variable of a non-integer based type in LIMIT clause +# +# Setting ROW fields using a SET command +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec ROW(a INT,b DOUBLE,c VARCHAR(10)); +a INT; +BEGIN +SET @a= 10, rec.a=10, rec.b=20, rec.c= 'test', a= 5; +SELECT rec.a, rec.b, rec.c, a; +END; +$$ +CALL p1(); +rec.a rec.b rec.c a +10 20 test 5 +DROP PROCEDURE p1; +# +# Assigning a ROW variable from a ROW value +# +CREATE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +rec:=ROW(1,2); +SELECT rec.a, rec.b; +END; +$$ +CALL p1(); +rec.a rec.b +1 2 +DROP PROCEDURE p1; +# +# Assigning a ROW variable from another ROW value +# +CREATE PROCEDURE p1 +AS +rec1 ROW(a INT,b INT); +rec2 ROW(a INT,b INT); +BEGIN +rec1:=ROW(1,2); +rec2:=rec1; +SELECT rec2.a, rec2.b; +END; +$$ +CALL p1(); +rec2.a rec2.b +1 2 +DROP PROCEDURE p1; +# +# Comparing a ROW variable to a ROW() function +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec ROW(a INT,b INT); +BEGIN +rec.a:= 1; +rec.b:= 2; +SELECT rec=(0,0), rec=ROW(0,0), (0,0)=rec, ROW(0,0)=rec; +SELECT rec=(1,2), rec=ROW(1,2), (1,2)=rec, ROW(1,2)=rec; +SELECT rec=(NULL,0), rec=ROW(NULL,0); +SELECT rec=(NULL,2), rec=ROW(NULL,2); +SELECT rec<>(0,0), rec<>ROW(0,0); +SELECT rec<>(1,2), rec<>ROW(1,2); +SELECT rec<>(NULL,0), rec<>ROW(NULL,0); +SELECT rec<>(NULL,2), rec<>ROW(NULL,2); +SELECT rec IN ((0,0)), rec IN (ROW(0,0)); +SELECT rec IN ((1,2)), rec IN (ROW(1,2)); +SELECT rec IN ((0,NULL),(1,2)); +SELECT rec NOT IN ((0,NULL),(1,1)); +SELECT rec NOT IN ((1,NULL),(1,1)); +END; +$$ +CALL p1(); +rec=(0,0) rec=ROW(0,0) (0,0)=rec ROW(0,0)=rec +0 0 0 0 +rec=(1,2) rec=ROW(1,2) (1,2)=rec ROW(1,2)=rec +1 1 1 1 +rec=(NULL,0) rec=ROW(NULL,0) +0 0 +rec=(NULL,2) rec=ROW(NULL,2) +NULL NULL +rec<>(0,0) rec<>ROW(0,0) +1 1 +rec<>(1,2) rec<>ROW(1,2) +0 0 +rec<>(NULL,0) rec<>ROW(NULL,0) +1 1 +rec<>(NULL,2) rec<>ROW(NULL,2) +NULL NULL +rec IN ((0,0)) rec IN (ROW(0,0)) +0 0 +rec IN ((1,2)) rec IN (ROW(1,2)) +1 1 +rec IN ((0,NULL),(1,2)) +1 +rec NOT IN ((0,NULL),(1,1)) +1 +rec NOT IN ((1,NULL),(1,1)) +NULL +DROP PROCEDURE p1; +# +# Comparing a ROW variable to another ROW variable +# +CREATE OR REPLACE PROCEDURE p1 +AS +rec1,rec2,rec3 ROW(a INT,b INT); +BEGIN +rec1.a:= 1; +rec1.b:= 2; +rec2.a:= 11; +rec2.b:= 12; +rec3.a:= 11; +rec3.b:= 12; +SELECT rec1=rec2, rec2=rec1, rec2=rec3, rec3=rec2; +END; +$$ +CALL p1(); +rec1=rec2 rec2=rec1 rec2=rec3 rec3=rec2 +0 0 1 1 +DROP PROCEDURE p1; +# +# Referencing a non-existing row variable +# +CREATE PROCEDURE p1() +AS +BEGIN +SET a.b=1; +END; +$$ +ERROR HY000: Unknown structured system variable or ROW routine variable 'a' +CREATE PROCEDURE p1() +AS +BEGIN +a.b:=1; +END; +$$ +ERROR HY000: Unknown structured system variable or ROW routine variable 'a' +# +# Referencing a non-existing row field +# +CREATE PROCEDURE p1() +AS +a ROW(a INT,b INT); +BEGIN +SELECT a.c FROM t1; +END; +$$ +ERROR HY000: Row variable 'a' does not have a field 'c' +# +# ROW and scalar variables with the same name shadowing each other +# +CREATE PROCEDURE p1() +AS +a ROW(a INT); +BEGIN +a.a:=100; +DECLARE +a INT:= 200; +BEGIN +SELECT a; +DECLARE +a ROW(a INT); +BEGIN +a.a:=300; +SELECT a.a; +END; +SELECT a; +END; +SELECT a.a; +END; +$$ +CALL p1(); +a +200 +a.a +300 +a +200 +a.a +100 +DROP PROCEDURE p1; +# +# ROW with good default values +# +CREATE PROCEDURE p1() +AS +a ROW(a INT,b INT):= (10,20); +b ROW(a INT,b INT):= (11,21); +c ROW(a INT,b INT):= a; +BEGIN +SELECT a.a, a.b, b.a, b.b, c.a, c.b FROM DUAL; +END; +$$ +CALL p1; +a.a a.b b.a b.b c.a c.b +10 20 11 21 10 20 +DROP PROCEDURE p1; +# +# ROW in WHERE clause +# +CREATE TABLE t1 (a INT,b INT); +INSERT INTO t1 VALUES (10,20); +CREATE PROCEDURE p1() +AS +rec ROW(a INT,b INT):=ROW(10,20); +BEGIN +SELECT * FROM t1 WHERE rec=ROW(a,b); +SELECT * FROM t1 WHERE ROW(a,b)=rec; +SELECT * FROM t1 WHERE rec=ROW(10,20); +SELECT * FROM t1 WHERE ROW(10,20)=rec; +END; +$$ +CALL p1(); +a b +10 20 +a b +10 20 +a b +10 20 +a b +10 20 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# ROW fields in WHERE clause +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +rec ROW(a INT); +BEGIN +rec.a:= 10; +SELECT * FROM t1 WHERE a=rec.a; +END; +$$ +CALL p1(); +a +10 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# ROW fields in HAVING clause +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +rec ROW(a INT); +BEGIN +rec.a:= 10; +SELECT * FROM t1 HAVING a=rec.a; +SELECT * FROM t1 HAVING MIN(a)=rec.a; +END; +$$ +CALL p1(); +a +10 +a +10 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# ROW fields in LIMIT clause +# +CREATE TABLE t1 (a INT); +SELECT 1 FROM t1 LIMIT t1.a; +ERROR 42000: Undeclared variable: t1 +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +rec ROW(a INT); +BEGIN +rec.a:= 10; +SELECT * FROM t1 LIMIT rec.a; +END; +$$ +CALL p1(); +a +10 +20 +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +rec ROW(a VARCHAR(10)); +BEGIN +rec.a:= '10'; +SELECT * FROM t1 LIMIT rec.a; +END; +$$ +ERROR HY000: A variable of a non-integer based type in LIMIT clause +# +# ROW fields in select list +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +CREATE PROCEDURE p1() +AS +t1 ROW(a INT); +BEGIN +t1.a:= 10; +SELECT t1.a, 'This is the variable t1.a value, rather than the column t1.a' AS comm FROM t1; +SELECT t1.a, t2.a, t1.a+t2.a FROM t1 t2; +END; +$$ +CALL p1(); +t1.a comm +10 This is the variable t1.a value, rather than the column t1.a +10 This is the variable t1.a value, rather than the column t1.a +t1.a a t1.a+t2.a +10 10 20 +10 20 30 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# ROW fields as insert values +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec ROW(a INT, b VARCHAR(10)); +BEGIN +rec.a:= 10; +rec.b:= 'test'; +INSERT INTO t1 VALUES (rec.a, rec.b); +END; +$$ +CALL p1(); +SELECT * FROM t1; +a b +10 test +DROP TABLE t1; +DROP PROCEDURE p1; +# +# ROW fields as SP out parameters +# +CREATE PROCEDURE p1(a OUT INT, b OUT VARCHAR) +AS +BEGIN +a:= 10; +b:= 'test'; +END; +$$ +CREATE PROCEDURE p2 +AS +rec ROW(a INT, b VARCHAR(10)); +BEGIN +CALL p1(rec.a, rec.b); +SELECT rec.a, rec.b; +END; +$$ +CALL p2; +rec.a rec.b +10 test +DROP PROCEDURE p1; +DROP PROCEDURE p2; +# +# ROW fields as dynamic SQL out parameters +# +CREATE PROCEDURE p1(a OUT INT, b OUT VARCHAR) +AS +BEGIN +a:= 20; +b:= 'test-dynamic-sql'; +END; +$$ +CREATE PROCEDURE p2 +AS +rec ROW(a INT, b VARCHAR(30)); +BEGIN +EXECUTE IMMEDIATE 'CALL p1(?,?)' USING rec.a, rec.b; +SELECT rec.a, rec.b; +END; +$$ +CALL p2; +rec.a rec.b +20 test-dynamic-sql +DROP PROCEDURE p1; +DROP PROCEDURE p2; +# +# ROW fields as SELECT..INTO targets +# +CREATE PROCEDURE p1 +AS +rec ROW(a INT, b VARCHAR(10)); +BEGIN +SELECT 10,'test' INTO rec.a,rec.b; +SELECT rec.a, rec.b; +END; +$$ +CALL p1; +rec.a rec.b +10 test +DROP PROCEDURE p1; +# +# Implicit default NULL handling +# +CREATE PROCEDURE p1 +AS +rec ROW(a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,0), e TIME, f DATETIME); +BEGIN +SELECT rec.a, rec.b, rec.c, rec.d, rec.e, rec.f FROM DUAL; +END; +$$ +CALL p1(); +rec.a rec.b rec.c rec.d rec.e rec.f +NULL NULL NULL NULL NULL NULL +DROP PROCEDURE p1; +# +# NULL handling +# +CREATE PROCEDURE p1 +AS +rec1 ROW(a INT, b VARCHAR(10)):=(NULL,NULL); +rec2 ROW(a INT, b VARCHAR(10)):=rec1; +BEGIN +SELECT rec1.a, rec1.b, rec2.a, rec2.b; +rec1:= (10,20); +rec2:= rec1; +SELECT rec1.a, rec1.b, rec2.a, rec2.b; +rec1:= (NULL,20); +rec2:= rec1; +SELECT rec1.a, rec1.b, rec2.a, rec2.b; +rec1:= (10,NULL); +rec2:= rec1; +SELECT rec1.a, rec1.b, rec2.a, rec2.b; +rec1:= (NULL,NULL); +rec2:= rec1; +SELECT rec1.a, rec1.b, rec2.a, rec2.b; +END; +$$ +CALL p1; +rec1.a rec1.b rec2.a rec2.b +NULL NULL NULL NULL +rec1.a rec1.b rec2.a rec2.b +10 20 10 20 +rec1.a rec1.b rec2.a rec2.b +NULL 20 NULL 20 +rec1.a rec1.b rec2.a rec2.b +10 NULL 10 NULL +rec1.a rec1.b rec2.a rec2.b +NULL NULL NULL NULL +DROP PROCEDURE p1; +# +# Testing multiple ROW variable declarations +# This makes sure that fill_field_definitions() is called only once +# per a ROW field, so create length is not converted to internal length +# multiple times. +# +CREATE PROCEDURE p1 +AS +rec1, rec2, rec3 ROW(a VARCHAR(10) CHARACTER SET utf8); +BEGIN +CREATE TABLE t1 AS SELECT rec1.a, rec2.a, rec3.a; +END; +$$ +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "rec1.a" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec2.a" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec3.a" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# INT +# +CREATE PROCEDURE p1() AS var INT; rec ROW(var INT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(1); rec ROW(var INT(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(2); rec ROW(var INT(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(3); rec ROW(var INT(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(4); rec ROW(var INT(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(5); rec ROW(var INT(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(6); rec ROW(var INT(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(7); rec ROW(var INT(7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(8); rec ROW(var INT(8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(9); rec ROW(var INT(9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(10); rec ROW(var INT(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(11); rec ROW(var INT(11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(11) DEFAULT NULL, + "rec.var" int(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(12); rec ROW(var INT(12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(12) DEFAULT NULL, + "rec.var" int(12) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(13); rec ROW(var INT(13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(13) DEFAULT NULL, + "rec.var" int(13) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(14); rec ROW(var INT(14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(14) DEFAULT NULL, + "rec.var" int(14) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(20); rec ROW(var INT(20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(20) DEFAULT NULL, + "rec.var" int(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var INT(21); rec ROW(var INT(21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" int(21) DEFAULT NULL, + "rec.var" int(21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# TINYINT +# +CREATE PROCEDURE p1() AS var TINYINT; rec ROW(var TINYINT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(4) DEFAULT NULL, + "rec.var" tinyint(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(1); rec ROW(var TINYINT(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(4) DEFAULT NULL, + "rec.var" tinyint(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(2); rec ROW(var TINYINT(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(4) DEFAULT NULL, + "rec.var" tinyint(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(3); rec ROW(var TINYINT(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(4) DEFAULT NULL, + "rec.var" tinyint(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(4); rec ROW(var TINYINT(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(4) DEFAULT NULL, + "rec.var" tinyint(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(5); rec ROW(var TINYINT(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(5) DEFAULT NULL, + "rec.var" tinyint(5) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(6); rec ROW(var TINYINT(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(6) DEFAULT NULL, + "rec.var" tinyint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(7); rec ROW(var TINYINT(7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(7) DEFAULT NULL, + "rec.var" tinyint(7) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(8); rec ROW(var TINYINT(8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(8) DEFAULT NULL, + "rec.var" tinyint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(9); rec ROW(var TINYINT(9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(9) DEFAULT NULL, + "rec.var" tinyint(9) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(10); rec ROW(var TINYINT(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(10) DEFAULT NULL, + "rec.var" tinyint(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(11); rec ROW(var TINYINT(11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(11) DEFAULT NULL, + "rec.var" tinyint(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(12); rec ROW(var TINYINT(12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(12) DEFAULT NULL, + "rec.var" tinyint(12) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(13); rec ROW(var TINYINT(13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(13) DEFAULT NULL, + "rec.var" tinyint(13) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(14); rec ROW(var TINYINT(14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(14) DEFAULT NULL, + "rec.var" tinyint(14) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(20); rec ROW(var TINYINT(20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(20) DEFAULT NULL, + "rec.var" tinyint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYINT(21); rec ROW(var TINYINT(21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinyint(21) DEFAULT NULL, + "rec.var" tinyint(21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# SMALLINT +# +CREATE PROCEDURE p1() AS var SMALLINT; rec ROW(var SMALLINT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(1); rec ROW(var SMALLINT(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(2); rec ROW(var SMALLINT(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(3); rec ROW(var SMALLINT(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(4); rec ROW(var SMALLINT(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(5); rec ROW(var SMALLINT(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(6); rec ROW(var SMALLINT(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(6) DEFAULT NULL, + "rec.var" smallint(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(7); rec ROW(var SMALLINT(7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(7) DEFAULT NULL, + "rec.var" smallint(7) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(8); rec ROW(var SMALLINT(8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(8) DEFAULT NULL, + "rec.var" smallint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(9); rec ROW(var SMALLINT(9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(9) DEFAULT NULL, + "rec.var" smallint(9) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(10); rec ROW(var SMALLINT(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(10) DEFAULT NULL, + "rec.var" smallint(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(11); rec ROW(var SMALLINT(11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(11) DEFAULT NULL, + "rec.var" smallint(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(12); rec ROW(var SMALLINT(12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(12) DEFAULT NULL, + "rec.var" smallint(12) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(13); rec ROW(var SMALLINT(13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(13) DEFAULT NULL, + "rec.var" smallint(13) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(14); rec ROW(var SMALLINT(14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(14) DEFAULT NULL, + "rec.var" smallint(14) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(20); rec ROW(var SMALLINT(20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(20) DEFAULT NULL, + "rec.var" smallint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var SMALLINT(21); rec ROW(var SMALLINT(21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" smallint(21) DEFAULT NULL, + "rec.var" smallint(21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# MEDIUMINT +# +CREATE PROCEDURE p1() AS var MEDIUMINT; rec ROW(var MEDIUMINT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(9) DEFAULT NULL, + "rec.var" mediumint(9) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(1); rec ROW(var MEDIUMINT(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(2); rec ROW(var MEDIUMINT(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(3); rec ROW(var MEDIUMINT(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(4); rec ROW(var MEDIUMINT(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(5); rec ROW(var MEDIUMINT(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(6); rec ROW(var MEDIUMINT(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(7); rec ROW(var MEDIUMINT(7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(8); rec ROW(var MEDIUMINT(8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(8) DEFAULT NULL, + "rec.var" mediumint(8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(9); rec ROW(var MEDIUMINT(9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(9) DEFAULT NULL, + "rec.var" mediumint(9) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(10); rec ROW(var MEDIUMINT(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(10) DEFAULT NULL, + "rec.var" mediumint(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(11); rec ROW(var MEDIUMINT(11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(11) DEFAULT NULL, + "rec.var" mediumint(11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(12); rec ROW(var MEDIUMINT(12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(12) DEFAULT NULL, + "rec.var" mediumint(12) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(13); rec ROW(var MEDIUMINT(13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(13) DEFAULT NULL, + "rec.var" mediumint(13) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(14); rec ROW(var MEDIUMINT(14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(14) DEFAULT NULL, + "rec.var" mediumint(14) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(20); rec ROW(var MEDIUMINT(20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(20) DEFAULT NULL, + "rec.var" mediumint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMINT(21); rec ROW(var MEDIUMINT(21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumint(21) DEFAULT NULL, + "rec.var" mediumint(21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# BIGINT +# +CREATE PROCEDURE p1() AS var BIGINT; rec ROW(var BIGINT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(1); rec ROW(var BIGINT(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(2); rec ROW(var BIGINT(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(3); rec ROW(var BIGINT(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(4); rec ROW(var BIGINT(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(5); rec ROW(var BIGINT(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(6); rec ROW(var BIGINT(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(7); rec ROW(var BIGINT(7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(8); rec ROW(var BIGINT(8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(9); rec ROW(var BIGINT(9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(10); rec ROW(var BIGINT(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(11); rec ROW(var BIGINT(11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(12); rec ROW(var BIGINT(12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(13); rec ROW(var BIGINT(13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(14); rec ROW(var BIGINT(14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(20); rec ROW(var BIGINT(20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(20) DEFAULT NULL, + "rec.var" bigint(20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BIGINT(21); rec ROW(var BIGINT(21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" bigint(21) DEFAULT NULL, + "rec.var" bigint(21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# DOUBLE +# +CREATE PROCEDURE p1() AS var DOUBLE; rec ROW(var DOUBLE); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double DEFAULT NULL, + "rec.var" double DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,1); rec ROW(var DOUBLE(30,1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,1) DEFAULT NULL, + "rec.var" double(30,1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,2); rec ROW(var DOUBLE(30,2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,2) DEFAULT NULL, + "rec.var" double(30,2) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,3); rec ROW(var DOUBLE(30,3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,3) DEFAULT NULL, + "rec.var" double(30,3) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,4); rec ROW(var DOUBLE(30,4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,4) DEFAULT NULL, + "rec.var" double(30,4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,5); rec ROW(var DOUBLE(30,5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,5) DEFAULT NULL, + "rec.var" double(30,5) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,6); rec ROW(var DOUBLE(30,6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,6) DEFAULT NULL, + "rec.var" double(30,6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,7); rec ROW(var DOUBLE(30,7)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,7) DEFAULT NULL, + "rec.var" double(30,7) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,8); rec ROW(var DOUBLE(30,8)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,8) DEFAULT NULL, + "rec.var" double(30,8) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,9); rec ROW(var DOUBLE(30,9)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,9) DEFAULT NULL, + "rec.var" double(30,9) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,10); rec ROW(var DOUBLE(30,10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,10) DEFAULT NULL, + "rec.var" double(30,10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,11); rec ROW(var DOUBLE(30,11)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,11) DEFAULT NULL, + "rec.var" double(30,11) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,12); rec ROW(var DOUBLE(30,12)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,12) DEFAULT NULL, + "rec.var" double(30,12) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,13); rec ROW(var DOUBLE(30,13)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,13) DEFAULT NULL, + "rec.var" double(30,13) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,14); rec ROW(var DOUBLE(30,14)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,14) DEFAULT NULL, + "rec.var" double(30,14) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,20); rec ROW(var DOUBLE(30,20)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,20) DEFAULT NULL, + "rec.var" double(30,20) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DOUBLE(30,21); rec ROW(var DOUBLE(30,21)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" double(30,21) DEFAULT NULL, + "rec.var" double(30,21) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# VARCHAR +# +CREATE PROCEDURE p1() AS var CHAR; rec ROW(var CHAR); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" char(1) DEFAULT NULL, + "rec.var" char(1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BINARY; rec ROW(var BINARY); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" binary(1) DEFAULT NULL, + "rec.var" binary(1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var CHAR(1); rec ROW(var CHAR(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" char(1) DEFAULT NULL, + "rec.var" char(1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var CHAR(10); rec ROW(var CHAR(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" char(10) DEFAULT NULL, + "rec.var" char(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var NCHAR(10); rec ROW(var NCHAR(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var BINARY(10); rec ROW(var BINARY(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" binary(10) DEFAULT NULL, + "rec.var" binary(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var VARBINARY(10); rec ROW(var VARBINARY(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" varbinary(10) DEFAULT NULL, + "rec.var" varbinary(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var VARCHAR(10); rec ROW(var VARCHAR(10)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" varchar(10) DEFAULT NULL, + "rec.var" varchar(10) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var VARCHAR(10) CHARACTER SET utf8; rec ROW(var VARCHAR(10) CHARACTER SET utf8); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin; rec ROW(var VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + "rec.var" varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# TIME +# +CREATE PROCEDURE p1() AS var TIME; rec ROW(var TIME); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time DEFAULT NULL, + "rec.var" time DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(1); rec ROW(var TIME(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(1) DEFAULT NULL, + "rec.var" time(1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(2); rec ROW(var TIME(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(2) DEFAULT NULL, + "rec.var" time(2) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(3); rec ROW(var TIME(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(3) DEFAULT NULL, + "rec.var" time(3) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(4); rec ROW(var TIME(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(4) DEFAULT NULL, + "rec.var" time(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(5); rec ROW(var TIME(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(5) DEFAULT NULL, + "rec.var" time(5) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TIME(6); rec ROW(var TIME(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" time(6) DEFAULT NULL, + "rec.var" time(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# DATETIME +# +CREATE PROCEDURE p1() AS var DATETIME; rec ROW(var DATETIME); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime DEFAULT NULL, + "rec.var" datetime DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(1); rec ROW(var DATETIME(1)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(1) DEFAULT NULL, + "rec.var" datetime(1) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(2); rec ROW(var DATETIME(2)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(2) DEFAULT NULL, + "rec.var" datetime(2) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(3); rec ROW(var DATETIME(3)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(3) DEFAULT NULL, + "rec.var" datetime(3) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(4); rec ROW(var DATETIME(4)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(4) DEFAULT NULL, + "rec.var" datetime(4) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(5); rec ROW(var DATETIME(5)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(5) DEFAULT NULL, + "rec.var" datetime(5) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var DATETIME(6); rec ROW(var DATETIME(6)); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" datetime(6) DEFAULT NULL, + "rec.var" datetime(6) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# LOB +# +CREATE PROCEDURE p1() AS var TEXT; rec ROW(var TEXT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" text DEFAULT NULL, + "rec.var" text DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYTEXT; rec ROW(var TINYTEXT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinytext DEFAULT NULL, + "rec.var" tinytext DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMTEXT; rec ROW(var MEDIUMTEXT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumtext DEFAULT NULL, + "rec.var" mediumtext DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var LONGTEXT; rec ROW(var LONGTEXT); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" longtext DEFAULT NULL, + "rec.var" longtext DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TEXT CHARACTER SET utf8; rec ROW(var TEXT CHARACTER SET utf8); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var TINYTEXT CHARACTER SET utf8; rec ROW(var TINYTEXT CHARACTER SET utf8); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" tinytext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" tinytext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var MEDIUMTEXT CHARACTER SET utf8; rec ROW(var MEDIUMTEXT CHARACTER SET utf8); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" mediumtext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" mediumtext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE PROCEDURE p1() AS var LONGTEXT CHARACTER SET utf8; rec ROW(var LONGTEXT CHARACTER SET utf8); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END; +CALL p1(); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "var" longtext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + "rec.var" longtext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# End of MDEV-10914 ROW data type for stored routine variables +# +# +# MDEV-12133 sql_mode=ORACLE: table%ROWTYPE in variable declarations +# +# +# Referring to a table in a non-existing database +# +CREATE PROCEDURE p1() +AS +rec test2.t1%ROWTYPE; +BEGIN +NULL; +END; +$$ +CALL p1(); +ERROR 42S02: Table 'test2.t1' doesn't exist +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CALL p1(); +ERROR 42S02: Table 'test2.t1' doesn't exist +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Referring to a table in the current database +# +CREATE PROCEDURE p1() +AS +rec t1%ROWTYPE; +BEGIN +CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +CALL p1(); +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CALL p1(); +Table Create Table +t2 CREATE TABLE "t2" ( + "rec.a" int(11) DEFAULT NULL, + "rec.b" varchar(10) DEFAULT NULL, + "rec.c" double DEFAULT NULL, + "rec.d" decimal(10,0) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Referring to a table in an explicitly specified database +# +CREATE PROCEDURE p1() +AS +rec test.t1%ROWTYPE; +BEGIN +CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +CALL p1(); +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CALL p1(); +Table Create Table +t2 CREATE TABLE "t2" ( + "rec.a" int(11) DEFAULT NULL, + "rec.b" varchar(10) DEFAULT NULL, + "rec.c" double DEFAULT NULL, + "rec.d" decimal(10,0) DEFAULT NULL +) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Referring to a view in the current database +# +CREATE PROCEDURE p1() +AS +rec v1%ROWTYPE; +BEGIN +CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +CALL p1(); +ERROR 42S02: Table 'test.v1' doesn't exist +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CREATE VIEW v1 AS SELECT * FROM t1; +CALL p1(); +Table Create Table +t2 CREATE TABLE "t2" ( + "rec.a" int(11) DEFAULT NULL, + "rec.b" varchar(10) DEFAULT NULL, + "rec.c" double DEFAULT NULL, + "rec.d" decimal(10,0) DEFAULT NULL +) +DROP VIEW v1; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Referring to a view in an explicitly specified database +# +CREATE PROCEDURE p1() +AS +rec test.v1%ROWTYPE; +BEGIN +CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; +SHOW CREATE TABLE t2; +DROP TABLE t2; +END; +$$ +CALL p1(); +ERROR 42S02: Table 'test.v1' doesn't exist +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CREATE VIEW v1 AS SELECT * FROM t1; +CALL p1(); +Table Create Table +t2 CREATE TABLE "t2" ( + "rec.a" int(11) DEFAULT NULL, + "rec.b" varchar(10) DEFAULT NULL, + "rec.c" double DEFAULT NULL, + "rec.d" decimal(10,0) DEFAULT NULL +) +DROP VIEW v1; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Checking that all table%ROWTYPE fields are NULL by default +# +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +BEGIN +SELECT rec1.a, rec1.b, rec1.c, rec1.d; +END; +$$ +CALL p1(); +rec1.a rec1.b rec1.c rec1.d +NULL NULL NULL NULL +DROP TABLE t1; +DROP PROCEDURE p1; +# +# A table%ROWTYPE variable with a ROW expression as a default +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE DEFAULT ROW(10,'bbb'); +BEGIN +SELECT rec1.a, rec1.b; +END; +$$ +CALL p1(); +rec1.a rec1.b +10 bbb +DROP TABLE t1; +DROP PROCEDURE p1; +# +# A table%ROWTYPE variable with an incompatible ROW expression as a default +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE DEFAULT ROW(10,'bbb','ccc'); +BEGIN +SELECT rec1.a, rec1.b; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# A table%ROWTYPE variable with a ROW variable as a default +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 ROW(a INT, b VARCHAR(10)):= ROW(10,'bbb'); +rec2 t1%ROWTYPE DEFAULT rec1; +BEGIN +SELECT rec2.a, rec2.b; +END; +$$ +CALL p1(); +rec2.a rec2.b +10 bbb +DROP TABLE t1; +DROP PROCEDURE p1; +# +# A ROW variable using a table%ROWTYPE variable as a default +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE := ROW(10,'bbb'); +rec2 ROW(a INT, b VARCHAR(10)):= rec1; +BEGIN +SELECT rec2.a, rec2.b; +END; +$$ +CALL p1(); +rec2.a rec2.b +10 bbb +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Assigning table%ROWTYPE variables with a different column count +# +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE); +CREATE TABLE t2 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +rec2 t2%ROWTYPE; +BEGIN +rec2:=rec1; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +rec2 t2%ROWTYPE; +BEGIN +rec1:=rec2; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 3 column(s) +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Assigning compatible table%ROWTYPE variables (equal number of fields) +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (x INT, y VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +rec2 t2%ROWTYPE; +BEGIN +rec1.a:= 10; +rec1.b:= 'bbb'; +rec2:=rec1; +SELECT rec2.x, rec2.y; +END; +$$ +CALL p1(); +rec2.x rec2.y +10 bbb +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Assigning between incompatible table%ROWTYPE and explicit ROW variables +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +rec2 ROW(x INT,y INT,z INT); +BEGIN +rec2.x:= 10; +rec2.y:= 20; +rec2.z:= 30; +rec1:= rec2; +END; +$$ +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Assigning between compatible table%ROWTYPE and explicit ROW variables +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +rec2 ROW(x INT,y INT); +BEGIN +rec2.x:= 10; +rec2.y:= 20; +rec1:= rec2; +SELECT rec1.a, rec1.b; +rec1.a:= 11; +rec1.b:= 21; +rec2:= rec1; +SELECT rec2.x, rec2.y; +END; +$$ +CALL p1(); +rec1.a rec1.b +10 20 +rec2.x rec2.y +11 21 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Assigning table%ROWTYPE from a ROW expression +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE; +BEGIN +rec1:= ROW(10,20); +SELECT rec1.a, rec1.b; +END; +$$ +CALL p1(); +rec1.a rec1.b +10 20 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Fetching a cursor into a table%ROWTYPE variable with a wrong field count +# +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +CREATE TABLE t2 (a INT, b VARCHAR(10)); +INSERT INTO t1 VALUES (10,'bb1',111.111e2, 12.31); +CREATE PROCEDURE p1() +AS +rec2 t2%ROWTYPE; +CURSOR cur1 IS SELECT * FROM t1; +BEGIN +OPEN cur1; +FETCH cur1 INTO rec2; +CLOSE cur1; +END; +$$ +CALL p1(); +ERROR HY000: Incorrect number of FETCH variables +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Fetching a cursor into a table%ROWTYPE variable +# +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +CREATE TABLE t2 LIKE t1; +INSERT INTO t1 VALUES (10,'bb1',111.111e2, 12.31); +INSERT INTO t1 VALUES (20,'bb2',222.222e2, 12.32); +INSERT INTO t1 VALUES (30,'bb3',333.333e2, 12.33); +CREATE PROCEDURE p1() +AS +rec t1%ROWTYPE; +CURSOR cur IS SELECT * FROM t1; +BEGIN +OPEN cur; +LOOP +FETCH cur INTO rec; +EXIT WHEN cur%NOTFOUND; +SELECT rec.a, rec.b, rec.c, rec.d; +INSERT INTO t2 VALUES (rec.a, rec.b, rec.c, rec.d); +END LOOP; +CLOSE cur; +END; +$$ +CALL p1(); +rec.a rec.b rec.c rec.d +10 bb1 11111.1 12.31 +rec.a rec.b rec.c rec.d +20 bb2 22222.2 12.32 +rec.a rec.b rec.c rec.d +30 bb3 33333.3 12.33 +SELECT * FROM t2; +a b c d +10 bb1 11111.1 12.31 +20 bb2 22222.2 12.32 +30 bb3 33333.3 12.33 +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Fetching a cursor into a table%ROWTYPE variable with different column names +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (x INT, y VARCHAR(10)); +INSERT INTO t1 VALUES (10,'bbb'); +CREATE PROCEDURE p1() +AS +rec2 t2%ROWTYPE; +CURSOR cur1 IS SELECT * FROM t1; +BEGIN +OPEN cur1; +FETCH cur1 INTO rec2; +SELECT rec2.x, rec2.y; +CLOSE cur1; +END; +$$ +CALL p1(); +rec2.x rec2.y +10 bbb +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# Fetching a cursor into a table%ROWTYPE variable, with truncation +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t1 VALUES (10,'11x'); +CREATE PROCEDURE p1() +AS +rec2 t2%ROWTYPE; +CURSOR cur1 IS SELECT * FROM t1; +BEGIN +OPEN cur1; +FETCH cur1 INTO rec2; +SELECT rec2.a, rec2.b; +CLOSE cur1; +END; +$$ +CALL p1(); +rec2.a rec2.b +10 11 +Warnings: +Warning 1265 Data truncated for column 'b' at row 1 +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; +# +# table%ROWTYPE variables are not allowed in LIMIT +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,2); +CREATE PROCEDURE p1() +AS +rec1 t1%ROWTYPE:=(1,2); +BEGIN +SELECT * FROM t1 LIMIT rec1.a; +END; +$$ +ERROR HY000: A variable of a non-integer based type in LIMIT clause +DROP TABLE t1; +# +# table%ROWTYPE variable fields as OUT parameters +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1(a OUT INT,b OUT VARCHAR(10)) +AS +BEGIN +a:=10; +b:='bb'; +END; +$$ +CREATE PROCEDURE p2() +AS +rec1 t1%ROWTYPE; +BEGIN +CALL p1(rec1.a, rec1.b); +SELECT rec1.a, rec1.b; +END; +$$ +CALL p2(); +rec1.a rec1.b +10 bb +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Passing the entire table%ROWTYPE variable +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1(a ROW(a INT, b VARCHAR(10))) +AS +BEGIN +SELECT a.a, a.b; +END; +$$ +CREATE PROCEDURE p2() +AS +rec1 t1%ROWTYPE:= ROW(10,'bb'); +BEGIN +CALL p1(rec1); +END; +$$ +CALL p2(); +a.a a.b +10 bb +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Passing the entire table%ROWTYPE variable as an OUT parameter +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1(a OUT ROW(a INT, b VARCHAR(10))) +AS +BEGIN +a:= ROW(10,'bb'); +END; +$$ +CREATE PROCEDURE p2() +AS +rec1 t1%ROWTYPE; +BEGIN +CALL p1(rec1); +SELECT rec1.a, rec1.b; +END; +$$ +CALL p2(); +rec1.a rec1.b +10 bb +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Assigning a table%ROWTYPE field to an OUT parameter +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1 (res IN OUT INTEGER) +AS +rec1 t1%ROWTYPE:=ROW(10,'b0'); +BEGIN +res:=rec1.a; +END; +$$ +CALL p1(@res); +SELECT @res; +@res +10 +SET @res=NULL; +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing Item_splocal_row_field_by_name::print +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1 +AS +rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN +EXPLAIN EXTENDED SELECT rec.a, rec.b; +END; +$$ +CALL p1(); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select rec.a@0["a"] AS "rec.a",rec.b@0["b"] AS "rec.b" +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Non-existing field +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1 +AS +rec t1%ROWTYPE; +BEGIN +SELECT rec.c; +END; +$$ +CALL p1(); +ERROR HY000: Row variable 'rec' does not have a field 'c' +ALTER TABLE t1 ADD c INT; +CALL p1(); +rec.c +NULL +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing that field names are case insensitive +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE PROCEDURE p1 +AS +rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN +SELECT rec.A, rec.B; +END; +$$ +CALL p1(); +rec.A rec.B +10 bb +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing that table%ROWTYPE uses temporary tables vs shadowed real tables +# +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TEMPORARY TABLE t1 (x INT, y VARCHAR(10)); +CREATE PROCEDURE p1 +AS +rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN +SELECT rec.A, rec.B; +END; +$$ +CALL p1(); +ERROR HY000: Row variable 'rec' does not have a field 'A' +DROP TEMPORARY TABLE t1; +CALL p1(); +rec.A rec.B +10 bb +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Testing that the structure of table%ROWTYPE variables is determined at the very beginning and is not changed after ALTER +# +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +BEGIN +ALTER TABLE t1 ADD c INT; +DECLARE +rec t1%ROWTYPE; -- this will not have column "c" + BEGIN +rec.c:=10; +END; +END; +$$ +CALL p1(); +ERROR HY000: Row variable 'rec' does not have a field 'c' +DROP TABLE t1; +DROP PROCEDURE p1; +# +# MDEV-12291 Allow ROW variables as SELECT INTO targets +# +# ROW variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 ROW(a INT, b VARCHAR(32), c DOUBLE); +BEGIN +SELECT * FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: The used SELECT statements have a different number of columns +DROP TABLE t1; +DROP PROCEDURE p1; +# Multiple ROW variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 ROW(a INT, b VARCHAR(32)); +BEGIN +SELECT * FROM t1 INTO rec1, rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP TABLE t1; +DROP PROCEDURE p1; +# ROW variables working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 ROW(a INT, b VARCHAR(32)); +BEGIN +SELECT * FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +rec1.a rec1.b +10 b10 +DROP TABLE t1; +DROP PROCEDURE p1; +# table%ROWTYPE variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 t1%ROWTYPE; +BEGIN +SELECT 10,'a','b' FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: The used SELECT statements have a different number of columns +DROP TABLE t1; +DROP PROCEDURE p1; +# Multiple table%ROWTYPE variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 t1%ROWTYPE; +BEGIN +SELECT 10,'a' FROM t1 INTO rec1, rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP TABLE t1; +DROP PROCEDURE p1; +# table%ROWTYPE working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +rec1 t1%ROWTYPE; +BEGIN +SELECT * FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +rec1.a rec1.b +10 b10 +DROP TABLE t1; +DROP PROCEDURE p1; +# cursor%ROWTYPE variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +CURSOR cur1 IS SELECT 10, 'b0', 'c0'; +rec1 cur1%ROWTYPE; +BEGIN +SELECT * FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: The used SELECT statements have a different number of columns +DROP TABLE t1; +DROP PROCEDURE p1; +# Multiple cursor%ROWTYPE variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +CURSOR cur1 IS SELECT * FROM t1; +rec1 cur1%ROWTYPE; +BEGIN +SELECT * FROM t1 INTO rec1, rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +ERROR 21000: Operand should contain 2 column(s) +DROP TABLE t1; +DROP PROCEDURE p1; +# cursor%ROWTYPE working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +CREATE PROCEDURE p1 AS +CURSOR cur1 IS SELECT * FROM t1; +rec1 cur1%ROWTYPE; +BEGIN +SELECT * FROM t1 INTO rec1; +SELECT rec1.a, rec1.b; +END; +$$ +Warnings: +Warning 1287 ' INTO FROM...' instead +CALL p1(); +rec1.a rec1.b +10 b10 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# MDEV-12347 Valgrind reports invalid read errors in Item_field_row::element_index_by_name +# +CREATE TABLE t1 (a INT, b ENUM('b0','b1','b12','b3')); +CREATE PROCEDURE p1 AS +BEGIN +DECLARE +rec t1%ROWTYPE; +BEGIN +rec.b:='b0'; +SELECT rec.b; +END; +END; +$$ +CALL p1(); +rec.b +b0 +DROP TABLE t1; +DROP PROCEDURE p1; +CREATE TABLE t1 (a INT, b SET('b0','b1','b12','b3')); +CREATE PROCEDURE p1 AS +BEGIN +DECLARE +rec t1%ROWTYPE; +BEGIN +rec.b:='b0'; +SELECT rec.b; +END; +END; +$$ +CALL p1(); +rec.b +b0 +DROP TABLE t1; +DROP PROCEDURE p1; +# +# MDEV-13273 Confusion between table alias and ROW type variable +# +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +CREATE PROCEDURE p1 +AS +a INT; +b INT; +BEGIN +-- a.c1 is a table column +SELECT a.c1 INTO b +FROM t1 a +WHERE a.c2 = 0; +SELECT b; +END; +$$ +CALL p1; +b +0 +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +CREATE PROCEDURE p1 +AS +a ROW (c1 INT, c2 INT) := ROW(101,102); +b INT; +BEGIN +-- a.c1 is a ROW variable field +SELECT a.c1 INTO b +FROM t1 a +WHERE a.c2 = 102; +SELECT b; +END; +$$ +CALL p1; +b +101 +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +CREATE PROCEDURE p1 +AS +a t1%ROWTYPE := ROW (10,20); +b INT; +BEGIN +-- a.c1 is a ROW variable field +SELECT a.c1 INTO b +FROM t1 a +WHERE a.c2 = 20; +SELECT b; +END; +$$ +CALL p1; +b +10 +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +CREATE PROCEDURE p1 +AS +CURSOR cur1 IS SELECT * FROM t1; +a cur1%ROWTYPE := ROW (10,20); +b INT; +BEGIN +-- a.c1 is a ROW variable field +SELECT a.c1 INTO b +FROM t1 a +WHERE a.c2 = 20; +SELECT b; +END; +$$ +CALL p1; +b +10 +DROP PROCEDURE p1; +DROP TABLE t1; +# +# MDEV-13527 Crash when EXPLAIN SELECT .. INTO row_sp_variable.field +# +DECLARE +a ROW(a INT); +BEGIN +EXPLAIN SELECT 1 INTO a.a; +END; +$$ +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +# +# MDEV-14139 Anchored data types for variables +# +DECLARE +row1 ROW(int11 INT,text1 TEXT); +a_row1 row1%TYPE; +aa_row1 a_row1%TYPE; +BEGIN +CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1; +SHOW CREATE TABLE t1; +DROP TABLE t1; +CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1; +SHOW CREATE TABLE t1; +DROP TABLE t1; +END; +$$ +Table Create Table +t1 CREATE TABLE "t1" ( + "int11" int(11) DEFAULT NULL, + "text1" text DEFAULT NULL +) +Table Create Table +t1 CREATE TABLE "t1" ( + "int11" int(11) DEFAULT NULL, + "text1" text DEFAULT NULL +) diff --git a/mysql-test/suite/compat/oracle/r/sp-security.result b/mysql-test/suite/compat/oracle/r/sp-security.result new file mode 100644 index 00000000..db29a17a --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp-security.result @@ -0,0 +1,288 @@ +SET sql_mode=ORACLE; +# +# MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations +# +# +# Initiation: +# - creating database db1 +# - creating user user1 with access rights to db1 +# +CREATE DATABASE db1; +CREATE TABLE db1.t1 (a INT, b VARCHAR(10)); +CREATE USER user1; +GRANT ALL PRIVILEGES ON test.* TO user1; +connect conn1,localhost,user1,,test; +SET sql_mode=ORACLE; +SELECT database(); +database() +test +SELECT user(); +user() +user1@localhost +# +# Making sure that user1 does not have privileges to db1.t1 +# +SHOW CREATE TABLE db1.t1; +ERROR 42000: SHOW command denied to user 'user1'@'localhost' for table `db1`.`t1` +SHOW FIELDS IN db1.t1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +# +# Trigger: using %TYPE with a table we don't have access to +# +CREATE TABLE test.t1 (a INT, b INT); +INSERT INTO test.t1 (a,b) VALUES (10,20); +SELECT * FROM t1; +a b +10 20 +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN +DECLARE b db1.t1.b%TYPE := 20; +BEGIN +:NEW.b := 10; +END; +END +$$ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +SELECT * FROM t1; +a b +10 20 +DROP TRIGGER tr1; +DROP TABLE t1; +# +# Stored procedure: Using %TYPE for with a table that we don't have access to +# DEFINER user1, SQL SECURITY DEFAULT +# +CREATE PROCEDURE p1() +AS +a db1.t1.a%TYPE := 10; +BEGIN +SELECT a; +END; +$$ +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +a db1.t1%ROWTYPE; +BEGIN +SELECT a.a; +END; +$$ +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP PROCEDURE p1; +# +# Stored procedure: Using %TYPE for with a table that we don't have access to +# DEFINER root, SQL SECURITY INVOKER +# +connection default; +CREATE PROCEDURE p1() +SQL SECURITY INVOKER +AS +a db1.t1.a%TYPE := 10; +BEGIN +SELECT a; +END; +$$ +connection conn1; +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP PROCEDURE p1; +connection default; +CREATE PROCEDURE p1() +SQL SECURITY INVOKER +AS +a db1.t1%ROWTYPE; +BEGIN +SELECT a.a; +END; +$$ +connection conn1; +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP PROCEDURE p1; +# +# Stored procedure: Using %TYPE for with a table that we don't have access to +# DEFINER root, SQL SECURITY DEFINER +# +connection default; +CREATE PROCEDURE p1() +SQL SECURITY DEFINER +AS +a db1.t1.a%TYPE := 10; +BEGIN +SELECT a; +END; +$$ +connection conn1; +CALL p1; +a +10 +DROP PROCEDURE p1; +connection default; +CREATE PROCEDURE p1() +SQL SECURITY DEFINER +AS +a db1.t1%ROWTYPE; +BEGIN +a.a:= 10; +SELECT a.a; +END; +$$ +connection conn1; +CALL p1; +a.a +10 +DROP PROCEDURE p1; +# +# Stored function: Using %TYPE for with a table that we don't have access to +# DEFINER user1, SQL SECURITY DEFAULT +# +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1() RETURN INT +AS +a db1.t1.a%TYPE:=0; +BEGIN +RETURN OCTET_LENGTH(a); +END; +$$ +SELECT f1(); +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP FUNCTION f1; +DROP TABLE t1; +# +# Stored function: Using %TYPE for with a table that we don't have access to +# DEFINER root, SQL SECURITY INVOKER +# +connection default; +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1() RETURN INT +SQL SECURITY INVOKER +AS +a db1.t1.a%TYPE:=0; +BEGIN +RETURN OCTET_LENGTH(a); +END; +$$ +connection conn1; +SELECT f1(); +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for table `db1`.`t1` +DROP FUNCTION f1; +DROP TABLE t1; +# +# Stored function: Using %TYPE for with a table that we don't have access to +# DEFINER root, SQL SECURITY DEFINER +# +connection default; +CREATE TABLE t1 (a INT); +CREATE FUNCTION f1() RETURN INT +SQL SECURITY DEFINER +AS +a db1.t1.a%TYPE:=0; +BEGIN +RETURN OCTET_LENGTH(a); +END; +$$ +connection conn1; +SELECT f1(); +f1() +1 +DROP FUNCTION f1; +DROP TABLE t1; +connection default; +GRANT SELECT (a) ON db1.t1 TO user1; +connection conn1; +# +# Making sure that user1 has access to db1.t1.a, but not to db1.t1.b +# +SHOW CREATE TABLE db1.t1; +ERROR 42000: SHOW command denied to user 'user1'@'localhost' for table `db1`.`t1` +SHOW FIELDS IN db1.t1; +Field Type Null Key Default Extra +a int(11) YES NULL +# +# Trigger: Per-column privileges +# +CREATE TABLE test.t1 (a INT, b INT); +INSERT INTO test.t1 (a,b) VALUES (10,20); +SELECT * FROM t1; +a b +10 20 +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN +DECLARE a db1.t1.a%TYPE := 20; +BEGIN +:NEW.b := 10; +END; +END +$$ +INSERT INTO t1 (a) VALUES (10); +SELECT * FROM t1; +a b +10 20 +10 10 +DROP TRIGGER tr1; +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN +DECLARE b db1.t1.b%TYPE := 20; +BEGIN +:NEW.b := 10; +END; +END +$$ +INSERT INTO t1 (a) VALUES (10); +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for column 'b' in table 't1' +SELECT * FROM t1; +a b +10 20 +10 10 +DROP TRIGGER tr1; +DROP TABLE t1; +# +# Stored procedure: Per-column privileges +# DEFINER user1, SQL SECURITY DEFAULT +# +CREATE PROCEDURE p1() +AS +a db1.t1.a%TYPE := 10; +BEGIN +SELECT a; +END; +$$ +CALL p1; +a +10 +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +b db1.t1.b%TYPE := 10; +BEGIN +SELECT b; +END; +$$ +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for column 'b' in table 't1' +DROP PROCEDURE p1; +CREATE PROCEDURE p1() +AS +b db1.t1%ROWTYPE; +BEGIN +b.b:=10; +SELECT b.b; +END; +$$ +CALL p1; +ERROR 42000: SELECT command denied to user 'user1'@'localhost' for column 'b' in table 't1' +DROP PROCEDURE p1; +# +# Clean up +# +disconnect conn1; +connection default; +DROP USER user1; +DROP DATABASE db1; +# +# End of MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations +# diff --git a/mysql-test/suite/compat/oracle/r/sp.result b/mysql-test/suite/compat/oracle/r/sp.result new file mode 100644 index 00000000..409ea3b8 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/sp.result @@ -0,0 +1,2577 @@ +SET sql_mode=ORACLE; +# Testing routines with no parameters +CREATE FUNCTION f1 RETURN INT +AS +BEGIN +RETURN 10; +END; +/ +SHOW CREATE FUNCTION f1; +Function f1 +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +Create Function CREATE DEFINER="root"@"localhost" FUNCTION "f1"() RETURN int(11) +AS +BEGIN +RETURN 10; +END +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SELECT f1(); +f1() +10 +DROP FUNCTION f1; +CREATE PROCEDURE p1 +AS +BEGIN +SET @a=10; +END; +/ +SHOW CREATE PROCEDURE p1; +Procedure p1 +sql_mode PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT +Create Procedure CREATE DEFINER="root"@"localhost" PROCEDURE "p1"() +AS +BEGIN +SET @a=10; +END +character_set_client latin1 +collation_connection latin1_swedish_ci +Database Collation latin1_swedish_ci +SET @a=0; +CALL p1(); +SELECT @a; +@a +10 +DROP PROCEDURE p1; +# Testing ":=" to set the default value of a variable +CREATE FUNCTION f1 () RETURN NUMBER(10) AS +a NUMBER(10) := 10; +BEGIN +DECLARE +b NUMBER(10) DEFAULT 3; +BEGIN +RETURN a+b; +END; +END; +/ +SELECT f1(); +f1() +13 +DROP FUNCTION f1; +# Testing labels +CREATE FUNCTION f1 (a INT) RETURN CLOB AS +BEGIN +<> +BEGIN +IF a = 1 THEN +LEAVE label1; +END IF; +RETURN 'IS NOT 1'; +END label1; +RETURN 'IS 1'; +END; +/ +SELECT f1(1); +f1(1) +IS 1 +SELECT f1(2); +f1(2) +IS NOT 1 +DROP FUNCTION f1; +CREATE FUNCTION f1 (a INT) RETURN INT IS +BEGIN +<> +LOOP +IF a = 2 THEN +LEAVE label1; +END IF; +SET a= a-1; +END LOOP; +RETURN a; +END; +/ +SELECT f1(4); +f1(4) +2 +DROP FUNCTION f1; +CREATE FUNCTION f1 (a INT) RETURN INT AS +BEGIN +<> +WHILE a>0 LOOP +IF a = 2 THEN +LEAVE label1; +END IF; +SET a= a-1; +END LOOP label1; +RETURN a; +END; +/ +SELECT f1(4); +f1(4) +2 +DROP FUNCTION f1; +CREATE FUNCTION f1 (a INT) RETURN INT AS +BEGIN +<> +REPEAT +IF a = 2 THEN +LEAVE label1; +END IF; +SET a= a-1; +UNTIL a=0 END REPEAT; +RETURN a; +END; +/ +SELECT f1(4); +f1(4) +2 +DROP FUNCTION f1; +# Testing IN/OUT/INOUT +CREATE PROCEDURE p1 (p1 IN VARCHAR2(10), p2 OUT VARCHAR2(10)) AS +BEGIN +SET p1='p1new'; +SET p2='p2new'; +END; +/ +SET @p1='p1', @p2='p2'; +CALL p1(@p1, @p2); +SELECT @p1, @p2; +@p1 @p2 +p1 p2new +DROP PROCEDURE p1; +# Testing Oracle-style assigment +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) AS +BEGIN +p1:= 'p1new'; +END; +/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +@p1 +p1new +DROP PROCEDURE p1; +# Testing that NULL is a valid statement +CREATE PROCEDURE p1(a INT) AS +BEGIN +NULL; +END; +/ +DROP PROCEDURE p1; +CREATE PROCEDURE p1(a INT) AS +a INT:=10; +BEGIN +IF a=10 THEN NULL; ELSE NULL; END IF; +END; +/ +DROP PROCEDURE p1; +# Keywords that are OK for table names, but not for SP variables +CREATE TABLE function (function int); +INSERT INTO function SET function=10; +SELECT function.function FROM function; +function +10 +DROP TABLE function; +# Testing that (some) keyword_sp are allowed in Oracle-style assignments +CREATE PROCEDURE p1 (action OUT INT) AS BEGIN action:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (clob OUT INT) AS BEGIN clob:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (enum OUT INT) AS BEGIN enum:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (via OUT INT) AS BEGIN via:=10; END;/ +DROP PROCEDURE p1/ +# Testing keyword_directly_assignable +CREATE PROCEDURE p1 (ascii OUT INT) AS BEGIN ascii:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (backup OUT INT) AS BEGIN backup:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (binlog OUT INT) AS BEGIN binlog:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (byte OUT INT) AS BEGIN byte:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (cache OUT INT) AS BEGIN cache:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (checksum OUT INT) AS BEGIN checksum:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (checkpoint OUT INT) AS BEGIN checkpoint:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_add OUT INT) AS BEGIN column_add:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_check OUT INT) AS BEGIN column_check:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_create OUT INT) AS BEGIN column_create:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_delete OUT INT) AS BEGIN column_delete:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_get OUT INT) AS BEGIN column_get:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (deallocate OUT INT) AS BEGIN deallocate:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (examined OUT INT) AS BEGIN examined:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (execute OUT INT) AS BEGIN execute:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (flush OUT INT) AS BEGIN flush:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (format OUT INT) AS BEGIN format:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (get OUT INT) AS BEGIN get:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (help OUT INT) AS BEGIN help:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (host OUT INT) AS BEGIN host:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (install OUT INT) AS BEGIN install:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (option OUT INT) AS BEGIN option:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (options OUT INT) AS BEGIN options:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (owner OUT INT) AS BEGIN owner:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (parser OUT INT) AS BEGIN parser:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (port OUT INT) AS BEGIN port:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (prepare OUT INT) AS BEGIN prepare:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (remove OUT INT) AS BEGIN remove:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (reset OUT INT) AS BEGIN reset:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (restore OUT INT) AS BEGIN restore:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (security OUT INT) AS BEGIN security:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (server OUT INT) AS BEGIN server:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (signed OUT INT) AS BEGIN signed:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (socket OUT INT) AS BEGIN socket:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (slave OUT INT) AS BEGIN slave:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (slaves OUT INT) AS BEGIN slaves:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (soname OUT INT) AS BEGIN soname:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (start OUT INT) AS BEGIN start:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (stop OUT INT) AS BEGIN stop:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (stored OUT INT) AS BEGIN stored:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (unicode OUT INT) AS BEGIN unicode:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (uninstall OUT INT) AS BEGIN uninstall:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (upgrade OUT INT) AS BEGIN upgrade:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (wrapper OUT INT) AS BEGIN wrapper:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (xa OUT INT) AS BEGIN xa:=10; END;/ +DROP PROCEDURE p1/ +# Testing that keyword_directly_not_assignable does not work in := +CREATE PROCEDURE p1 (commit OUT INT) AS BEGIN commit:=10; END;/ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':=10; END' at line 1 +CREATE PROCEDURE p1 (rollback OUT INT) AS BEGIN rollback:=10; END;/ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':=10; END' at line 1 +CREATE PROCEDURE p1 (shutdown OUT INT) AS BEGIN shutdown:=10; END;/ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':=10; END' at line 1 +CREATE PROCEDURE p1 (exception OUT INT) AS BEGIN exception:=10; END;/ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':=10; END' at line 1 +# Testing that keyword_directly_not_assignable works in SET statements. +CREATE PROCEDURE p1 (contains OUT INT) AS BEGIN SET contains=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (language OUT INT) AS BEGIN SET language=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (no OUT INT) AS BEGIN SET no=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (charset OUT INT) AS BEGIN SET charset=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (do OUT INT) AS BEGIN SET do=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (repair OUT INT) AS BEGIN SET repair=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (handler OUT INT) AS BEGIN SET handler=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (open OUT INT) AS BEGIN SET open=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (close OUT INT) AS BEGIN SET close=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (savepoint OUT INT) AS BEGIN SET savepoint=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (truncate OUT INT) AS BEGIN SET truncate=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (begin OUT INT) AS BEGIN SET begin=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (end OUT INT) AS BEGIN SET end=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (exception OUT INT) AS BEGIN SET exception=10; END;/ +DROP PROCEDURE p1/ +# Testing that keyword_directly_not_assignable works in table/column names +CREATE TABLE contains (contains INT); +DROP TABLE contains; +CREATE TABLE language (language INT); +DROP TABLE language; +CREATE TABLE no (no INT); +DROP TABLE no; +CREATE TABLE charset (charset INT); +DROP TABLE charset; +CREATE TABLE do (do INT); +DROP TABLE do; +CREATE TABLE repair (repair INT); +DROP TABLE repair; +CREATE TABLE handler (handler INT); +DROP TABLE handler; +CREATE TABLE open (open INT); +DROP TABLE open; +CREATE TABLE close (close INT); +DROP TABLE close; +CREATE TABLE savepoint (savepoint INT); +DROP TABLE savepoint; +CREATE TABLE truncate (truncate INT); +DROP TABLE truncate; +CREATE TABLE begin (begin INT); +DROP TABLE begin; +CREATE TABLE end (end INT); +DROP TABLE end; +CREATE TABLE exception (exception INT); +DROP TABLE exception; +# Testing ELSIF +CREATE FUNCTION f1(a INT) RETURN CLOB +AS +BEGIN +IF a=1 THEN RETURN 'a is 1'; +ELSIF a=2 THEN RETURN 'a is 2'; +ELSE RETURN 'a is unknown'; +END IF; +END; +/ +SELECT f1(2) FROM DUAL; +f1(2) +a is 2 +DROP FUNCTION f1; +# Testing top-level declarations +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) +AS +p2 VARCHAR(10); +BEGIN +p2:='p1new'; +p1:=p2; +END; +/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +@p1 +p1new +DROP PROCEDURE p1; +CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20) +AS +p2 VARCHAR(10); +BEGIN +p2:='new'; +RETURN CONCAT(p1, p2); +END; +/ +SET @p1='p1'; +SELECT f1(@p1); +f1(@p1) +p1new +DROP FUNCTION f1; +# Testing non-top declarations +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) +AS +BEGIN +DECLARE +p2 VARCHAR(10); +BEGIN +p2:='p1new'; +p1:=p2; +END; +DECLARE +t1 VARCHAR(10); +t2 VARCHAR(10); +BEGIN +END; +END; +/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +@p1 +p1new +DROP PROCEDURE p1; +CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20) +AS +BEGIN +DECLARE +p2 VARCHAR(10); +BEGIN +p2:='new'; +RETURN CONCAT(p1, p2); +END; +DECLARE +t1 VARCHAR(10); +t2 VARCHAR(10); +BEGIN +END; +END; +/ +SET @p1='p1'; +SELECT f1(@p1); +f1(@p1) +p1new +DROP FUNCTION f1; +# Testing exceptions +CREATE TABLE t1 (c1 INT); +CREATE PROCEDURE sp1 (p1 IN VARCHAR2(20), p2 OUT VARCHAR2(30)) +IS +v1 INT; +BEGIN +SELECT c1 INTO v1 FROM t1; +p2 := p1; +EXCEPTION +WHEN NOT FOUND THEN +BEGIN +p2 := 'def'; +END; +END; +/ +CALL sp1('abc', @a); +SELECT @a; +@a +def +DROP PROCEDURE sp1; +DROP TABLE t1; +CREATE PROCEDURE sp1 (v IN OUT INT, error IN INT) +IS +BEGIN +SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=error, MESSAGE_TEXT='User defined error!'; +v:= 223; +EXCEPTION +WHEN 30001 THEN +BEGIN +v:= 113; +END; +END; +/ +SET @v=10; +CALL sp1(@v, 30001); +CALL sp1(@v, 30002); +ERROR 45000: User defined error! +SELECT @v; +@v +113 +DROP PROCEDURE sp1; +CREATE PROCEDURE sp1 (v IN OUT INT, error IN INT) +IS +BEGIN +BEGIN +BEGIN +SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=error, MESSAGE_TEXT='User defined error!'; +v:= 223; +EXCEPTION +WHEN 30001 THEN +BEGIN +v:= 113; +END; +END; +END; +END; +/ +SET @v=10; +CALL sp1(@v, 30001); +SELECT @v; +@v +113 +SET @v=10; +CALL sp1(@v, 30002); +ERROR 45000: User defined error! +SELECT @v; +@v +10 +DROP PROCEDURE sp1; +# +# Testing EXIT statement +# +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +EXIT; +END; +/ +ERROR 42000: EXIT with no matching label: +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +<> +BEGIN +<> +LOOP +EXIT label1; +END LOOP; +END; +END; +/ +ERROR 42000: EXIT with no matching label: label1 +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +LOOP +LOOP +i:= i + 1; +IF i >= 5 THEN +EXIT; +END IF; +END LOOP; +i:= i + 100; +EXIT; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +105 +DROP FUNCTION f1; +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +<> +LOOP +<> +LOOP +i:= i + 1; +IF i >= 5 THEN +EXIT label2; +END IF; +END LOOP; +i:= i + 100; +EXIT; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +105 +DROP FUNCTION f1; +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +<> +LOOP +<> +LOOP +i:= i + 1; +IF i >= 5 THEN +EXIT label1; +END IF; +END LOOP; +i:= i + 100; +EXIT; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +5 +DROP FUNCTION f1; +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +LOOP +i:= i + 1; +EXIT WHEN i >=5; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +5 +DROP FUNCTION f1; +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +<> +LOOP +<> +LOOP +i:= i + 1; +EXIT label2 WHEN i >= 5; +END LOOP; +i:= i + 100; +EXIT; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +105 +DROP FUNCTION f1; +CREATE FUNCTION f1 RETURN INT +IS +i INT := 0; +BEGIN +<> +LOOP +<> +LOOP +i:= i + 1; +EXIT label1 WHEN i >= 5; +END LOOP; +i:= i + 100; +EXIT; +END LOOP; +RETURN i; +END; +/ +SELECT f1() FROM DUAL; +f1() +5 +DROP FUNCTION f1; +# Testing CURSOR declaration +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); +CREATE FUNCTION f1 RETURN INT +AS +v_a INT:=10; +CURSOR c IS SELECT a FROM t1; +BEGIN +OPEN c; +FETCH c INTO v_a; +CLOSE c; +RETURN v_a; +EXCEPTION +WHEN OTHERS THEN RETURN -1; +END; +/ +SELECT f1() FROM DUAL; +f1() +1 +DROP FUNCTION f1; +DROP TABLE t1; +# Testing RETURN in procedures +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN +RETURN 10; +END; +/ +ERROR 42000: RETURN is only allowed in a FUNCTION +CREATE FUNCTION f1 (a INT) RETURN INT +AS +BEGIN +RETURN; +END; +/ +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '; +END' at line 4 +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN +IF a < 10 THEN +BEGIN +a:= a - 1; +RETURN; +END; +END IF; +a:= a + 1; +EXCEPTION +WHEN OTHERS THEN RETURN; +END; +/ +SET @v=10; +CALL p1(@v); +SELECT @v; +@v +11 +SET @v=9; +CALL p1(@v); +SELECT @v; +@v +8 +DROP PROCEDURE p1; +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN +DROP TABLE t1_non_existent; +EXCEPTION +WHEN OTHERS THEN +BEGIN +a:= 100; +RETURN; +END; +END; +/ +SET @v=10; +CALL p1(@v); +SELECT @v; +@v +100 +DROP PROCEDURE p1; +# Testing WHILE loop +CREATE PROCEDURE p1 (a IN OUT INT) +AS +i INT:= 1; +j INT:= 3; +BEGIN +WHILE i<=j +LOOP +a:= a + i; +i:= i + 1; +END LOOP; +END; +/ +SET @v=0; +CALL p1(@v); +SELECT @v; +@v +6 +DROP PROCEDURE p1; +CREATE PROCEDURE p1 (a IN OUT INT) +AS +i INT:= 1; +j INT:= 3; +BEGIN +<
SET = FUNCTION(a IN) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a IN INT) RETURN INT + AS + BEGIN + RETURN a * 10; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 5; +UPDATE Persons SET Age = pkg2.func(@a) WHERE ID = 1; +SELECT * FROM Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Call function from UPDATE query +--echo # UPDATE
SET = FUNCTION(a OUT) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + a := 5; + RETURN 80; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +UPDATE Persons SET Age = pkg2.func(@a) WHERE ID = 1; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Call function from INSERT query +--echo # INSERT INTO
SELECT , , FUNCTION(a IN) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a IN INT) RETURN INT + AS + BEGIN + RETURN a * 10; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 4; +INSERT INTO Persons SELECT 4, 'DDD', PKG2.func(@a); +SELECT * FROM Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Call function from INSERT query +--echo # INSERT INTO
SELECT , , FUNCTION(a OUT) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + a := 45; + RETURN 40; + END; +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +set @a = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +INSERT INTO Persons SELECT 5, 'EEE', PKG2.func(@a); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Call function from DELETE query +--echo # DELETE FROM
WHERE = FUNCTION(a IN) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a IN INT) RETURN INT + AS + BEGIN + RETURN a; + END; +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +set @a = 4; +DELETE FROM Persons WHERE ID = PKG2.func(@a); +SELECT * FROM Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Call function from DELETE query +--echo # DELETE FROM
WHERE = FUNCTION(a OUT) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + a := 40; + RETURN 4; + END; +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +set @a = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +DELETE FROM Persons WHERE ID = PKG2.func(@a); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # SELECT query inside function +--echo # FUNCTION(a IN) > SELECT … FROM
+--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + c INT; + BEGIN + SELECT AGE INTO c FROM Persons WHERE ID = a; + RETURN c; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 3; +select pkg2.func_main(@a); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # SELECT query inside function +--echo # FUNCTION(a OUT) > SELECT … FROM
+--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a OUT INT) RETURN INT + AS + BEGIN + SELECT AGE INTO a FROM Persons WHERE ID = 3; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # SELECT query inside function +--echo # FUNCTION(a INOUT) > SELECT … FROM
+--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a INOUT INT) RETURN INT + AS + BEGIN + SELECT AGE INTO a FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 1; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # SELECT query inside function +--echo # FUNCTION(a IN) > FUNCTION(a IN, b OUT) > SELECT … FROM
+--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + b INT; + res INT; + BEGIN + res := func_sub(a, b); + RETURN b; + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 2; +select pkg2.func_main(@a); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # UPDATE query inside function +--echo # FUNCTION(a IN) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + c INT; + BEGIN + UPDATE Persons SET AGE = 50 WHERE ID = a; + + SELECT AGE INTO c FROM Persons WHERE ID = a; + RETURN c; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 5; +select pkg2.func_main(@a); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # UPDATE query inside function +--echo # FUNCTION(a IN, b OUT) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + UPDATE Persons SET AGE = 60 WHERE ID = a; + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 5; +set @b = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a, @b); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # UPDATE query inside function +--echo # FUNCTION(a IN, b INOUT) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT + AS + BEGIN + UPDATE Persons SET AGE = 60 WHERE ID = a; + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +set @a = 5; +set @b = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a, @b); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # UPDATE query inside function +--echo # FUNCTION(a IN) > FUNCTION(a IN, b OUT) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 80); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + b INT; + res INT; + BEGIN + res := func_sub(a, b); + RETURN b; + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + UPDATE Persons SET AGE = 10 WHERE ID = a; + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 1; +select pkg2.func_main(@a); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # INSERT query inside function +--echo # FUNCTION(a IN) > INSERT INTO
VALUES … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 50); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + b INT; + BEGIN + INSERT INTO Persons VALUE (a, 'FFF', 60); + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN b; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +--disable_ps2_protocol +select pkg2.func_main(@a); +--enable_ps2_protocol +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # INSERT query inside function +--echo # FUNCTION(a IN, b OUT) > INSERT INTO
VALUES … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 50); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + INSERT INTO Persons VALUE (a, 'FFF', 60); + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +set @b = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a, @b); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # INSERT query inside function +--echo # FUNCTION(a IN, b INOUT) > INSERT INTO
VALUES … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT, b INOUT INT) RETURN INT + AS + BEGIN + INSERT INTO Persons VALUE (a, 'FFF', 60); + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +set @b = 0; +--error ER_SF_OUT_INOUT_ARG_NOT_ALLOWED +select pkg2.func_main(@a, @b); +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # INSERT query inside function +--echo # FUNCTION(a IN) > FUNCTION(a IN, b OUT) > INSERT INTO
VALUES … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'EEE', 40); + + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func_main(a IN INT) RETURN INT + AS + b INT; + res INT; + BEGIN + res := func_sub(a, b); + RETURN b; + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + INSERT INTO Persons VALUE (a, 'FFF', 60); + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +--disable_ps2_protocol +select pkg2.func_main(@a); +--enable_ps2_protocol +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(IN) > SELECT FROM
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + BEGIN + b := func_sub(a); + END; + FUNCTION func_sub(a IN INT) RETURN INT + AS + b INT; + BEGIN + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN b; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 2; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(OUT) > SELECT FROM
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + res INT; + BEGIN + res := func_sub(a, b); + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + SELECT AGE INTO b FROM Persons WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 1; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(INOUT) > SELECT FROM
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + c INT; + res INT; + BEGIN + c := 5; + res := func_sub(a, c); + b := c; + END; + FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT + AS + res INT; + BEGIN + SELECT AGE INTO res FROM Persons WHERE ID = a; + c := c * 100; + RETURN res; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 2; +set @b = 0; +call pkg2.proc_main(@a, @b); +select @b; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(IN) > INSESRT INTO
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + BEGIN + b := func_sub(a); + END; + FUNCTION func_sub(a IN INT) RETURN INT + AS + BEGIN + INSERT INTO Persons VALUE (a, 'FFF', 50); + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 5; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(OUT) > INSESRT INTO
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + res INT; + BEGIN + res := func_sub(a, b); + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + INSERT INTO Persons VALUE (a, 'GGG', 60); + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(INOUT) > INSESRT INTO
… +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); +INSERT INTO Persons VALUES (6, 'GGG', 60); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + c INT; + res INT; + BEGIN + c := 5; + res := func_sub(a, c); + b := c; + END; + FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT + AS + res INT; + BEGIN + INSERT INTO Persons VALUE (a, 'HHH', 70); + c := c * 100; + RETURN res; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 7; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(IN) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 50); +INSERT INTO Persons VALUES (6, 'GGG', 60); +INSERT INTO Persons VALUES (7, 'HHH', 70); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + BEGIN + b := func_sub(a); + END; + FUNCTION func_sub(a IN INT) RETURN INT + AS + BEGIN + UPDATE Persons SET AGE = 100 WHERE ID = a; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 5; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 100); +INSERT INTO Persons VALUES (6, 'GGG', 60); +INSERT INTO Persons VALUES (7, 'HHH', 70); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + res INT; + BEGIN + res := func_sub(a, b); + END; + FUNCTION func_sub(a IN INT, b OUT INT) RETURN INT + AS + BEGIN + UPDATE Persons SET AGE = 100 WHERE ID = a; + b := 1; + RETURN 0; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 6; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # PROCEDURE > FUNCTION > SQL query +--echo # PROCEDURE(OUT) > FUNCTION(INOUT) > UPDATE
SET … +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); +INSERT INTO Persons VALUES (4, 'DDD', 40); +INSERT INTO Persons VALUES (5, 'FFF', 100); +INSERT INTO Persons VALUES (6, 'GGG', 100); +INSERT INTO Persons VALUES (7, 'HHH', 70); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT); + FUNCTION func_sub(a IN INT, b INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc_main(a IN INT, b OUT INT) + AS + c INT; + res INT; + BEGIN + c := 5; + res := func_sub(a, c); + b := c; + END; + FUNCTION func_sub(a IN INT, c INOUT INT) RETURN INT + AS + res INT; + BEGIN + UPDATE Persons SET AGE = 100 WHERE ID = a; + c := c * 100; + RETURN res; + END; +END; +$$ +DELIMITER ;$$ + +select * from Persons; +set @a = 7; +set @b = 0; +call pkg2.proc_main(@a, @b); +select * from Persons; +DROP TABLE Persons; +DROP PACKAGE pkg2; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 20 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(IN) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a IN INT) RETURN INT + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE + a INT; + res INT; +BEGIN + a := 10; + res := 0; + res := pkg2.func(a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 30 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(OUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 40); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + a := 100; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE + a INT; + res INT; +BEGIN + a := 10; + res := 0; + res := pkg2.func(a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > FUNCTION(INOUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 50); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + FUNCTION func(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + FUNCTION func(a INOUT INT) RETURN INT + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + a := 100; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +DECLARE + a INT; + res INT; +BEGIN + a := 10; + res := 0; + res := pkg2.func(a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 60 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(IN) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a IN INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a IN INT) + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 30 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a OUT INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a OUT INT) + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(INOUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a INOUT INT); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a INOUT INT) + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + a := 100; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + set @a = 2; + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 50 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(IN) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a OUT INT); + FUNCTION func(a IN INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a OUT INT) + AS + res INT; + BEGIN + a := 100; + res := func(a); + END; + FUNCTION func(a IN INT) RETURN INT + AS + BEGIN + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 60 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a OUT INT); + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a OUT INT) + AS + res INT; + BEGIN + a := 100; + res := func(a); + END; + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + a := 200; + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 80 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(INOUT) > UPDATE TABLE2 +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a OUT INT); + FUNCTION func(a INOUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a OUT INT) + AS + res INT; + BEGIN + a := 100; + res := func(a); + END; + FUNCTION func(a INOUT INT) RETURN INT + AS + BEGIN + a := 200; + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 90 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + +--echo # +--echo # Trigger +--echo # TRIGGER AFTER UPDATE ON TABLE1 > PROCEDURE(OUT) > FUNCTION(OUT) > UPDATE TABLE2 with OUT argument (to check if OUT is returning by reference) +--echo # + +CREATE TABLE Persons ( + ID int, + Name varchar(255), + Age int +); +INSERT INTO Persons VALUES (1, 'AAA', 10); +INSERT INTO Persons VALUES (2, 'BBB', 20); +INSERT INTO Persons VALUES (3, 'CCC', 30); + +CREATE TABLE PersonsLog ( + UpdateCount int +); +INSERT INTO PersonsLog VALUES (0); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg2 +AS + PROCEDURE proc(a OUT INT); + FUNCTION func(a OUT INT) RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg2 +AS + PROCEDURE proc(a OUT INT) + AS + res INT; + BEGIN + res := func(a); + UPDATE PersonsLog SET UpdateCount = a; + END; + FUNCTION func(a OUT INT) RETURN INT + AS + BEGIN + a := 111; + UPDATE PersonsLog SET UpdateCount = UpdateCount+1; + RETURN 0; + END; +END; +$$ +CREATE OR REPLACE TRIGGER my_trigger +AFTER UPDATE ON Persons +FOR EACH ROW +BEGIN + call pkg2.proc(@a); +END; +$$ +DELIMITER ;$$ + +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +UPDATE Persons SET Age = 80 WHERE ID = 1; +SELECT * FROM Persons; +SELECT * FROM PersonsLog; +DROP TRIGGER my_trigger; +DROP PACKAGE pkg2; +DROP TABLE Persons; +DROP TABLE PersonsLog; + + +--echo # +--echo # Package BODY variables as OUT parameters +--echo # + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + FUNCTION f1(b IN OUT INT) RETURN INT; + FUNCTION show_private_variables() RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + pa INT:= 0; + pb INT:= 10; + FUNCTION f1(b IN OUT INT) RETURN INT AS + BEGIN + b:= b + 100; + RETURN 500+b-100; + END; + + FUNCTION show_private_variables() RETURN TEXT AS + BEGIN + RETURN 'Private variables: pa=' || pa || ' pb=' || pb; + END; +BEGIN + SET pa=f1(pb); +END; +$$ +DELIMITER ;$$ +SELECT pkg1.show_private_variables(); +DROP PACKAGE pkg1; diff --git a/mysql-test/suite/compat/oracle/t/sp-memory-leak.test b/mysql-test/suite/compat/oracle/t/sp-memory-leak.test new file mode 100644 index 00000000..015169c2 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-memory-leak.test @@ -0,0 +1,35 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-26186 280 Bytes lost in mysys/array.c, mysys/hash.c, sql/sp.cc, sql/sp.cc, sql/item_create.cc, sql/item_create.cc, sql/sql_yacc.yy:10748 when using oracle sql_mode +--echo # + +SET sql_mode= 'oracle'; +--error ER_SP_LILABEL_MISMATCH +BEGIN CONTINUE WHEN f0(); + +SET sql_mode= 'oracle'; +--error ER_SP_LILABEL_MISMATCH +BEGIN CONTINUE label WHEN f0(); + +SET sql_mode= 'oracle'; +--error ER_SP_LILABEL_MISMATCH +BEGIN EXIT WHEN f0(); + +SET sql_mode= 'oracle'; +--error ER_SP_LILABEL_MISMATCH +BEGIN EXIT label WHEN f0(); + +SET sql_mode= 'oracle'; +--error ER_PARSE_ERROR +--query WHILE f(8)<1 DO SELECT 1; + +SET sql_mode= 'oracle'; +--error ER_SP_BADRETURN +BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f0(); + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/mysql-test/suite/compat/oracle/t/sp-package-code.test b/mysql-test/suite/compat/oracle/t/sp-package-code.test new file mode 100644 index 00000000..9cca5396 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-code.test @@ -0,0 +1,182 @@ +-- source include/have_debug.inc + +SET sql_mode=ORACLE; + + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; + PROCEDURE p2show; + PROCEDURE p2public; + FUNCTION f2public RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + a INT:=10; + PROCEDURE p1 AS + b INT:=20; + BEGIN + b:=a; + b:=a+1; + a:=b; + a:=b+1; + a:=a+1; + SET @a:=@a+2; + SELECT f1() FROM DUAL; + END; + FUNCTION f1 RETURN INT AS + BEGIN + RETURN a; + END; + PROCEDURE p2private AS + BEGIN + SELECT 'This is p2private'; + END; + PROCEDURE p2public AS + BEGIN + SELECT 'This is p2public'; + END; + FUNCTION f2private RETURN TEXT AS + BEGIN + RETURN 'This is f2private'; + END; + FUNCTION f2public RETURN TEXT AS + BEGIN + RETURN 'This is f2public'; + END; + PROCEDURE p2show AS + BEGIN + SHOW FUNCTION CODE f2public; + SHOW FUNCTION CODE f2private; + SHOW PROCEDURE CODE p2public; + SHOW PROCEDURE CODE p2private; + SHOW PROCEDURE CODE p2show; + END; +BEGIN + a:=a+1; + DECLARE + b INT; + BEGIN + b:=a; + b:=a+1; + a:=b; + a:=b+1; + END; +END; +$$ +DELIMITER ;$$ + +SHOW PROCEDURE CODE pkg1.p1; +SHOW FUNCTION CODE pkg1.f1; +SHOW PACKAGE BODY CODE pkg1; +CALL pkg1.p2show; + +DROP PACKAGE pkg1; + + +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + a t1.a%TYPE:=10; + PROCEDURE p1 AS + b t1.a%TYPE:=20; + BEGIN + b:=a; + b:=a+1; + b:=b+1; + a:=b; + a:=b+1; + a:=a+1; + END; +BEGIN + a:=a+1; + DECLARE + b t1.a%TYPE; + BEGIN + b:=a; + b:=a+1; + a:=b; + a:=b+1; + END; +END; +$$ +DELIMITER ;$$ +SHOW PROCEDURE CODE pkg1.p1; +SHOW PACKAGE BODY CODE pkg1; +DROP PACKAGE pkg1; +DROP TABLE t1; + + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + a ROW(a INT,b TEXT):=ROW(10,'x10'); + PROCEDURE p1 AS + b ROW(a INT,b TEXT):=ROW(20,'x20'); + BEGIN + b:=a; + a:=b; + b.a:=a.a+1; + a.a:=b.a+1; + a.a:=a.a+1; + END; +BEGIN + a.a:=a.a+1; + DECLARE + b ROW(a INT,b TEXT):=ROW(30,'x30'); + BEGIN + b:=a; + b.a:=a.a+1; + a:=b; + a.a:=b.a+1; + END; +END; +$$ +DELIMITER ;$$ +SHOW PROCEDURE CODE pkg1.p1; +SHOW PACKAGE BODY CODE pkg1; +DROP PACKAGE pkg1; + + +CREATE TABLE t1 (a INT, b TEXT); +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + a t1%ROWTYPE:=ROW(10,'x10'); + PROCEDURE p1 AS + b t1%ROWTYPE:=ROW(20,'x20'); + BEGIN + b:=a; + a:=b; + b.a:=a.a+1; + a.a:=b.a+1; + a.a:=a.a+1; + END; +BEGIN + a.a:=a.a+1; + DECLARE + b t1%ROWTYPE:=ROW(30,'x30'); + BEGIN + b:=a; + b.a:=a.a+1; + a:=b; + a.a:=b.a+1; + END; +END; +$$ +DELIMITER ;$$ +SHOW PROCEDURE CODE pkg1.p1; +SHOW PACKAGE BODY CODE pkg1; +DROP PACKAGE pkg1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-db.test b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-db.test new file mode 100644 index 00000000..0528e6cb --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-db.test @@ -0,0 +1,6 @@ +--echo # +--echo # MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +--echo # + +SET @object_type='db'; +--source sp-package-concurrent-dml.inc diff --git a/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-package.test b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-package.test new file mode 100644 index 00000000..0f1a0ef3 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-package.test @@ -0,0 +1,10 @@ +--echo # +--echo # MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +--echo # + +SET @object_type='package_replace_pkg1'; +--source sp-package-concurrent-dml.inc + +SET @object_type='package_body_replace_pkg1'; +--source sp-package-concurrent-dml.inc + diff --git a/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-trigger.test b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-trigger.test new file mode 100644 index 00000000..09ba1d70 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-trigger.test @@ -0,0 +1,6 @@ +--echo # +--echo # MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +--echo # + +SET @object_type='trigger'; +--source sp-package-concurrent-dml.inc diff --git a/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-view.test b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-view.test new file mode 100644 index 00000000..d2c2041a --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml-view.test @@ -0,0 +1,6 @@ +--echo # +--echo # MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +--echo # + +SET @object_type='view'; +--source sp-package-concurrent-dml.inc diff --git a/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml.inc b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml.inc new file mode 100644 index 00000000..8ee96d1e --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-concurrent-dml.inc @@ -0,0 +1,107 @@ +--echo # +--echo # Start of sp-package-concurrent-dml.inc +--echo # + +--source include/count_sessions.inc + +let $object_type= `SELECT @object_type`; + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p2 AS + BEGIN + SELECT 'This is p2' AS msg; + END; + PROCEDURE p1 AS + BEGIN + SELECT 'This is p1' AS msg; + DO GET_LOCK('mdev15070',120); + CALL p2(); + DO RELEASE_LOCK('mdev15070'); + END; +END; +$$ +DELIMITER ;$$ + +connect (con2,localhost,root); +connection con2; +DO GET_LOCK('mdev15070', 120); + +connection default; +send CALL pkg1.p1; + +connection con2; +let $wait_condition= + SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST + WHERE state = "User lock" AND info LIKE "%GET_LOCK%mdev15070%"; +--source include/wait_condition.inc + + +if ($object_type==view) +{ + CREATE VIEW v1 AS SELECT 1 AS c; + DROP VIEW v1; +} + + +if ($object_type==package_replace_pkg1) +{ + SET sql_mode=ORACLE; + DELIMITER $$; + CREATE OR REPLACE PACKAGE pkg1 AS + PROCEDURE p1; + END; + $$ + DELIMITER ;$$ + DROP PACKAGE pkg1; +} + + +if ($object_type==package_body_replace_pkg1) +{ + SET sql_mode=ORACLE; + DELIMITER $$; + CREATE OR REPLACE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS + BEGIN + SELECT 'This is p1 version 2' AS msg; + END; + END; + $$ + DELIMITER ;$$ + DROP PACKAGE pkg1; +} + + +if ($object_type==trigger) +{ + CREATE TABLE t1 (a INT); + CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=1; + DROP TRIGGER tr1; + DROP TABLE t1; +} + + +if ($object_type=='db') +{ + CREATE DATABASE test1; + CREATE FUNCTION test1.f1() RETURNS INT RETURN 10; + DROP DATABASE test1; +} + + +DO RELEASE_LOCK('mdev15070'); + +disconnect con2; + +connection default; +reap; + +DROP PACKAGE IF EXISTS pkg1; + +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/suite/compat/oracle/t/sp-package-i_s.test b/mysql-test/suite/compat/oracle/t/sp-package-i_s.test new file mode 100644 index 00000000..a355e484 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-i_s.test @@ -0,0 +1,69 @@ +--source include/default_charset.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + + +--echo # +--echo # MDEV-30662 SQL/PL package body does not appear in I_S.ROUTINES.ROUTINE_DEFINITION +--echo # + +# Testing a package without the executable section + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg1 AS + FUNCTION f1() RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + FUNCTION f1() RETURN INT AS + BEGIN + RETURN 1; + END; +END; +$$ +DELIMITER ;$$ + +--vertical_results +SELECT routine_name, routine_type, routine_definition +FROM information_schema.routines +WHERE routine_type LIKE 'PACKAGE%' +ORDER BY routine_type; +--horizontal_results + +DROP PACKAGE pkg1; + +# Testing a package with the executable section + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg1 AS + FUNCTION f1() RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + FUNCTION f1() RETURN INT AS + BEGIN + RETURN 1; + END; +BEGIN + SET @a=10; + SET @a=f1(); +END; +$$ +DELIMITER ;$$ + +--vertical_results +SELECT routine_name, routine_type, routine_definition +FROM information_schema.routines +WHERE routine_type LIKE 'PACKAGE%' +ORDER BY routine_type; +--horizontal_results + +DROP PACKAGE pkg1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/mysql-test/suite/compat/oracle/t/sp-package-innodb.test b/mysql-test/suite/compat/oracle/t/sp-package-innodb.test new file mode 100644 index 00000000..94c7b714 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-innodb.test @@ -0,0 +1,66 @@ +-- source include/have_innodb.inc + +SET default_storage_engine=InnoDB; + +SET sql_mode=ORACLE; + +CREATE TABLE t1 (a INT, routine TEXT); +SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES +WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (10,'none'); + +--enable_prepare_warnings + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + a INT; + PROCEDURE p1 AS + BEGIN + a:=a+1; + INSERT INTO t1 VALUES (a,'p1'); + END; +BEGIN + SELECT MAX(t1.a) FROM t1 INTO a; + a:=a+1; + INSERT INTO t1 VALUES (a,'pkg1 initialization'); +END; +$$ +DELIMITER ;$$ +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +DELETE FROM t1; + +--source sp-cache-invalidate.inc +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +ROLLBACK; +SELECT * FROM t1 ORDER BY a; +DELETE FROM t1; + +--source sp-cache-invalidate.inc +INSERT INTO t1 VALUES (20,'none'); +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +COMMIT; +SELECT * FROM t1 ORDER BY a; +DELETE FROM t1; + +--source sp-cache-invalidate.inc +INSERT INTO t1 VALUES (20,'none'); +START TRANSACTION; +CALL pkg1.p1; +SELECT * FROM t1 ORDER BY a; +ROLLBACK; +SELECT * FROM t1 ORDER BY a; +DELETE FROM t1; + +--disable_prepare_warnings + +DROP PACKAGE pkg1; +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/t/sp-package-mdl.test b/mysql-test/suite/compat/oracle/t/sp-package-mdl.test new file mode 100644 index 00000000..de4f7aaa --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-mdl.test @@ -0,0 +1,110 @@ +--source include/have_metadata_lock_info.inc + +# +# This test demonstrates that: +# - A call to a package routine acquires a shared MDL lock on the entire package +# - "DROP PACKAGE" waits until the currently running package routines end +# + +SET sql_mode=ORACLE; +DO GET_LOCK('lock',300); + + +# +# conn1 will execute package pkg1 routines and +# and therefore acquire a shared MDL on "package body pkg1" +# + +connect (conn1,localhost,root,,); +SET sql_mode=ORACLE; +let $conn1_id= `SELECT CONNECTION_ID()`; +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS + BEGIN + DO GET_LOCK('lock',300); + END; + FUNCTION f1 RETURN INT AS + BEGIN + CALL p1; + RETURN 1; + END; +END; +$$ +DELIMITER ;$$ +send SELECT pkg1.f1(); + +# +# wait for conn1 to actually start execution of pkg1.p1 +# + +connection default; +let $wait_timeout= 60; +let $wait_condition= SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST +WHERE ID=$conn1_id AND INFO LIKE '%GET_LOCK%' AND STATE='User lock'; +--source include/wait_condition.inc + + +# +# conn2 will do "DROP PACKAGE pkg1". +# It will acquire an exclusive MDL on "package body pkg1", and therefore +# it should wait until conn1 ends the package routine execution +# + +connect (conn2,localhost,root,,); +let $conn2_id= `SELECT CONNECTION_ID()`; +SET sql_mode=ORACLE; +send DROP PACKAGE pkg1; + +# +# wait for conn2 to actually enter the "DROP" statement and get locked by conn1 +# +connection default; +let $wait_timeout= 60; +let $wait_condition= SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST +WHERE ID=$conn2_id + AND INFO LIKE '%DROP PACKAGE%' + AND STATE='Waiting for stored package body metadata lock'; +--source include/wait_condition.inc + +# +# Now we have three threads involved. +# The following I_S query will check that the threads are in these states: +# +# default (0) - is holding a user lock 'lock' +# conn1 (1) - is executing the package procedure test.pkg1.p1, +# is holding a shared MDL on 'package body pkg1', +# is waiting for the user lock 'lock' to be released +# conn2 (2) - is waiting for 'conn1' to end execution of test.pkg1.* routines, +# to acquire an exclusive MDL on 'package body pkg1', +# to DROP the package pkg1 +# +--vertical_results +SELECT ID-CONNECTION_ID() AS CONN,INFO,STATE,LOCK_MODE,LOCK_TYPE,TABLE_NAME + FROM INFORMATION_SCHEMA.PROCESSLIST + LEFT JOIN INFORMATION_SCHEMA.METADATA_LOCK_INFO + ON (ID=THREAD_ID) + ORDER BY ID,TABLE_NAME,LOCK_MODE,LOCK_TYPE; +--horizontal_results + +# +# Now let conn1 finish the package routine execution +# +DO RELEASE_LOCK('lock'); +connection conn1; +reap; +disconnect conn1; + +# +# Now conn2 should actually DROP the package +# +connection conn2; +reap; +disconnect conn2; + +connection default; diff --git a/mysql-test/suite/compat/oracle/t/sp-package-mysqldump.test b/mysql-test/suite/compat/oracle/t/sp-package-mysqldump.test new file mode 100644 index 00000000..c4e4b2a1 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-mysqldump.test @@ -0,0 +1,94 @@ +--source include/have_utf8mb4.inc +--source include/not_embedded.inc + +SET sql_mode=ORACLE; + +# +# Create a standalone procedure test.p1 and a package pkg1. +# The standalone routine test.p1 and the package routines call each other. +# + +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + SELECT pkg1.f1(); -- a standalone routine calls a package routine +END; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS + BEGIN + CALL test.p1; -- a package routine calls a standalone routine + END; + FUNCTION f1 RETURN INT AS + BEGIN + RETURN 10; + END; +END; +$$ +DELIMITER ;$$ + +CALL p1; +CALL pkg1.p1; +SELECT pkg1.f1(); + + +# +# Create specifications for one more package, without a BODY +# +DELIMITER $$; +CREATE PACKAGE pkg2 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ + + +--exec $MYSQL_DUMP --skip-comments --routines --default-character-set=utf8mb4 test +--exec $MYSQL_DUMP --skip-comments --routines --xml test + +let $dump = $MYSQLTEST_VARDIR/tmp/sp-package-mysqldump.sql; + +--exec $MYSQL_DUMP --compact --routines test > $dump + +DROP PACKAGE pkg1; +DROP PACKAGE pkg2; +DROP PROCEDURE p1; + +--exec $MYSQL test < $dump + +--vertical_results +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE STATUS; +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE BODY STATUS; +--horizontal_results + +SHOW CREATE PACKAGE pkg1; +SHOW CREATE PACKAGE pkg2; +SHOW CREATE PACKAGE BODY pkg1; + +CALL p1; +CALL pkg1.p1; +SELECT pkg1.f1(); + +DROP PACKAGE pkg1; +DROP PACKAGE pkg2; +DROP PROCEDURE p1; + +--echo # removing the dump file +--error 0,1 +--remove_file $dump diff --git a/mysql-test/suite/compat/oracle/t/sp-package-security.test b/mysql-test/suite/compat/oracle/t/sp-package-security.test new file mode 100644 index 00000000..583f70af --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package-security.test @@ -0,0 +1,332 @@ +--source include/not_embedded.inc +--source include/default_charset.inc + +SET sql_mode=ORACLE; + +CREATE DATABASE db1; +CREATE USER u1@localhost IDENTIFIED BY ''; +GRANT SELECT ON db1.* TO u1@localhost; + +connect (conn1,localhost,u1,,db1); +SELECT CURRENT_USER; +SET sql_mode=ORACLE; + +--echo # +--echo # User u1 cannot drop PROCEDURE, PACKAGE, PACKAGE BODY by default +--echo # + +--error ER_PROCACCESS_DENIED_ERROR +DROP PROCEDURE p1; +--error ER_PROCACCESS_DENIED_ERROR +DROP PACKAGE pkg1; +--error ER_PROCACCESS_DENIED_ERROR +DROP PACKAGE BODY pkg1; + +--echo # +--echo # User u1 cannot create PROCEDURE, PACKAGE, PACKAGE BODY by default +--echo # + +DELIMITER $$; +--error ER_DBACCESS_DENIED_ERROR +CREATE PROCEDURE p1 AS +BEGIN + NULL; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_DBACCESS_DENIED_ERROR +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +DELIMITER ;$$ + +# TODO: this should probably return ER_DBACCESS_DENIED_ERROR +DELIMITER $$; +--error ER_SP_DOES_NOT_EXIST +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Now create a PACKAGE by root +--echo # + +connection default; +USE db1; + +DELIMITER $$; +CREATE PROCEDURE p1root AS +BEGIN + SELECT 1; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +DELIMITER ;$$ +SHOW CREATE PACKAGE pkg1; + +--echo # +--echo # u1 cannot SHOW yet: +--echo # - the standalone procedure earlier created by root +--echo # - the package specifications earlier create by root +--echo # + +connection conn1; +--error ER_SP_DOES_NOT_EXIST +SHOW CREATE PROCEDURE p1root; +--error ER_SP_DOES_NOT_EXIST +SHOW CREATE PACKAGE pkg1; + + +--echo # +--echo # User u1 still cannot create a PACKAGE BODY +--echo # + +connection conn1; +DELIMITER $$; +--error ER_DBACCESS_DENIED_ERROR +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS BEGIN NULL; END; + FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Now grant EXECUTE: +--echo # - on the standalone procedure earlier created by root +--echo # - on the package specification earlier created by root +--echo # +connection default; +GRANT EXECUTE ON PROCEDURE db1.p1root TO u1@localhost; +GRANT EXECUTE ON PACKAGE db1.pkg1 TO u1@localhost; + +--echo # +--echo # Now u1 can do SHOW for: +--echo # - the standalone procedure earlier created by root +--echo # - the package specification earlier created by root +--echo # + +disconnect conn1; +connect (conn1,localhost,u1,,db1); +SET sql_mode=ORACLE; +SHOW CREATE PROCEDURE db1.p1root; +SHOW CREATE PACKAGE db1.pkg1; + + +--echo # +--echo # Now revoke EXECUTE and grant CREATE ROUTINE instead +--echo # + +connection default; +REVOKE EXECUTE ON PROCEDURE db1.p1root FROM u1@localhost; +REVOKE EXECUTE ON PACKAGE db1.pkg1 FROM u1@localhost; +GRANT CREATE ROUTINE ON db1.* TO u1@localhost; + +--echo # +--echo # Reconnect u1 to make new grants have effect +--echo # + +disconnect conn1; +connect (conn1,localhost,u1,,db1); +SET sql_mode=ORACLE; + +--echo # +--echo # Now u1 can SHOW: +--echo # - standalone routines earlier created by root +--echo # - package specifications earlier created by root +--echo # +SHOW CREATE PROCEDURE p1root; +SHOW CREATE PACKAGE pkg1; + +--echo # +--echo # Now u1 can CREATE, DROP and EXECUTE its own standalone procedures +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + NULL; +END; +$$ +DELIMITER ;$$ +SHOW GRANTS; +CALL p1; +DROP PROCEDURE p1; +SHOW GRANTS; + +--echo # +--echo # Now u1 can also CREATE, DROP its own package specifications +--echo # + +DELIMITER $$; +CREATE PACKAGE pkg2 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +DELIMITER ;$$ +SHOW CREATE PACKAGE pkg2; +SHOW GRANTS; +DROP PACKAGE pkg2; +SHOW GRANTS; + + +--echo # +--echo # Now u1 can also CREATE, DROP package bodies and EXECUTE package body routines +--echo # + +DELIMITER $$; +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS BEGIN SELECT 'This is pkg1.p1' AS `comment`; END; + FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is pkg1.f1'; END; +END; +$$ +DELIMITER ;$$ +SHOW CREATE PACKAGE pkg1; +SHOW CREATE PACKAGE BODY pkg1; +SHOW GRANTS; +CALL pkg1.p1; +SELECT pkg1.f1(); +DROP PACKAGE BODY pkg1; +SHOW GRANTS; + +--echo # +--echo # Now create a PACKAGE BODY by root. +--echo # u1 does not have EXECUTE access by default. +--echo # + +connection default; +DELIMITER $$; +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS BEGIN SELECT 'This is pkg1.p1' AS `comment`; END; + FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is pkg1.f1'; END; +END; +$$ +DELIMITER ;$$ + +connection conn1; +SHOW CREATE PACKAGE pkg1; +SHOW CREATE PACKAGE BODY pkg1; +--error ER_PROCACCESS_DENIED_ERROR +CALL pkg1.p1; +--error ER_PROCACCESS_DENIED_ERROR +SELECT pkg1.f1(); + +--echo # +--echo # Now grant EXECUTE to u1 on the PACKAGE BODY created by root +--echo # + +connection default; +GRANT EXECUTE ON PACKAGE BODY db1.pkg1 TO u1@localhost; +disconnect conn1; +connect (conn1,localhost,u1,,db1); +SELECT CURRENT_USER; +SET sql_mode=ORACLE; +SHOW GRANTS; +CALL pkg1.p1; +SELECT pkg1.f1(); + +connection default; +DROP PACKAGE BODY pkg1; + + +--echo # +--echo # u1 still cannot DROP the package specification earlier created by root. +--echo # + +connection conn1; +--error ER_PROCACCESS_DENIED_ERROR +DROP PACKAGE pkg1; + +--echo # +--echo # Grant ALTER ROUTINE to u1 +--echo # + +connection default; +GRANT ALTER ROUTINE ON db1.* TO u1@localhost; + +--echo # +--echo # Now u1 can DROP: +--echo # - the standalone procedure earlier created by root +--echo # - the package specification earlier created by root +--echo # + +disconnect conn1; +connect (conn1,localhost,u1,,db1); +SET sql_mode=ORACLE; +DROP PACKAGE pkg1; +DROP PROCEDURE p1root; + +disconnect conn1; +connection default; + +DROP USER u1@localhost; +DROP DATABASE db1; +USE test; + + +--echo # +--echo # Creator=root, definer=xxx +--echo # + +CREATE USER xxx@localhost; +DELIMITER $$; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS + PROCEDURE p1 AS + BEGIN + SELECT SESSION_USER(), CURRENT_USER(), 'p1.p1' AS msg; + END; +BEGIN + SELECT SESSION_USER(), CURRENT_USER(), 'package body p1' AS msg; +END; +$$ +DELIMITER ;$$ +--error ER_PROCACCESS_DENIED_ERROR +CALL p1.p1; +GRANT EXECUTE ON PACKAGE BODY test.p1 TO xxx@localhost; +CALL p1.p1; +DROP PACKAGE p1; +DROP USER xxx@localhost; + + +--echo # +--echo # Creator=root, definer=xxx, SQL SECURITY INVOKER +--echo # + +CREATE USER xxx@localhost; +DELIMITER $$; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS + PROCEDURE p1 AS + BEGIN + SELECT SESSION_USER(), CURRENT_USER(), 'p1.p1' AS msg; + END; +BEGIN + SELECT SESSION_USER(), CURRENT_USER(), 'package body p1' AS msg; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; +DROP USER xxx@localhost; diff --git a/mysql-test/suite/compat/oracle/t/sp-package.test b/mysql-test/suite/compat/oracle/t/sp-package.test new file mode 100644 index 00000000..b6310eed --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-package.test @@ -0,0 +1,3092 @@ +--source include/default_charset.inc + +SET sql_mode=ORACLE; + +--enable_prepare_warnings +--disable_ps2_protocol + +--echo # +--echo # Creating a body of a non-existing package +--echo # +DELIMITER $$; +--error ER_SP_DOES_NOT_EXIST +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +DELIMITER ;$$ + +--echo # +--echo # Dropping a non-existing package +--echo # +--error ER_SP_DOES_NOT_EXIST +DROP PACKAGE test2; +DROP PACKAGE IF EXISTS test2; +--error ER_SP_DOES_NOT_EXIST +DROP PACKAGE BODY test2; + + +--echo # +--echo # Bad combinations of OR REPLACE and IF EXISTS +--echo # + +DELIMITER $$; +--error ER_WRONG_USAGE +CREATE OR REPLACE PACKAGE IF NOT EXISTS pkg AS + PROCEDURE p1; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_WRONG_USAGE +CREATE OR REPLACE PACKAGE BODY IF NOT EXISTS pkg AS + PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # PACKAGE and PS +--echo # + +PREPARE stmt FROM 'CREATE PACKAGE test2 AS FUNCTION f1 RETURN INT; END test2'; + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ +PREPARE stmt FROM 'CREATE PACKAGE BODY test2 AS' + ' FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END;' + 'END test2'; +DROP PACKAGE test2; + + +--echo # +--echo # Package and READ ONLY transactions +--echo # + +SET SESSION TRANSACTION READ ONLY; + +DELIMITER $$; +--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END +$$ +DELIMITER ;$$ + +SET SESSION TRANSACTION READ WRITE; + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f2 RETURN INT; +END; +$$ +SET SESSION TRANSACTION READ ONLY +$$ +--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; + FUNCTION f2 RETURN INT AS BEGIN RETURN f1(); END; + PROCEDURE p1 AS + BEGIN + SELECT f2(); + END; +END; +$$ +DELIMITER ;$$ +SET SESSION TRANSACTION READ WRITE; +DROP PACKAGE test2; + +SET SESSION TRANSACTION READ ONLY; +--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION +DROP PACKAGE test2; +--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION +DROP PACKAGE BODY test2; + +SET SESSION TRANSACTION READ WRITE; + + +--echo # +--echo # Syntax error inside a CREATE PACKAGE, inside a routine definition +--echo # + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f2 RETURN INT; + FUNCTION f3; + FUNCTION f4 RETURN INT; +END +$$ +DELIMITER ;$$ + + +--echo # +--echo # Syntax error inside a CREATE PACKAGE, outside of a routine definition +--echo # + +# The definition "FUNCTION f3 RETURN INT AS BEGIN RETURN 10; END;" +# is valid in CREATE PACKAGE BODY, but not in CREATE PACKAGE. +# Syntax error happens after parsing "FUNCTION f3 RETURN INT". + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f2 RETURN INT; + FUNCTION f3 RETURN INT AS BEGIN RETURN 10; END; + FUNCTION f4 RETURN INT; +END +$$ +DELIMITER ;$$ + + +--echo # +--echo # Syntax error inside a CREATE PACKAGE BODY, inside a routine definition +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f2 RETURN INT; +END; +$$ +--error ER_PARSE_ERROR +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; + FUNCTION f2 RETURN INT SA BEGIN RETURN 10; END; -- Notice "SA" vs "AS" +END +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +--echo # +--echo # Syntax error inside a CREATE PACKAGE BODY, outside a routine definition +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f2 RETURN INT; +END; +$$ +--error ER_PARSE_ERROR +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; + SOME SYNTAX ERROR; + FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END; +END +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # Syntax error inside a CREATE PACKAGE BODY executable section +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +--error ER_PARSE_ERROR +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +BEGIN + SOME SYNTAX ERROR; +END +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # CREATE PROCEDURE inside a package PROCEDURE is not allowed +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_NO_RECURSIVE_CREATE +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS + BEGIN + CREATE PROCEDURE p1 AS BEGIN NULL; END; + END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # CREATE PACKAGE inside a package PROCEDURE is not allowed +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_NO_RECURSIVE_CREATE +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS + BEGIN + CREATE PACKAGE p1 AS PROCEDURE p1; END; + END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # CREATE PROCEDURE inside a package executable section is not allowed +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_NO_RECURSIVE_CREATE +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; +BEGIN + CREATE PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # CREATE FUNCTION inside a package executable section is not allowed +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_NO_RECURSIVE_CREATE +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; +BEGIN + CREATE FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # CREATE PACKAGE inside a package executable section is not allowed +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_NO_RECURSIVE_CREATE +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; +BEGIN + CREATE PACKAGE p1 AS PROCEDURE p1; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # Broken CREATE PACKAGE at CREATE PACKAGE BODY time +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ + +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; + +DELIMITER $$; +--error ER_SP_PROC_TABLE_CORRUPT +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT + AS BEGIN + RETURN f2(); + END; +END; +$$ +DELIMITER ;$$ +show warnings; + +DROP PACKAGE test2; + + +--echo # +--echo # Broken CREATE PACKAGE at a package function call time +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT + AS BEGIN + RETURN f2(); + END; +END; +$$ +DELIMITER ;$$ + +--error ER_SP_DOES_NOT_EXIST +SELECT test2.f1(); +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; +--source sp-cache-invalidate.inc +--error ER_SP_PROC_TABLE_CORRUPT +SELECT test2.f1(); +show warnings; +--error ER_SP_PROC_TABLE_CORRUPT +SELECT test2.f1(); +show warnings; +--error ER_SP_PROC_TABLE_CORRUPT +SELECT test2.f1(); +show warnings; + +DROP PACKAGE test2; + + +--echo # +--echo # Broken CREATE PACKAGE at a package procedure call time +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 + AS BEGIN + CALL p2; + END; +END; +$$ +DELIMITER ;$$ + +--error ER_SP_DOES_NOT_EXIST +CALL test2.f1(); +UPDATE mysql.proc SET `body`='garbage' + WHERE db='test' AND name='test2' AND type='PACKAGE'; +--source sp-cache-invalidate.inc +--error ER_SP_PROC_TABLE_CORRUPT +CALL test2.p1(); +show warnings; +--error ER_SP_PROC_TABLE_CORRUPT +CALL test2.p1(); +show warnings; +--error ER_SP_PROC_TABLE_CORRUPT +CALL test2.p1(); +show warnings; + +DROP PACKAGE test2; + + +--echo # +--echo # Bad routine names +--echo # + +DELIMITER $$; +--error ER_TOO_LONG_IDENT +CREATE PACKAGE p1 AS + PROCEDURE pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp1; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_TOO_LONG_IDENT +CREATE PACKAGE p1 AS + FUNCTION fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1 + RETURN INT; +END; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_SP_WRONG_NAME +CREATE PACKAGE p1 AS + PROCEDURE "p1 "; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_SP_WRONG_NAME +CREATE PACKAGE p1 AS + FUNCTION "f1 " RETURN INT; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_SP_WRONG_NAME +CREATE PACKAGE p1 AS + PROCEDURE "p1.p1"; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_SP_WRONG_NAME +CREATE PACKAGE p1 AS + FUNCTION "f1.f1" RETURN INT; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Duplicate PROCEDURE in CREATE PACKAGE +--echo # + +DELIMITER $$; +--error ER_SP_ALREADY_EXISTS, +CREATE PACKAGE test2 AS + PROCEDURE p1; + PROCEDURE p1; +END; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_SP_ALREADY_EXISTS, +CREATE PACKAGE test2 AS + PROCEDURE p1; + PROCEDURE P1; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Duplicate FUNCTION in CREATE PACKAGE +--echo # + +DELIMITER $$; +--error ER_SP_ALREADY_EXISTS, +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_SP_ALREADY_EXISTS, +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + FUNCTION F1 RETURN INT; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Duplicate PROCEDURE in CREATE PACKAGE BODY +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_SP_ALREADY_EXISTS +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; + PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +--error ER_SP_ALREADY_EXISTS +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; + PROCEDURE P1 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # Duplicate FUNCTION in CREATE PACKAGE BODY +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +--error ER_SP_ALREADY_EXISTS +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; + FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +--error ER_SP_ALREADY_EXISTS +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 0; END; + FUNCTION F1 RETURN INT AS BEGIN RETURN 0; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # Routines declared in CREATE PACKAGE missing in CREATE PACKAGE BODY +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY +CREATE PACKAGE BODY test2 AS + PROCEDURE p2 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; +END; +$$ +--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY +CREATE PACKAGE BODY test2 AS + FUNCTION f2 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY +CREATE PACKAGE BODY test2 AS + FUNCTION p1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY +CREATE PACKAGE BODY test2 AS + PROCEDURE p1(a INT) AS BEGIN NULL; END; -- Notice different prototype +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +--echo # +--echo # Forward declarations in CREATE PACKAGE BODY with missing implementations +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS BEGIN NULL; END; + PROCEDURE p2; +END; +$$ +--error ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1 AS BEGIN NULL; END; +END; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # Creating a new package +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 COMMENT 'package-test2-comment' AS + FUNCTION f1 RETURN INT DETERMINISTIC; + FUNCTION f2(a INT) RETURN INT; + FUNCTION concat RETURN INT; + PROCEDURE p1; + PROCEDURE p2(a INT); +END +$$ +DELIMITER ;$$ + +--vertical_results +--replace_column 13 # 14 # +SELECT * FROM mysql.proc WHERE db='test' AND name='test2'; +--replace_column 24 # 25 # +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME='test2'; +--horizontal_results + +DELIMITER $$; +CREATE PACKAGE IF NOT EXISTS test2 AS + FUNCTION f1 RETURN INT; +END test2 +$$ +DELIMITER ;$$ + + +DELIMITER $$; +CREATE PACKAGE BODY test2 COMMENT 'package-body-test2-comment' AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; + FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; + FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; + PROCEDURE p1 AS + BEGIN + SELECT f2(0); + END; + PROCEDURE p2(a INT) AS + BEGIN + SELECT f2(a); + END; +END; +$$ +DELIMITER ;$$ + +# This should do nothing and return a warning +DELIMITER $$; +CREATE PACKAGE BODY IF NOT EXISTS test2 AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 20; END; + FUNCTION f2(a INT) RETURN INT AS BEGIN RETURN f1()+a; END; + FUNCTION concat RETURN INT AS BEGIN RETURN 1; END; + PROCEDURE p1 AS + BEGIN + SELECT f2(0); + END; + PROCEDURE p2(a INT) AS + BEGIN + SELECT f2(a); + END; +END; +$$ +DELIMITER ;$$ + +# +# The next query issues a warning about "concat" name collision, +# raised during compilation of the package body. +# However, "mtr --ps" does not produce the warning. +# It's not a package specific issue. The same difference exists for +# standalone functions. So just suppress warning for now. +# +--disable_warnings +SELECT test2.f1(); +--enable_warnings +SELECT test2.f2(1); +CALL test2.p1(); +CALL test2.p2(1); + +--vertical_results +--replace_column 13 # 14 # +SELECT * FROM mysql.proc WHERE db='test' AND name LIKE 'test2.%'; +--replace_column 24 # 25 # +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME='test2'; +--replace_column 24 # 25 # +SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='test' AND ROUTINE_NAME LIKE 'test2.%'; +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE STATUS; +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE BODY STATUS; +SHOW CREATE PACKAGE test2; +SHOW CREATE PACKAGE BODY test2; +--horizontal_results + + + +DROP PACKAGE BODY test2; +--error ER_SP_DOES_NOT_EXIST +SELECT test2.f1(); +--error ER_SP_DOES_NOT_EXIST +SELECT test2.f2(); +--error ER_SP_DOES_NOT_EXIST +CALL test2.p1(); + +DROP PACKAGE BODY IF EXISTS test2; + +--error ER_SP_DOES_NOT_EXIST +DROP PACKAGE BODY test2; + + +DROP PACKAGE test2; + + +--echo # +--echo # Creating a new package in a remote database +--echo # + +CREATE DATABASE test2; + +DELIMITER $$; +CREATE PACKAGE test2.test2 COMMENT 'package-test2-comment' AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE BODY test2.test2 COMMENT 'package-body-test2-comment' AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; + PROCEDURE p1 AS BEGIN SELECT f1(); END; +END; +$$ +DELIMITER ;$$ + +--vertical_results +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE STATUS; +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +SHOW PACKAGE BODY STATUS; +--horizontal_results + +USE test2; +SELECT test2.f1(); +CALL test2.p1(); +USE test; +DROP PACKAGE BODY test2.test2; +DROP PACKAGE test2.test2; +DROP DATABASE test2; + + +--echo # +--echo # Only public routines are available outside +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS + -- Public routines + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is test2.f1'; + END; + PROCEDURE p1 AS + BEGIN + SELECT 'This is test2.p1'; + END; + -- Private routines + FUNCTION f2 RETURN TEXT AS + BEGIN + RETURN 'This is test2.f2'; + END; + PROCEDURE p2 AS + BEGIN + SELECT 'This is test2.p2'; + END; +END; +$$ +DELIMITER ;$$ +SELECT test2.f1(); +CALL test2.p1(); +--error ER_SP_DOES_NOT_EXIST +SELECT test2.f2(); +--error ER_SP_DOES_NOT_EXIST +CALL test2.p2(); +DROP PACKAGE test2; + + +--echo # +--echo # PACKAGE BODY with forward declarations +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS + -- Forward declarations + FUNCTION f2private RETURN TEXT; + PROCEDURE p2private; + -- Public routines + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN f2private(); + END; + PROCEDURE p1 AS + BEGIN + CALL p2private; + END; + -- Definitions for the forward declarations + FUNCTION f2private RETURN TEXT AS + BEGIN + RETURN 'This is f2private'; + END; + PROCEDURE p2private AS + BEGIN + SELECT 'This is p2private'; + END; +END; +$$ +DELIMITER ;$$ +SELECT test2.f1(); +CALL test2.p1(); +DROP PACKAGE test2; + + +--echo # +--echo # Calling private routines with forward declarations, +--echo # using qualified notation, e.g. "CALL pkg.proc" +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS + -- Forward declarations + FUNCTION f2private RETURN TEXT; + PROCEDURE p2private; + -- Public routines + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN test2.f2private(); + END; + PROCEDURE p1 AS + BEGIN + CALL test2.p2private; + END; + -- Definitions for the forward declarations + FUNCTION f2private RETURN TEXT AS + BEGIN + RETURN 'This is f2private'; + END; + PROCEDURE p2private AS + BEGIN + SELECT 'This is p2private' AS msg; + END; +END; +$$ +DELIMITER ;$$ +SELECT test2.f1(); +CALL test2.p1(); +DROP PACKAGE test2; + + +--echo # +--echo # Calling private routines, using qualified notation, e.g. "pkg.proc" +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS + -- Private routines + FUNCTION f2private RETURN TEXT AS + BEGIN + RETURN 'This is f2private'; + END; + PROCEDURE p2private AS + BEGIN + SELECT 'This is p2private' AS msg; + END; + -- Public routines + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN test2.f2private(); + END; + PROCEDURE p1 AS + BEGIN + CALL test2.p2private; + END; +END; +$$ +DELIMITER ;$$ +SELECT test2.f1(); +CALL test2.p1(); +DROP PACKAGE test2; + + +--echo # +--echo # Calling private routines from the package initialization section, +--echo # using qualified notation, e.g. "pkg.proc" +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY test2 AS + -- Private routines + FUNCTION f2private RETURN TEXT AS + BEGIN + RETURN 'This is f2private'; + END; + PROCEDURE p2private AS + BEGIN + SELECT 'This is p2private' AS msg; + END; + -- Public routines + PROCEDURE p1 AS + BEGIN + SELECT 'This is p1' AS msg; + END; +BEGIN + SELECT test2.f2private(); + CALL test2.p2private(); +END; +$$ +DELIMITER ;$$ +CALL test2.p1(); +DROP PACKAGE test2; + + +--echo # +--echo # Testing OR REPLACE +--echo # + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg AS + FUNCTION f0 RETURN INT; +END; +$$ +CREATE OR REPLACE PACKAGE pkg AS + FUNCTION f1 RETURN INT; +END; +$$ +DELIMITER ;$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; + +DELIMITER $$; +CREATE OR REPLACE PACKAGE BODY pkg AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 10; END; +END; +$$ +DELIMITER ;$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +SELECT pkg.f1(); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE BODY pkg AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 20; END; +END; +$$ +DELIMITER ;$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +SELECT pkg.f1(); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg AS + FUNCTION f1 RETURN BIGINT; +END; +$$ +DELIMITER ;$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +--error ER_SP_DOES_NOT_EXIST +SELECT pkg.f1(); + +DELIMITER $$; +CREATE OR REPLACE PACKAGE BODY pkg AS + FUNCTION f1 RETURN INT AS BEGIN RETURN 30; END; +END; +$$ +DELIMITER ;$$ +SELECT name, type, `body` FROM mysql.proc WHERE name LIKE 'pkg%' ORDER BY type; +SELECT pkg.f1(); + +DROP PACKAGE pkg; + + +--echo # +--echo # Package routines accessing tables +--echo # +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE PACKAGE test2 AS + PROCEDURE p1(a INT); +END; +$$ +CREATE PACKAGE BODY test2 AS + PROCEDURE p1(a INT) AS + BEGIN + INSERT INTO t1 VALUES (10); + END; +END; +$$ +DELIMITER ;$$ +CALL test2.p1(10); +SELECT * FROM t1; +DROP PACKAGE test2; +DROP TABLE t1; + + +--echo # +--echo # CREATE PACKAGE: Optional package name after the "END" keyword +--echo # + +DELIMITER $$; +--error ER_END_IDENTIFIER_DOES_NOT_MATCH +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END test2.test2 +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_END_IDENTIFIER_DOES_NOT_MATCH +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END test3 +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END test2 +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + + +--echo # +--echo # MDEV-12089 sql_mode=ORACLE: Understand optional routine name after the END keyword +--echo # + + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN INT; + PROCEDURE p1; +END test2; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS + BEGIN + RETURN 10; + END f1.f1; +END test2; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_END_IDENTIFIER_DOES_NOT_MATCH +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS + BEGIN + RETURN 10; + END f2; +END test2; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS + BEGIN + NULL; + END p1.p1; +END test2; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +--error ER_END_IDENTIFIER_DOES_NOT_MATCH +CREATE PACKAGE BODY test2 AS + PROCEDURE p1 AS + BEGIN + NULL; + END p2; +END test2; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN INT AS + BEGIN + RETURN 10; + END f1; + PROCEDURE p1 AS + BEGIN + NULL; + END p1; +END test2; +$$ +DELIMITER ;$$ +DROP PACKAGE test2; + +--echo # +--echo # Package and package routine name and end name are case insensitive +--echo # + +DELIMITER $$; +CREATE PACKAGE test2 AS + FUNCTION f1 RETURN TEXT; + PROCEDURE p1; +END TEST2; +$$ +DELIMITER ;$$ + +DELIMITER $$; +CREATE PACKAGE BODY test2 AS + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is f1'; + END F1; + PROCEDURE P1 AS + BEGIN + SELECT 'This is p1' AS msg; + END p1; +END TEST2; +$$ +DELIMITER ;$$ +SELECT TEST2.F1(); +SELECT test2.f1(); +CALL TEST2.p1(); +CALL test2.P1(); +DROP PACKAGE BODY TEST2; +DROP PACKAGE TEST2; + + +--echo # +--echo # Testing various qualified/non-qualified db/package SP call chains +--echo # + +DELIMITER $$; +CREATE FUNCTION f3() RETURN TEXT AS +BEGIN + SET @track= @track || ' ' || 'test.f3()'; + RETURN ''; +END; +$$ +CREATE PROCEDURE p3() AS +BEGIN + SET @track= @track || ' ' || 'test.p3()'; +END; +$$ +CREATE FUNCTION ff2(task TEXT) RETURN TEXT AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; +BEGIN + SET @track= @track || ' ' || 'test.ff2()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; + RETURN ''; +END; +$$ +CREATE PROCEDURE pp2(task TEXT) AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; +BEGIN + SET @track= @track || ' ' || 'test.pp2()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; +END; +$$ +CREATE PACKAGE pack AS + PROCEDURE p1(task TEXT); + PROCEDURE p2(task TEXT); + FUNCTION f1(task TEXT) RETURN TEXT; + FUNCTION f2(step2 TEXT) RETURN TEXT; + FUNCTION f3 RETURN TEXT; + PROCEDURE p3; +END; +$$ +CREATE PACKAGE BODY pack AS + PROCEDURE p1(task TEXT) AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; + BEGIN + SET @track= 'test.pack.p1()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p2' THEN CALL p2(tail); + WHEN 'f2' THEN rc:= f2(tail); + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'px' THEN CALL px(); + WHEN 'fx' THEN rc:= fx(); + WHEN 'pp2' THEN CALL pp2(tail); + WHEN 'ff2' THEN rc:= ff2(tail); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'pack.px' THEN CALL pack.px(); + WHEN 'pack.fx' THEN rc:= pack.fx(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; + SELECT @track; + END; + + FUNCTION f1(task TEXT) RETURN TEXT AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; + BEGIN + SET @track= 'test.pack.f1()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p2' THEN CALL p2(tail); + WHEN 'f2' THEN rc:= f2(tail); + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'px' THEN CALL px(); + WHEN 'fx' THEN rc:= fx(); + WHEN 'pp2' THEN CALL pp2(tail); + WHEN 'ff2' THEN rc:= ff2(tail); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'pack.px' THEN CALL pack.px(); + WHEN 'pack.fx' THEN rc:= pack.fx(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; + SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT=@track; + RETURN ''; + END; + + PROCEDURE p2(task TEXT) AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; + BEGIN + SET @track= @track || ' ' || 'test.pack.p2()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p2' THEN CALL p2(tail); + WHEN 'f2' THEN rc:= f2(tail); + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'px' THEN CALL px(); + WHEN 'fx' THEN rc:= fx(); + WHEN 'pp2' THEN CALL pp2(tail); + WHEN 'ff2' THEN rc:= ff2(tail); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'pack.px' THEN CALL pack.px(); + WHEN 'pack.fx' THEN rc:= pack.fx(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; + END; + + FUNCTION f2(task TEXT) RETURN TEXT AS + step TEXT := REGEXP_SUBSTR(task,'^[^ ]*'); + tail TEXT := REGEXP_REPLACE(task,'^[^ ]*[ ]*(.*)','\\1'); + rc TEXT; + BEGIN + SET @track= @track || ' ' || 'test.pack.f2()'; + CASE step + WHEN '' THEN NULL; + WHEN 'p2' THEN CALL p2(tail); + WHEN 'f2' THEN rc:= f2(tail); + WHEN 'p3' THEN CALL p3(); + WHEN 'f3' THEN rc:= f3(); + WHEN 'px' THEN CALL px(); + WHEN 'fx' THEN rc:= fx(); + WHEN 'pp2' THEN CALL pp2(tail); + WHEN 'ff2' THEN rc:= ff2(tail); + WHEN 'pack.p2' THEN CALL pack.p2(tail); + WHEN 'pack.f2' THEN rc:= pack.f2(tail); + WHEN 'pack.p3' THEN CALL pack.p3(); + WHEN 'pack.f3' THEN rc:= pack.f3(); + WHEN 'pack.px' THEN CALL pack.px(); + WHEN 'pack.fx' THEN rc:= pack.fx(); + WHEN 'test.p3' THEN CALL test.p3(); + WHEN 'test.f3' THEN rc:= test.f3(); + WHEN 'test.pp2' THEN CALL test.pp2(tail); + WHEN 'test.ff2' THEN rc:= test.ff2(tail); + ELSE SET @track= @track || ' ' || step || ' [unknown step]'; + END CASE; + RETURN ''; + END; + PROCEDURE p3 AS + BEGIN + SET @track= @track || ' ' || 'test.pack.p3()'; + END; + FUNCTION f3 RETURN TEXT AS + BEGIN + SET @track= @track || ' ' || 'test.pack.f3()'; + RETURN ''; + END; + +END pack; +$$ +DELIMITER ;$$ + +SET max_sp_recursion_depth=10; + +--echo # pack.routine -> * + +CALL pack.p1('p2'); +CALL pack.p1('f2'); +--error ER_SP_DOES_NOT_EXIST +CALL pack.p1('px'); +--error ER_SP_DOES_NOT_EXIST +CALL pack.p1('fx'); + +CALL pack.p1('pp2'); +CALL pack.p1('ff2'); + +CALL pack.p1('pack.p2'); +CALL pack.p1('pack.f2'); +--error ER_SP_DOES_NOT_EXIST +CALL pack.p1('pack.px'); +--error ER_SP_DOES_NOT_EXIST +CALL pack.p1('pack.fx'); + +CALL pack.p1('test.pp2'); +CALL pack.p1('test.ff2'); + +DO pack.f1('p2'); +DO pack.f1('f2'); +--error ER_SP_DOES_NOT_EXIST +DO pack.p1('px'); +--error ER_SP_DOES_NOT_EXIST +DO pack.p1('fx'); + +DO pack.f1('pp2'); +DO pack.f1('ff2'); + +DO pack.f1('pack.p2'); +DO pack.f1('pack.f2'); +--error ER_SP_DOES_NOT_EXIST +SELECT pack.f1('pack.px'); +--error ER_SP_DOES_NOT_EXIST +SELECT pack.f1('pack.fx'); + +DO pack.f1('test.pp2'); +DO pack.f1('test.ff2'); + +--echo # +--echo # Qualified_package_routine -> Non_qualified_package_routine +--echo # + +--echo # pack.routine -> [pack.]routine -> pack.routine + +CALL pack.p1('p2 pack.p3'); +CALL pack.p1('p2 pack.f3'); +CALL pack.p1('f2 pack.p3'); +CALL pack.p1('f2 pack.f3'); + +DO pack.f1('p2 pack.p3'); +DO pack.f1('p2 pack.f3'); +DO pack.f1('f2 pack.p3'); +DO pack.f1('f2 pack.f3'); + +--echo # pack.routine -> [pack.]routine -> [pack]routine + +CALL pack.p1('p2 p3'); +CALL pack.p1('p2 f3'); +CALL pack.p1('f2 p3'); +CALL pack.p1('f2 f3'); + +DO pack.f1('p2 p3'); +DO pack.f1('p2 f3'); +DO pack.f1('f2 p3'); +DO pack.f1('f2 f3'); + +--echo # pack.routine -> [pack.]routine -> test.routine + +CALL pack.p1('p2 test.p3'); +CALL pack.p1('p2 test.f3'); +CALL pack.p1('f2 test.p3'); +CALL pack.p1('f2 test.f3'); + +DO pack.f1('p2 test.p3'); +DO pack.f1('p2 test.f3'); +DO pack.f1('f2 test.p3'); +DO pack.f1('f2 test.f3'); + +--echo # pack.routine -> [pack.]routine -> [test.]routine + +CALL pack.p1('p2 pp2'); +CALL pack.p1('p2 ff2'); +CALL pack.p1('f2 pp2'); +CALL pack.p1('f2 ff2'); + +DO pack.f1('p2 pp2'); +DO pack.f1('p2 ff2'); +DO pack.f1('f2 pp2'); +DO pack.f1('f2 ff2'); + + +--echo # +--echo # Qualified_package_routine -> Non_qualified_database_routine +--echo # + +--echo # pack.routine -> [test.]routine -> pack.routine + +CALL pack.p1('pp2 pack.p3'); +CALL pack.p1('pp2 pack.f3'); +CALL pack.p1('ff2 pack.p3'); +CALL pack.p1('ff2 pack.f3'); + +DO pack.f1('pp2 pack.p3'); +DO pack.f1('pp2 pack.f3'); +DO pack.f1('ff2 pack.p3'); +DO pack.f1('ff2 pack.f3'); + +--echo # pack.routine -> [test.]routine -> test.routine + +CALL pack.p1('pp2 test.p3'); +CALL pack.p1('pp2 test.f3'); +CALL pack.p1('ff2 test.p3'); +CALL pack.p1('ff2 test.f3'); + +DO pack.f1('pp2 test.p3'); +DO pack.f1('pp2 test.f3'); +DO pack.f1('ff2 test.p3'); +DO pack.f1('ff2 test.f3'); + +--echo # pack.routine -> [test.]routine -> [test.]routine + +CALL pack.p1('pp2 p3'); +CALL pack.p1('pp2 f3'); +CALL pack.p1('ff2 p3'); +CALL pack.p1('ff2 f3'); + +DO pack.f1('pp2 p3'); +DO pack.f1('pp2 f3'); +DO pack.f1('ff2 p3'); +DO pack.f1('ff2 f3'); + + +--echo # +--echo # Qualified_package_routine -> Qualified_package_routine +--echo # + +--echo # pack.routine -> pack.routine -> pack.routine + +CALL pack.p1('pack.p2 pack.p3'); +CALL pack.p1('pack.p2 pack.f3'); +CALL pack.p1('pack.f2 pack.p3'); +CALL pack.p1('pack.f2 pack.f3'); + +DO pack.f1('pack.p2 pack.p3'); +DO pack.f1('pack.p2 pack.f3'); +DO pack.f1('pack.f2 pack.p3'); +DO pack.f1('pack.f2 pack.f3'); + +--echo # pack.routine -> pack.routine -> [pack.]routine + +CALL pack.p1('pack.p2 p3'); +CALL pack.p1('pack.p2 f3'); +CALL pack.p1('pack.f2 p3'); +CALL pack.p1('pack.f2 f3'); + +DO pack.f1('pack.p2 p3'); +DO pack.f1('pack.p2 f3'); +DO pack.f1('pack.f2 p3'); +DO pack.f1('pack.f2 f3'); + +--echo # pack.routine -> pack.routine -> test.routine + +CALL pack.p1('pack.p2 test.p3'); +CALL pack.p1('pack.p2 test.f3'); +CALL pack.p1('pack.f2 test.p3'); +CALL pack.p1('pack.f2 test.f3'); + +DO pack.f1('pack.p2 test.p3'); +DO pack.f1('pack.p2 test.f3'); +DO pack.f1('pack.f2 test.p3'); +DO pack.f1('pack.f2 test.f3'); + +--echo # pack.routine -> pack.routine -> [test.]routine + +CALL pack.p1('pack.p2 pp2'); +CALL pack.p1('pack.p2 ff2'); +CALL pack.p1('pack.f2 pp2'); +CALL pack.p1('pack.f2 ff2'); + +DO pack.f1('pack.p2 pp2'); +DO pack.f1('pack.p2 ff2'); +DO pack.f1('pack.f2 pp2'); +DO pack.f1('pack.f2 ff2'); + + +--echo # +--echo # Qualified_package_routine -> Qualified_database_routine +--echo # + +--echo pack.routine -> test.routine -> pack.routine + +CALL pack.p1('test.pp2 pack.p3'); +CALL pack.p1('test.pp2 pack.f3'); +CALL pack.p1('test.ff2 pack.p3'); +CALL pack.p1('test.ff2 pack.f3'); + +DO pack.f1('test.pp2 pack.p3'); +DO pack.f1('test.pp2 pack.f3'); +DO pack.f1('test.ff2 pack.p3'); +DO pack.f1('test.ff2 pack.f3'); + +--echo pack.routine -> test.routine -> test.routine + +CALL pack.p1('test.pp2 test.p3'); +CALL pack.p1('test.pp2 test.f3'); +CALL pack.p1('test.ff2 test.p3'); +CALL pack.p1('test.ff2 test.f3'); + +DO pack.f1('test.pp2 test.p3'); +DO pack.f1('test.pp2 test.f3'); +DO pack.f1('test.ff2 test.p3'); +DO pack.f1('test.ff2 test.f3'); + +--echo pack.routine -> test.routine -> [test.]routine + +CALL pack.p1('test.pp2 p3'); +CALL pack.p1('test.pp2 f3'); +CALL pack.p1('test.ff2 p3'); +CALL pack.p1('test.ff2 f3'); + +DO pack.f1('test.pp2 p3'); +DO pack.f1('test.pp2 f3'); +DO pack.f1('test.ff2 p3'); +DO pack.f1('test.ff2 f3'); + + +--echo # Longer chains + +CALL pack.p1('p2 f2 p2 test.pp2 test.ff2 pack.p3'); +CALL pack.p1('p2 test.pp2 pack.p2 pack.f2 test.ff2 pack.p3'); + + +DROP PACKAGE pack; +DROP FUNCTION f3; +DROP PROCEDURE p3; +DROP FUNCTION ff2; +DROP PROCEDURE pp2; + + +--echo # +--echo # Calling a standalone function from a non-current database, +--echo # which calls a package routine from the same non-current database. +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + CALL pkg1.p1; +END; +$$ +CREATE PACKAGE pkg1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + PROCEDURE p1 AS + BEGIN + SELECT database(); + END; +END; +$$ +DELIMITER ;$$ +# Current database +CALL p1; +CREATE DATABASE test2; +USE test2; +# Non-current database +CALL test.p1; +DROP DATABASE test2; +# No current database at all +CALL test.p1; +USE test; +DROP PACKAGE pkg1; +DROP PROCEDURE p1; + + +--echo # +--echo # Creating a package with a different DEFINER +--echo # + +CREATE USER xxx@localhost; +DELIMITER $$; +CREATE DEFINER=xxx@localhost PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 AS + PROCEDURE p1 AS + BEGIN + NULL; + END; +END; +$$ +DELIMITER ;$$ +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +DROP PACKAGE p1; +DROP USER xxx@localhost; + +--echo # +--echo # Creating a package with a different DEFINER, with SQL SECURITY INVOKER +--echo # + +CREATE USER xxx@localhost; +DELIMITER $$; +CREATE DEFINER=xxx@localhost PACKAGE p1 SQL SECURITY INVOKER AS + PROCEDURE p1; +END; +$$ +CREATE DEFINER=xxx@localhost PACKAGE BODY p1 SQL SECURITY INVOKER AS + PROCEDURE p1 AS + BEGIN + NULL; + END; +END; +$$ +DELIMITER ;$$ +SELECT definer, name, security_type, type FROM mysql.proc WHERE name LIKE 'p1%' ORDER BY definer, name, type; +DROP PACKAGE p1; +DROP USER xxx@localhost; + +--echo # +--echo # A package with an initialization section +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; + FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN + SET @a:=10; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; + + +--echo # +--echo # A package with an initialization section calling +--echo # routines from the same package, and standalone routines. +--echo # + +DELIMITER $$; +CREATE PROCEDURE init20 AS +BEGIN + SET @msg= @msg || '[init20]'; +END; +$$ +CREATE PACKAGE p1 AS + PROCEDURE init1; + PROCEDURE init2; + FUNCTION init3 RETURN INT; + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE init1 AS + BEGIN + SET @msg= @msg || '[p1.init1]'; + END; + PROCEDURE init2 AS + BEGIN + SET @msg= @msg || '[p1.init2]'; + END; + FUNCTION init3 RETURN INT AS + BEGIN + SET @msg= @msg || '[p1.init3]'; + RETURN 0; + END; + PROCEDURE p1 AS + BEGIN + SET @msg= @msg || '[p1.p1]'; + SELECT @msg; + END; + FUNCTION f1 RETURN TEXT AS + BEGIN + SET @msg= @msg || '[p1.f1]'; + RETURN @msg; + END; +BEGIN + SET @msg= ''; + init1(); + init2(); + DO init3(); + init20(); +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; +DROP PROCEDURE init20; + + +--echo # +--echo # EXECUTE IMMEDIATE in the package initialization section +--echo # + +SET @a=1000; +CREATE TABLE t1 AS SELECT 10 AS a; +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; + FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN + EXECUTE IMMEDIATE 'SELECT MAX(a) FROM t1 INTO @a'; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +SELECT p1.f1(); +DROP PACKAGE p1; +DROP TABLE t1; + + +--echo # +--echo # A package with an initialization section, loading table data into a user variable +--echo # + +SET @a=1000; +CREATE TABLE t1 AS SELECT 10 AS a; +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS BEGIN SET @a=@a+1; SELECT @a; END; + FUNCTION f1 RETURN INT AS BEGIN SET @a=@a+1; RETURN @a; END; +BEGIN + SELECT MAX(a) FROM t1 INTO @a; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +DROP PACKAGE p1; +DROP TABLE t1; + +--echo # +--echo # A package with an initialization section producing an error +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS BEGIN SELECT 'This is p1' AS msg; END; + FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +BEGIN + SELECT 1 FROM t1 INTO @a; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1.p1(); +--error ER_NO_SUCH_TABLE +SELECT p1.f1(); +--source sp-cache-invalidate.inc +--error ER_NO_SUCH_TABLE +SELECT p1.f1(); +--error ER_NO_SUCH_TABLE +CALL p1.p1(); +--error ER_NO_SUCH_TABLE +SELECT p1.f1(); +CREATE TABLE t1 (a INT) AS SELECT 1; +CALL p1.p1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +--source sp-cache-invalidate.inc +CALL p1.p1(); +DROP TABLE t1; +DROP PACKAGE p1; + + +--echo # +--echo # A package with SF-unsafe statements in the initialization section +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS BEGIN SELECT 'This is p1' AS msg; END; + FUNCTION f1 RETURN TEXT AS BEGIN RETURN 'This is f1'; END; +BEGIN + CREATE TABLE IF NOT EXISTS t1 (a INT); + DROP TABLE IF EXISTS t1; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +DROP PACKAGE p1; + + +--echo # +--echo # MDEV-13139 Package-wide variables in CREATE PACKAGE +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +--error ER_SP_DUP_VAR +CREATE PACKAGE BODY p1 AS + a INT; + a INT; + PROCEDURE p1 AS + BEGIN + CREATE VIEW v1 AS SELECT a; + END; +END; +$$ +--error ER_PARSE_ERROR +CREATE PACKAGE BODY p1 AS + a INT; + PROCEDURE p1 AS + BEGIN + NULL; + END; + b INT; -- Variables cannot go after routine definitions +END; +$$ +--error ER_VIEW_SELECT_VARIABLE +CREATE PACKAGE BODY p1 AS + a INT; + PROCEDURE p1 AS + BEGIN + CREATE VIEW v1 AS SELECT a; + END; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT:=NULL; + PROCEDURE p1 AS + BEGIN + SELECT a; + a:=COALESCE(a,0)+100; + SET a=a+1; + END; + FUNCTION f1 RETURN INT AS + BEGIN + RETURN a; + END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +CALL p1.p1; +CALL p1.p1; +SELECT p1.f1(); +DROP PACKAGE p1; + + +--echo # +--echo # One package variable with a default value +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT:=10; + PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; + FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; + + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a ROW (a INT, b TEXT):=ROW(10,'bbb'); + PROCEDURE p1 AS + BEGIN + a.a:= a.a+1; + a.b:= a.b || 'B'; + SELECT a.a, a.b; + END; + FUNCTION f1 RETURN INT AS BEGIN a.a:= a.a+1; RETURN a.a; END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; + + +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a t1.a%TYPE:=10; + PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; + FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; +DROP TABLE t1; + + +CREATE TABLE t1 (a INT, b TEXT); +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a t1%ROWTYPE:=ROW(10,'bbb'); + PROCEDURE p1 AS + BEGIN + a.a:= a.a+1; + a.b:= a.b || 'B'; + SELECT a.a, a.b; + END; + FUNCTION f1 RETURN INT AS BEGIN a.a:= a.a+1; RETURN a.a; END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; +DROP TABLE t1; + + +--echo # +--echo # One package variable, set in the package initialization section +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT; + PROCEDURE p1 AS BEGIN a:=a+1; SELECT a; END; + FUNCTION f1 RETURN INT AS BEGIN a:=a+1; RETURN a; END; +BEGIN + a:=10; +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +CALL p1.p1(); +SELECT p1.f1(); +CALL p1.p1(); +DROP PACKAGE p1; + + +--echo # +--echo # A package with an initialization section, +--echo # loading table data into a package variable +--echo # + +CREATE TABLE t1 AS SELECT 10 AS a; +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN INT; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT; + PROCEDURE p1 AS BEGIN SET a=a+1; SELECT a; END; + FUNCTION f1 RETURN INT AS BEGIN SET a=a+1; RETURN a; END; +BEGIN + a:=(SELECT MAX(t1.a) FROM t1); +END; +$$ +DELIMITER ;$$ +CALL p1.p1(); +CALL p1.p1(); +SELECT p1.f1(); +SELECT p1.f1(); +--source sp-cache-invalidate.inc +SELECT p1.f1(); +DROP PACKAGE p1; +DROP TABLE t1; + +--echo # +--echo # Package variables and XPath +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS + i INT:=0; + xml TEXT:= 'b1b2b3'; + FUNCTION f1 RETURN TEXT AS + BEGIN + SET i=i+1; + RETURN ExtractValue(xml, '/a/b[$i]'); + END; +END; +$$ +DELIMITER ;$$ +SELECT p1.f1(); +SELECT p1.f1(); +SELECT p1.f1(); +DROP PACKAGE p1; + +--echo # +--echo # Package variables as OUT routine parameter +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT; + b INT; + c INT:=10; + PROCEDURE p2(a OUT INT) AS + BEGIN + a:=c; + c:=c+1; + END; + PROCEDURE p1 AS + BEGIN + CALL p2(b); + SELECT a,b; + END; +BEGIN + CALL p2(a); +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; + + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a ROW(a INT, b TEXT); + b ROW(a INT, b TEXT); + c ROW(a INT, b TEXT):=ROW(1,'b'); + PROCEDURE p2(x OUT ROW(a INT,b TEXT)) AS + BEGIN + x:=c; + x.a:=c.a+100; + x.b:=c.b||'X'; + c.a:=c.a+1; + c.b:=c.b||'B'; + END; + PROCEDURE p1 AS + BEGIN + CALL p2(b); + SELECT a.a,a.b,b.a,b.b; + END; +BEGIN + CALL p2(a); +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; + + +CREATE TABLE t1 (a INT,b TEXT); +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a t1%ROWTYPE; + b t1%ROWTYPE; + c t1%ROWTYPE:=ROW(1,'b'); + PROCEDURE p2(x OUT t1%ROWTYPE) AS + BEGIN + x:=c; + x.a:=c.a+100; + x.b:=c.b||'X'; + c.a:=c.a+1; + c.b:=c.b||'B'; + END; + PROCEDURE p1 AS + BEGIN + CALL p2(b); + SELECT a.a,a.b,b.a,b.b; + END; +BEGIN + CALL p2(a); +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; +DROP TABLE t1; + + +--echo # +--echo # Package variable fields as OUT routine parameters +--echo # + +CREATE TABLE t1 (a INT,b TEXT); +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a t1%ROWTYPE; + x t1%ROWTYPE:=ROW(10,'b'); + PROCEDURE p2(a OUT INT,b OUT TEXT) AS + BEGIN + a:=x.a; + b:=x.b; + x.a:=x.a+1; + x.b:=x.b||'B'; + END; + PROCEDURE p1 AS + BEGIN + CALL p2(a.a, a.b); + SELECT a.a,a.b; + END; +BEGIN + CALL p2(a.a, a.b); + SELECT a.a, a.b; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; +DROP TABLE t1; + + +--echo # +--echo # Package variables as SELECT INTO targets +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a INT; + b INT; + PROCEDURE p1 AS + BEGIN + SELECT 2 INTO b; + SELECT a,b; + END; +BEGIN + SELECT 1 INTO a; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; + + +CREATE TABLE t1 (a INT, b TEXT); +INSERT INTO t1 VALUES (10,'b'); +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a t1%ROWTYPE; + b t1%ROWTYPE; + PROCEDURE p1 AS + BEGIN + SELECT * FROM t1 INTO a; + SELECT a.a,a.b; + END; +BEGIN + SELECT * FROM t1 INTO b; + SELECT b.a, b.b; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; +DROP TABLE t1; + + +--echo # +--echo # Package variable fields as SELECT INTO targets +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END; +$$ +CREATE PACKAGE BODY p1 AS + a ROW(a INT, b TEXT); + b ROW(a INT, b TEXT); + PROCEDURE p1 AS + BEGIN + SELECT 20,'x2' INTO b.a,b.b; + SELECT a.a,a.b,b.a,b.b; + END; +BEGIN + SELECT 10,'x1' INTO a.a,a.b; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; + + +--echo # +--echo # Recursive package procedure calls +--echo # Makes sure that the non-top sp_head instances created by +--echo # sp_clone_and_link_routine() correctly reproduce the package context: +--echo # package variables, package routines. +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1(c INT); +END p1; +$$ +CREATE PACKAGE BODY p1 AS + pv1 INT:=10; + FUNCTION f1 RETURN INT AS BEGIN RETURN pv1+100; END; + PROCEDURE p1(c INT) AS + BEGIN + SELECT c, pv1, f1(); + IF c>0 THEN + pv1:=pv1+1; + CALL p1(c-1); + END IF; + END; +END; +$$ +DELIMITER ;$$ +SET max_sp_recursion_depth=5; +CALL p1.p1(5); +SET max_sp_recursion_depth=0; +CALL p1.p1(0); +--error ER_SP_RECURSION_LIMIT +CALL p1.p1(1); +DROP PACKAGE p1; + + +--echo # +--echo # Non-reserved keywords as package body variable names +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; +END p1; +$$ +CREATE PACKAGE BODY p1 AS + ascii INT:=10; + action INT:=20; + PROCEDURE p1 AS + BEGIN + SELECT ascii, action; + END; +BEGIN + ascii := ascii + 1; + action := action + 1; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +DROP PACKAGE p1; + + +--echo # +--echo # Package routines calling routines of another package +--echo # + +DELIMITER $$; +CREATE PACKAGE p1 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE p2 AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY p1 AS + PROCEDURE p1 AS + BEGIN + SELECT 'This is p1.p1' AS msg; + END; + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is p1.f1'; + END; +END; +$$ +CREATE PACKAGE BODY p2 AS + PROCEDURE p1 AS + BEGIN + CALL p1.p1; + END; + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN p1.f1(); + END; +END; +$$ +DELIMITER ;$$ +CALL p1.p1; +CALL p2.p1; +SELECT p1.f1(), p2.f1(); +DROP PACKAGE p2; +DROP PACKAGE p1; + +--echo # +--echo # Package names with dot characters +--echo # + +DELIMITER $$; +CREATE PACKAGE "p1.p1" AS + PROCEDURE p1; + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY "p1.p1" AS + PROCEDURE p1 AS + BEGIN + SELECT 'This is p1' AS msg; + END; + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is f1'; + END; +END; +$$ +DELIMITER ;$$ +CALL "p1.p1"."p1"; +SELECT "p1.p1"."f1"(); +DROP PACKAGE "p1.p1"; + + +--echo # +--echo # MDEV-15070 Crash when doing a CREATE VIEW inside a package routine +--echo # + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg1 AS + PROCEDURE p00(); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg1 AS + PROCEDURE p01() AS + BEGIN + SELECT 'This is p01' AS msg; + END; + PROCEDURE p00() AS + BEGIN + CREATE OR REPLACE VIEW v1 AS SELECT 1; + DROP VIEW v1; + CALL p01(); + END; +END; +$$ +DELIMITER ;$$ +CALL pkg1.p00; +DROP PACKAGE pkg1; + + +CREATE OR REPLACE TABLE t1 (a INT); +CREATE OR REPLACE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=1; +DELIMITER $$; +CREATE OR REPLACE PACKAGE pkg1 AS + PROCEDURE p00(); +END; +$$ +CREATE OR REPLACE PACKAGE BODY pkg1 AS + PROCEDURE p01() AS + BEGIN + SELECT 'This is p01' AS msg; + END; + PROCEDURE p00() AS + BEGIN + DROP TRIGGER tr1; + CALL p01(); + END; +END; +$$ +DELIMITER ;$$ +CALL pkg1.p00; +DROP PACKAGE pkg1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-17387 MariaDB Server giving wrong error while executing select query from procedure +--echo # + +CREATE TABLE t1 ( + CTR varchar(2) NOT NULL, + COR varchar(3) NOT NULL, + DATE datetime NOT NULL, + CHAN varchar(4) NOT NULL, + CNO varchar(20) NOT NULL, + JOBN varchar(18) NOT NULL, + C1 varchar(30) DEFAULT NULL, + C2 varchar(30) DEFAULT NULL, + TIME datetime DEFAULT NULL, + AMT decimal(12,2) DEFAULT NULL, + DT datetime NOT NULL, + pk int(11) NOT NULL, + PRIMARY KEY (pk), + KEY Indx1 (JOBN) +); + +DELIMITER $$; + +CREATE PACKAGE xyz IS + PROCEDURE xyz123(ctr IN VARCHAR2,Jn IN VARCHAR2,R OUT VARCHAR2); +END; +$$ + +CREATE OR REPLACE PACKAGE BODY xyz IS + PROCEDURE xyz123( + ctr IN VARCHAR2, + Jn IN VARCHAR2, + R OUT VARCHAR2) + AS + lS NUMBER(10) :=0; + CURSOR cBPD IS + SELECT CTR, COR, DATE, CHAN, CNO, C1, C2, TIME, AMT + FROM t1 WHERE JOBN=Jn; + BEGIN + FOR lbpd IN cBPD + LOOP + lS:=lS+1; + END LOOP; + EXCEPTION + WHEN OTHERS THEN + BEGIN + SELECT SQLERRM; + END; + END; +END $$ +DELIMITER ;$$ + +CALL xyz.xyz123(17,18,@R); +DROP PACKAGE xyz; +DROP TABLE t1; +--disable_prepare_warnings + + +--echo # +--echo # MDEV-28166 sql_mode=ORACLE: fully qualified package function calls do not work: db.pkg.func() +--echo # + +--error ER_WRONG_DB_NAME +SELECT `db `.pkg.func(); +--error ER_SP_WRONG_NAME +SELECT db.`pkg `.func(); +--error ER_SP_WRONG_NAME +SELECT db.pkg.`func `(); + + +CREATE DATABASE db1; +USE db1; + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + FUNCTION f1 RETURN TEXT; + FUNCTION f2_db1_pkg1_f1 RETURN TEXT; + FUNCTION f2_pkg1_f1 RETURN TEXT; + FUNCTION f2_f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 +AS + FUNCTION f1 RETURN TEXT IS + BEGIN + RETURN 'This is db1.pkg1.f1'; + END; + FUNCTION f2_db1_pkg1_f1 RETURN TEXT IS + BEGIN + RETURN db1.pkg1.f1(); + END; + FUNCTION f2_pkg1_f1 RETURN TEXT IS + BEGIN + RETURN pkg1.f1(); + END; + FUNCTION f2_f1 RETURN TEXT IS + BEGIN + RETURN f1(); + END; +END; +$$ +DELIMITER ;$$ + +USE db1; +SELECT pkg1.f2_db1_pkg1_f1(); +SELECT pkg1.f2_pkg1_f1(); +SELECT pkg1.f2_f1(); + +SELECT db1.pkg1.f2_db1_pkg1_f1(); +SELECT db1.pkg1.f2_pkg1_f1(); +SELECT db1.pkg1.f2_f1(); + +USE test; +SELECT db1.pkg1.f2_db1_pkg1_f1(); +SELECT db1.pkg1.f2_pkg1_f1(); +SELECT db1.pkg1.f2_f1(); + +DROP DATABASE db1; + + +# +# Testing db.pkg.func() in the package initialization section +# + +CREATE DATABASE db1; +CREATE DATABASE db2; + +DELIMITER $$; +CREATE PACKAGE db1.pkg1 AS + FUNCTION f1 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY db1.pkg1 AS + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is db1.pkg1.f1'; + END; +END; +$$ +DELIMITER ;$$ + + +DELIMITER $$; +CREATE PACKAGE db2.pkg1 AS + FUNCTION f1 RETURN TEXT; + FUNCTION var1 RETURN TEXT; + FUNCTION var2 RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY db2.pkg1 AS + m_var1 TEXT; + m_var2 TEXT; + FUNCTION f1 RETURN TEXT AS + BEGIN + RETURN 'This is db2.pkg1.f1'; + END; + FUNCTION var1 RETURN TEXT AS + BEGIN + RETURN m_var1; + END; + FUNCTION var2 RETURN TEXT AS + BEGIN + RETURN m_var2; + END; +BEGIN + m_var1:= db1.pkg1.f1(); + m_var2:= db2.pkg1.f1(); +END; +$$ +DELIMITER ;$$ + +SELECT db2.pkg1.var1(), db2.pkg1.var2(); + +DROP DATABASE db1; +DROP DATABASE db2; + +# +# Make sure fully qualified package function call does not support AS syntax: +# SELECT db.pkg.func(10 AS a); +# + +DELIMITER $$; +CREATE PACKAGE pkg1 AS + FUNCTION f1(a TEXT) RETURN TEXT; +END; +$$ +CREATE PACKAGE BODY pkg1 AS + FUNCTION f1(a TEXT) RETURN TEXT AS + BEGIN + RETURN a; + END; +END; +$$ +DELIMITER ;$$ +SELECT test.pkg1.f1('xxx'); +--error ER_PARSE_ERROR +SELECT test.pkg1.f1('xxx' AS a); +DROP PACKAGE pkg1; + + +--echo # +--echo # MDEV-19328 sql_mode=ORACLE: Package function in VIEW +--echo # + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE PACKAGE test1 AS + FUNCTION f_test RETURN number; +END test1; +$$ +CREATE PACKAGE BODY test1 +AS + FUNCTION f_test RETURN NUMBER IS + BEGIN + RETURN 1; + END; +END test1; +$$ +DELIMITER ;$$ + + +SET sql_mode=ORACLE; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test1.f_test(); +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +SET sql_mode=DEFAULT; +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +DROP VIEW v_test; + + +SET sql_mode=DEFAULT; +--error ER_SP_DOES_NOT_EXIST +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test1.f_test(); + + +SET sql_mode=ORACLE; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test.test1.f_test(); +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +SET sql_mode=DEFAULT; +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +DROP VIEW v_test; + + +SET sql_mode=DEFAULT; +CREATE VIEW v_test AS SELECT 1 AS c1 FROM DUAL WHERE 1=test.test1.f_test(); +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +SET sql_mode=ORACLE; +SELECT * FROM v_test; +--vertical_results +SHOW CREATE VIEW v_test; +--horizontal_results +DROP VIEW v_test; + +SET sql_mode=ORACLE; +DROP PACKAGE test1; + + +--echo # +--echo # MDEV-19804 sql_mode=ORACLE: call procedure in packages +--echo # + +--error ER_WRONG_DB_NAME +CALL `db1 `.pkg.p; +--error ER_SP_WRONG_NAME +CALL db1.`pkg `.p; +--error ER_SP_WRONG_NAME +CALL db1.pkg.`p `; + + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE PACKAGE pkg1 as + PROCEDURE p1(); +END; +$$ +CREATE PACKAGE BODY pkg1 as + PROCEDURE p1() as + BEGIN + SELECT 'test-function' AS c1; + END; +END; +$$ +DELIMITER ;$$ + +CALL pkg1.p1; +CALL test.pkg1.p1; + +# In sql_mode=DEFAULT we support fully qualified package function names +# (this is needed for VIEWs). Let's make sure we also support fully +# qualified package procedure names, for symmetry + +SET sql_mode=DEFAULT; +CALL test.pkg1.p1; +SET sql_mode=ORACLE; + +DELIMITER $$; +BEGIN + CALL pkg1.p1; + CALL test.pkg1.p1; +END +$$ +DELIMITER ;$$ + +DELIMITER $$; +BEGIN + pkg1.p1; + test.pkg1.p1; +END +$$ +DELIMITER ;$$ + +DROP PACKAGE pkg1; + + +# +# Testing packages in different databases calling each other +# in routines and in the initialization section. +# + +CREATE DATABASE db1; +DELIMITER $$; +CREATE PACKAGE db1.pkg1 AS + PROCEDURE p1(a OUT TEXT); +END; +$$ +CREATE PACKAGE BODY db1.pkg1 AS + PROCEDURE p1(a OUT TEXT) AS + BEGIN + a:= 'This is db1.pkg1.p1'; + END; +END; +$$ +DELIMITER ;$$ + +CREATE DATABASE db2; +DELIMITER $$; +CREATE PACKAGE db2.pkg1 AS + FUNCTION var1 RETURN TEXT; + PROCEDURE p1(a OUT TEXT); + PROCEDURE p2_db1_pkg1_p1; +END; +$$ +CREATE PACKAGE BODY db2.pkg1 AS + m_var1 TEXT; + FUNCTION var1 RETURN TEXT AS + BEGIN + RETURN m_var1; + END; + PROCEDURE p1(a OUT TEXT) AS + BEGIN + a:= 'This is db2.pkg1.p1'; + END; + PROCEDURE p2_db1_pkg1_p1 AS + a TEXT; + BEGIN + db1.pkg1.p1(a); + SELECT a; + END; +BEGIN + db1.pkg1.p1(m_var1); +END; +$$ +DELIMITER ;$$ + +SELECT db2.pkg1.var1(); +CALL db2.pkg1.p2_db1_pkg1_p1; +--enable_ps2_protocol + +DROP DATABASE db1; +DROP DATABASE db2; + + +--echo # +--echo # MDEV-29370 Functions in packages are slow and seems to ignore deterministic +--echo # + +SET SQL_MODE=ORACLE; + +CREATE TABLE t1 (c1 CHAR(1)); + +DELIMITER //; +CREATE FUNCTION f1_deterministic() +RETURN CHAR(1) +DETERMINISTIC +IS +BEGIN + RETURN 'X'; +END; +// + +CREATE FUNCTION f2_not_deterministic() +RETURN CHAR(1) +IS +BEGIN + RETURN 'X'; +END; +// + +CREATE PACKAGE pkg1 +IS + PROCEDURE t1_populate(numrows INTEGER); + FUNCTION f3_deterministic() RETURN CHAR(1) DETERMINISTIC; + FUNCTION f4_not_deterministic() RETURN CHAR(1); +END; +// + +CREATE PACKAGE BODY pkg1 +IS + PROCEDURE t1_populate(numrounds INTEGER) + IS + i INTEGER; + BEGIN + INSERT INTO t1 VALUES('Y'); + FOR i IN 1..numrounds LOOP + INSERT INTO t1 SELECT * FROM t1; + END LOOP; + END; + FUNCTION f3_deterministic() RETURN CHAR(1) DETERMINISTIC COMMENT 'xxx' + IS + BEGIN + RETURN 'X'; + END; + FUNCTION f4_not_deterministic() RETURN CHAR(1) + IS + BEGIN + RETURN 'X'; + END; +END; +// +DELIMITER ;// + +CALL pkg1.t1_populate(3); + +EXPLAIN EXTENDED SELECT 'Deterministic function', COUNT(*) FROM t1 WHERE c1 = f1_deterministic(); +EXPLAIN EXTENDED SELECT 'Non-deterministic function', COUNT(*) FROM t1 WHERE c1 = f2_not_deterministic(); +EXPLAIN EXTENDED SELECT 'Deterministic package function', COUNT(*) FROM t1 WHERE c1 = pkg1.f3_deterministic(); +EXPLAIN EXTENDED SELECT 'Non-deterministic package function', COUNT(*) FROM t1 WHERE c1 = pkg1.f4_not_deterministic(); + +DROP TABLE t1; +DROP FUNCTION f1_deterministic; +DROP FUNCTION f2_not_deterministic; +DROP PACKAGE pkg1; diff --git a/mysql-test/suite/compat/oracle/t/sp-param.inc b/mysql-test/suite/compat/oracle/t/sp-param.inc new file mode 100644 index 00000000..35bce8ac --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-param.inc @@ -0,0 +1,9 @@ +--eval CREATE FUNCTION f1(param $type) RETURN $type AS BEGIN RETURN param; END; +SHOW CREATE FUNCTION f1; + +--eval SELECT LENGTH(f1(REPEAT('a',$length))); +--eval CREATE TABLE t1 AS SELECT f1(REPEAT('a',$length)) AS a; + +SHOW CREATE TABLE t1; +DROP TABLE t1; +DROP FUNCTION f1; diff --git a/mysql-test/suite/compat/oracle/t/sp-param.test b/mysql-test/suite/compat/oracle/t/sp-param.test new file mode 100644 index 00000000..b887858d --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-param.test @@ -0,0 +1,363 @@ +SET sql_mode=ORACLE; + +--echo # +--echo # MDEV-10596 Allow VARCHAR and VARCHAR2 without length as a data type of routine parameters and in RETURN clause +--echo # + +--let type = CHAR +--let length = 2000 +--source sp-param.inc + +--let type = NCHAR +--let length = 2000 +--source sp-param.inc + +--let type = BINARY +--let length = 2000 +--source sp-param.inc + +--let type = VARCHAR +--let length = 4000 +--source sp-param.inc + +--let type = VARCHAR2 +--let length = 4000 +--source sp-param.inc + +--let type = NVARCHAR +--let length = 4000 +--source sp-param.inc + +--let type = VARBINARY +--let length = 4000 +--source sp-param.inc + +--let type = RAW +--let length = 4000 +--source sp-param.inc + +--echo +--echo MDEV-13919 sql_mode=ORACLE: Derive length of VARCHAR SP parameters with no length from actual parameters +--echo +set sql_mode= 'oracle,strict_trans_tables'; +delimiter /; +CREATE OR REPLACE PROCEDURE p1(pinout INOUT varchar, pin IN varchar) +AS +BEGIN + pinout:=pin; +END; +/ +call p1(@w,'0123456789') +/ +declare w varchar(10); +begin + call p1(w,'0123456789'); +end; +/ +--error ER_DATA_TOO_LONG +declare w varchar(5); +begin + call p1(w,'0123456789'); +end; +/ +declare w varchar(20); +begin + w:='aaa'; + call p1(w,'0123456789'); +end; +/ +--error ER_DATA_TOO_LONG +declare w varchar(8); +begin + w:='aaa'; + call p1(w,'0123456789'); +end; +/ +declare str varchar(6000); + pout varchar(6000); +begin + str:=lpad('x',6000,'y'); + call p1(pout,str); + select length(pout); +end; +/ +--error ER_DATA_TOO_LONG +declare str varchar(6000); + pout varchar(4000); +begin + str:=lpad('x',6000,'y'); + call p1(pout,str); + select length(pout); +end; +/ +declare str varchar(40000); + pout varchar(60000); +begin + str:=lpad('x',40000,'y'); + call p1(pout,str); + select length(pout); +end; +/ +--error ER_DATA_TOO_LONG +declare str text(80000); + pout text(80000); +begin + str:=lpad('x',80000,'y'); + call p1(pout,str); + select length(pout); +end; +/ +declare str text(80000); + pout text(80000); +begin + str:=lpad('x',60000,'y'); + call p1(pout,str); + select length(pout); +end; +/ +drop procedure p1 +/ +DELIMITER ;/ + + +# +# Procedure, non-strict mode +# + +SET sql_mode=ORACLE; +DELIMITER /; +CREATE PROCEDURE p1(pinout INOUT varchar, pin IN varchar) +AS +BEGIN + pinout:=pin; +END; +/ +CREATE PROCEDURE p2(len INT) +AS + pinout VARCHAR(10); + pin VARCHAR(30); +BEGIN + pin:= REPEAT('x', len); + p1(pinout, pin); + SELECT LENGTH(pinout); +END; +/ +DELIMITER ;/ +CALL p2(10); +CALL p2(11); +DROP PROCEDURE p1; +DROP PROCEDURE p2; + + +# +# Function, not-strict mode +# + +SET sql_mode=ORACLE; +DELIMITER /; +CREATE FUNCTION f1(pin VARCHAR, padlen INT) RETURN TEXT +AS +BEGIN + pin:=LPAD(pin, padlen); + RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT :='x'; +BEGIN + SELECT LENGTH(f1(str,padlen)); +END; +/ +DELIMITER ;/ +CALL p2(65535); +CALL p2(65536); +DROP PROCEDURE p2; +DROP FUNCTION f1; + + +# +# Procedure, utf8 formal parameter, latin actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE PROCEDURE p1(pinout INOUT VARCHAR CHARACTER SET utf8, + pin IN VARCHAR CHARACTER SET utf8) +AS +BEGIN + pinout:=pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str VARCHAR(40000) CHARACTER SET latin1; + pout VARCHAR(60000) CHARACTER SET latin1; +BEGIN + str:=lpad('x',padlen,'y'); + p1(pout,str); + SELECT length(pout); +END; +/ +DELIMITER ;/ +CALL p2(21844); +--error ER_DATA_TOO_LONG +CALL p2(21845); +--error ER_DATA_TOO_LONG +CALL p2(21846); +DROP PROCEDURE p2; +DROP PROCEDURE p1; + + +# +# Procedure, utf8 formal parameter, utf8 actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE PROCEDURE p1(pinout INOUT VARCHAR CHARACTER SET utf8, + pin IN VARCHAR CHARACTER SET utf8) +AS +BEGIN + pinout:=pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT CHARACTER SET utf8; + pout TEXT CHARACTER SET utf8; +BEGIN + str:=lpad('x',padlen,'y'); + p1(pout,str); + SELECT length(pout); +END; +/ +DELIMITER ;/ +CALL p2(21844); +--error ER_DATA_TOO_LONG +CALL p2(21845); +--error ER_DATA_TOO_LONG +CALL p2(21846); +DROP PROCEDURE p2; +DROP PROCEDURE p1; + + +# +# Function, latin1 formal parameter, latin1 actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET latin1, padlen INT) RETURN TEXT +AS +BEGIN + pin:=LPAD(pin, padlen); + RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT CHARACTER SET latin1 :='x'; +BEGIN + SELECT LENGTH(f1(str,padlen)); +END; +/ +DELIMITER ;/ +CALL p2(65532); +--error ER_DATA_TOO_LONG +CALL p2(65533); +--error ER_DATA_TOO_LONG +CALL p2(65534); +--error ER_DATA_TOO_LONG +CALL p2(65535); +--error ER_DATA_TOO_LONG +CALL p2(65536); +DROP PROCEDURE p2; +DROP FUNCTION f1; + + +# +# Function, utf8 formal parameter, utf8 actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET utf8, padlen INT) RETURN TEXT +AS +BEGIN + pin:=LPAD(pin, padlen); + RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT CHARACTER SET utf8 := 'x'; +BEGIN + SELECT LENGTH(f1(str,padlen)); +END; +/ +DELIMITER ;/ +CALL p2(21844); +--error ER_DATA_TOO_LONG +CALL p2(21845); +--error ER_DATA_TOO_LONG +CALL p2(21846); +DROP PROCEDURE p2; +DROP FUNCTION f1; + + +# +# Function, utf8 formal parameter, latin1 actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET utf8, padlen INT) RETURN TEXT +AS +BEGIN + pin:=LPAD(pin, padlen); + RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT CHARACTER SET latin1 := 'x'; +BEGIN + SELECT LENGTH(f1(str,padlen)); +END; +/ +DELIMITER ;/ +CALL p2(21844); +--error ER_DATA_TOO_LONG +CALL p2(21845); +--error ER_DATA_TOO_LONG +CALL p2(21846); +DROP PROCEDURE p2; +DROP FUNCTION f1; + + +# +# Function, latin1 formal parameter, utf8 actual parameter +# + +SET sql_mode='ORACLE,STRICT_TRANS_TABLES'; +DELIMITER /; +CREATE FUNCTION f1(pin VARCHAR CHARACTER SET latin1, padlen INT) RETURN TEXT +AS +BEGIN + pin:=LPAD(pin, padlen); + RETURN pin; +END; +/ +CREATE PROCEDURE p2(padlen INT) AS + str TEXT CHARACTER SET utf8 := 'x'; +BEGIN + SELECT LENGTH(f1(str,padlen)); +END; +/ +DELIMITER ;/ +CALL p2(65532); +--error ER_DATA_TOO_LONG +CALL p2(65533); +--error ER_DATA_TOO_LONG +CALL p2(65534); +--error ER_DATA_TOO_LONG +CALL p2(65535); +--error ER_DATA_TOO_LONG +CALL p2(65536); +DROP PROCEDURE p2; +DROP FUNCTION f1; diff --git a/mysql-test/suite/compat/oracle/t/sp-row-vs-var.inc b/mysql-test/suite/compat/oracle/t/sp-row-vs-var.inc new file mode 100644 index 00000000..14f6f7df --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-row-vs-var.inc @@ -0,0 +1,6 @@ +--let $query= CREATE PROCEDURE p1() AS var $type; rec ROW(var $type); BEGIN CREATE TABLE t1 AS SELECT var,rec.var FROM DUAL;END +--eval $query +CALL p1(); +SHOW CREATE TABLE t1; +DROP TABLE t1; +DROP PROCEDURE p1; diff --git a/mysql-test/suite/compat/oracle/t/sp-row.test b/mysql-test/suite/compat/oracle/t/sp-row.test new file mode 100644 index 00000000..c7658c76 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-row.test @@ -0,0 +1,2418 @@ + +SET sql_mode=ORACLE; + + +--echo # +--echo # MDEV-10914 ROW data type for stored routine variables +--echo # + + + +--echo # +--echo # ROW of ROWs is not supported yet +--echo # + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE PROCEDURE p1() +AS + a ROW(a ROW(a INT)); +BEGIN +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Returning the entire ROW parameter from a function +--echo # +# TODO: this should probably return an error at compile time +DELIMITER $$; +CREATE FUNCTION f1(a ROW(a INT, b INT)) RETURN INT +AS +BEGIN + RETURN a; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT f1(ROW(10,20)); +DROP FUNCTION f1; + + + +--echo # +--echo # ROW as an SP parameter +--echo # + +DELIMITER $$; +CREATE FUNCTION f1(a ROW(a INT,b INT)) RETURN INT +AS +BEGIN + RETURN a.b; +END; +$$ +CREATE PROCEDURE p1() +AS + a ROW(a INT,b INT):=(11,21); +BEGIN + SELECT f1(a); +END; +$$ +DELIMITER ;$$ +SELECT f1(ROW(10,20)); +--error ER_OPERAND_COLUMNS +SELECT f1(10); +--error ER_OPERAND_COLUMNS +SELECT f1(ROW(10,20,30)); +CALL p1(); +DROP PROCEDURE p1; +DROP FUNCTION f1; + +DELIMITER $$; +CREATE PROCEDURE p1(a ROW(a INT,b INT)) +AS +BEGIN + SELECT a.a, a.b; +END; +$$ +DELIMITER ;$$ +CALL p1(ROW(10,20)); +--error ER_OPERAND_COLUMNS +CALL p1(10); +--error ER_OPERAND_COLUMNS +CALL p1(ROW(10,20,30)); +DROP PROCEDURE p1; + + +--echo # +--echo # ROW as an SP OUT parameter +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1(a OUT ROW(a INT,b INT)) +AS +BEGIN + a.a:=10; + a.b:=20; +END; +$$ +CREATE PROCEDURE p2 +AS + a ROW(a INT,b INT):=(11,21); +BEGIN + CALL p1(a); + SELECT a.a,a.b; +END; +$$ +DELIMITER ;$$ +CALL p2(); +DROP PROCEDURE p2; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW as an SP return value is not supported yet +--echo # + +DELIMITER $$; +--error ER_PARSE_ERROR +CREATE FUNCTION p1() RETURN ROW(a INT) +AS +BEGIN + RETURN NULL; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Diplicate row field +--echo # +DELIMITER $$; +--error ER_DUP_FIELDNAME +CREATE PROCEDURE p1() +AS + a ROW (a INT, a DOUBLE); +BEGIN + SELECT a.a; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Bad scalar default value +--echo # +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT, b DOUBLE):= 1; +BEGIN + SELECT a.a; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + +--echo # +--echo # Bad ROW default value with a wrong number of fields +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT, b DOUBLE):= ROW(1,2,3); +BEGIN + SELECT a.a; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Scalar variable vs table alias cause no ambiguity +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a INT; +BEGIN + -- a.x is a table column here (not a row variable field) + SELECT a.x FROM a; + SELECT a.x FROM t1 a; +END; +$$ +DELIMITER ;$$ +DROP PROCEDURE p1; + +--echo # +--echo # Using the entire ROW variable in select list +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT); +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Using the entire ROW variable in functions +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT); +BEGIN + SELECT COALESCE(a); +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT COALESCE(a); +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT); +BEGIN + SELECT a+1; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; + + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT a+1; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Comparing the entire ROW to a scalar value +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT a=1; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; + + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT 1=a; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Passing the entire ROW to a stored function +--echo # + +DELIMITER $$; +CREATE FUNCTION f1(a INT) RETURN INT +AS +BEGIN + RETURN a; +END; +$$ +CREATE PROCEDURE p1() +AS + a ROW (a INT,b INT); +BEGIN + SELECT f1(a); +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; +DROP FUNCTION f1; + + +DELIMITER $$; +CREATE FUNCTION f1(a INT) RETURN INT +AS +BEGIN + RETURN a; +END; +$$ +CREATE PROCEDURE p1() +AS + a ROW (a INT); +BEGIN + SELECT f1(a); +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CALL p1(); +DROP PROCEDURE p1; +DROP FUNCTION f1; + + +--echo # +--echo # Assigning a scalar value to a ROW variable with 1 column +--echo # + +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec ROW(a INT); +BEGIN + rec:=1; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning a scalar value to a ROW variable with 2 columns +--echo # + +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec ROW(a INT,b INT); +BEGIN + rec:=1; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning a ROW value to a ROW variable with different number of columns +--echo # + +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec ROW(a INT,b INT); +BEGIN + rec:=ROW(1,2,3); +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + +--echo # +--echo # Returning the entire ROW from a function is not supported yet +--echo # This syntax would be needed: SELECT f1().x FROM DUAL; +--echo # +DELIMITER $$; +CREATE FUNCTION f1(a INT) RETURN INT +AS + rec ROW(a INT); +BEGIN + RETURN rec; +END; +$$ +DELIMITER ;$$ +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT f1(10); +DROP FUNCTION f1; + + +--echo # +--echo # Using the entire ROW in SELECT..CREATE +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec ROW(a INT,b INT); +BEGIN + CREATE TABLE t1 AS SELECT rec; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Using the entire ROW in LIMIT +--echo # +DELIMITER $$; +--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +CREATE PROCEDURE p1() +AS + rec ROW(a INT); +BEGIN + rec.a:= '10'; + SELECT * FROM t1 LIMIT rec; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Setting ROW fields using a SET command +--echo # +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec ROW(a INT,b DOUBLE,c VARCHAR(10)); + a INT; +BEGIN + SET @a= 10, rec.a=10, rec.b=20, rec.c= 'test', a= 5; + SELECT rec.a, rec.b, rec.c, a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning a ROW variable from a ROW value +--echo # +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec ROW(a INT,b INT); +BEGIN + rec:=ROW(1,2); + SELECT rec.a, rec.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning a ROW variable from another ROW value +--echo # +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec1 ROW(a INT,b INT); + rec2 ROW(a INT,b INT); +BEGIN + rec1:=ROW(1,2); + rec2:=rec1; + SELECT rec2.a, rec2.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Comparing a ROW variable to a ROW() function +--echo # + +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec ROW(a INT,b INT); +BEGIN + rec.a:= 1; + rec.b:= 2; + SELECT rec=(0,0), rec=ROW(0,0), (0,0)=rec, ROW(0,0)=rec; + SELECT rec=(1,2), rec=ROW(1,2), (1,2)=rec, ROW(1,2)=rec; + SELECT rec=(NULL,0), rec=ROW(NULL,0); + SELECT rec=(NULL,2), rec=ROW(NULL,2); + SELECT rec<>(0,0), rec<>ROW(0,0); + SELECT rec<>(1,2), rec<>ROW(1,2); + SELECT rec<>(NULL,0), rec<>ROW(NULL,0); + SELECT rec<>(NULL,2), rec<>ROW(NULL,2); + SELECT rec IN ((0,0)), rec IN (ROW(0,0)); + SELECT rec IN ((1,2)), rec IN (ROW(1,2)); + SELECT rec IN ((0,NULL),(1,2)); + SELECT rec NOT IN ((0,NULL),(1,1)); + SELECT rec NOT IN ((1,NULL),(1,1)); +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Comparing a ROW variable to another ROW variable +--echo # + +DELIMITER $$; +CREATE OR REPLACE PROCEDURE p1 +AS + rec1,rec2,rec3 ROW(a INT,b INT); +BEGIN + rec1.a:= 1; + rec1.b:= 2; + rec2.a:= 11; + rec2.b:= 12; + rec3.a:= 11; + rec3.b:= 12; + SELECT rec1=rec2, rec2=rec1, rec2=rec3, rec3=rec2; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Referencing a non-existing row variable +--echo # +DELIMITER $$; +--error ER_UNKNOWN_STRUCTURED_VARIABLE +CREATE PROCEDURE p1() +AS +BEGIN + SET a.b=1; +END; +$$ +DELIMITER ;$$ + +DELIMITER $$; +--error ER_UNKNOWN_STRUCTURED_VARIABLE +CREATE PROCEDURE p1() +AS +BEGIN + a.b:=1; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Referencing a non-existing row field +--echo # +DELIMITER $$; +--error ER_ROW_VARIABLE_DOES_NOT_HAVE_FIELD +CREATE PROCEDURE p1() +AS + a ROW(a INT,b INT); +BEGIN + SELECT a.c FROM t1; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # ROW and scalar variables with the same name shadowing each other +--echo # +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW(a INT); +BEGIN + a.a:=100; + DECLARE + a INT:= 200; + BEGIN + SELECT a; + DECLARE + a ROW(a INT); + BEGIN + a.a:=300; + SELECT a.a; + END; + SELECT a; + END; + SELECT a.a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # ROW with good default values +--echo # +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a ROW(a INT,b INT):= (10,20); + b ROW(a INT,b INT):= (11,21); + c ROW(a INT,b INT):= a; +BEGIN + SELECT a.a, a.b, b.a, b.b, c.a, c.b FROM DUAL; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW in WHERE clause +--echo # + +CREATE TABLE t1 (a INT,b INT); +INSERT INTO t1 VALUES (10,20); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec ROW(a INT,b INT):=ROW(10,20); +BEGIN + SELECT * FROM t1 WHERE rec=ROW(a,b); + SELECT * FROM t1 WHERE ROW(a,b)=rec; + SELECT * FROM t1 WHERE rec=ROW(10,20); + SELECT * FROM t1 WHERE ROW(10,20)=rec; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW fields in WHERE clause +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec ROW(a INT); +BEGIN + rec.a:= 10; + SELECT * FROM t1 WHERE a=rec.a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW fields in HAVING clause +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec ROW(a INT); +BEGIN + rec.a:= 10; + SELECT * FROM t1 HAVING a=rec.a; + SELECT * FROM t1 HAVING MIN(a)=rec.a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW fields in LIMIT clause +--echo # + +CREATE TABLE t1 (a INT); +--error ER_SP_UNDECLARED_VAR +SELECT 1 FROM t1 LIMIT t1.a; +DROP TABLE t1; + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec ROW(a INT); +BEGIN + rec.a:= 10; + SELECT * FROM t1 LIMIT rec.a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +DELIMITER $$; +--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +CREATE PROCEDURE p1() +AS + rec ROW(a VARCHAR(10)); +BEGIN + rec.a:= '10'; + SELECT * FROM t1 LIMIT rec.a; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # ROW fields in select list +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + t1 ROW(a INT); +BEGIN + t1.a:= 10; + SELECT t1.a, 'This is the variable t1.a value, rather than the column t1.a' AS comm FROM t1; + SELECT t1.a, t2.a, t1.a+t2.a FROM t1 t2; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW fields as insert values +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec ROW(a INT, b VARCHAR(10)); +BEGIN + rec.a:= 10; + rec.b:= 'test'; + INSERT INTO t1 VALUES (rec.a, rec.b); +END; +$$ +DELIMITER ;$$ +CALL p1(); +SELECT * FROM t1; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # ROW fields as SP out parameters +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1(a OUT INT, b OUT VARCHAR) +AS +BEGIN + a:= 10; + b:= 'test'; +END; +$$ +CREATE PROCEDURE p2 +AS + rec ROW(a INT, b VARCHAR(10)); +BEGIN + CALL p1(rec.a, rec.b); + SELECT rec.a, rec.b; +END; +$$ +DELIMITER ;$$ +CALL p2; +DROP PROCEDURE p1; +DROP PROCEDURE p2; + + +--echo # +--echo # ROW fields as dynamic SQL out parameters +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1(a OUT INT, b OUT VARCHAR) +AS +BEGIN + a:= 20; + b:= 'test-dynamic-sql'; +END; +$$ +CREATE PROCEDURE p2 +AS + rec ROW(a INT, b VARCHAR(30)); +BEGIN + EXECUTE IMMEDIATE 'CALL p1(?,?)' USING rec.a, rec.b; + SELECT rec.a, rec.b; +END; +$$ +DELIMITER ;$$ +CALL p2; +DROP PROCEDURE p1; +DROP PROCEDURE p2; + + +--echo # +--echo # ROW fields as SELECT..INTO targets +--echo # + +--enable_prepare_warnings + +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec ROW(a INT, b VARCHAR(10)); +BEGIN + SELECT 10,'test' INTO rec.a,rec.b; + SELECT rec.a, rec.b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; + +--disable_prepare_warnings + +--echo # +--echo # Implicit default NULL handling +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec ROW(a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,0), e TIME, f DATETIME); +BEGIN + SELECT rec.a, rec.b, rec.c, rec.d, rec.e, rec.f FROM DUAL; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # NULL handling +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec1 ROW(a INT, b VARCHAR(10)):=(NULL,NULL); + rec2 ROW(a INT, b VARCHAR(10)):=rec1; +BEGIN + SELECT rec1.a, rec1.b, rec2.a, rec2.b; + + rec1:= (10,20); + rec2:= rec1; + SELECT rec1.a, rec1.b, rec2.a, rec2.b; + + rec1:= (NULL,20); + rec2:= rec1; + SELECT rec1.a, rec1.b, rec2.a, rec2.b; + + rec1:= (10,NULL); + rec2:= rec1; + SELECT rec1.a, rec1.b, rec2.a, rec2.b; + + rec1:= (NULL,NULL); + rec2:= rec1; + SELECT rec1.a, rec1.b, rec2.a, rec2.b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # Testing multiple ROW variable declarations +--echo # This makes sure that fill_field_definitions() is called only once +--echo # per a ROW field, so create length is not converted to internal length +--echo # multiple times. +--echo # +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec1, rec2, rec3 ROW(a VARCHAR(10) CHARACTER SET utf8); +BEGIN + CREATE TABLE t1 AS SELECT rec1.a, rec2.a, rec3.a; +END; +$$ +DELIMITER ;$$ +CALL p1(); +SHOW CREATE TABLE t1; +DROP TABLE t1; +DROP PROCEDURE p1; + +--echo # +--echo # INT +--echo # + +--let type=INT +--source sp-row-vs-var.inc + +--let type=INT(1) +--source sp-row-vs-var.inc + +--let type=INT(2) +--source sp-row-vs-var.inc + +--let type=INT(3) +--source sp-row-vs-var.inc + +--let type=INT(4) +--source sp-row-vs-var.inc + +--let type=INT(5) +--source sp-row-vs-var.inc + +--let type=INT(6) +--source sp-row-vs-var.inc + +--let type=INT(7) +--source sp-row-vs-var.inc + +--let type=INT(8) +--source sp-row-vs-var.inc + +--let type=INT(9) +--source sp-row-vs-var.inc + +--let type=INT(10) +--source sp-row-vs-var.inc + +--let type=INT(11) +--source sp-row-vs-var.inc + +--let type=INT(12) +--source sp-row-vs-var.inc + +--let type=INT(13) +--source sp-row-vs-var.inc + +--let type=INT(14) +--source sp-row-vs-var.inc + +--let type=INT(20) +--source sp-row-vs-var.inc + +--let type=INT(21) +--source sp-row-vs-var.inc + + +--echo # +--echo # TINYINT +--echo # + +--let type=TINYINT +--source sp-row-vs-var.inc + +--let type=TINYINT(1) +--source sp-row-vs-var.inc + +--let type=TINYINT(2) +--source sp-row-vs-var.inc + +--let type=TINYINT(3) +--source sp-row-vs-var.inc + +--let type=TINYINT(4) +--source sp-row-vs-var.inc + +--let type=TINYINT(5) +--source sp-row-vs-var.inc + +--let type=TINYINT(6) +--source sp-row-vs-var.inc + +--let type=TINYINT(7) +--source sp-row-vs-var.inc + +--let type=TINYINT(8) +--source sp-row-vs-var.inc + +--let type=TINYINT(9) +--source sp-row-vs-var.inc + +--let type=TINYINT(10) +--source sp-row-vs-var.inc + +--let type=TINYINT(11) +--source sp-row-vs-var.inc + +--let type=TINYINT(12) +--source sp-row-vs-var.inc + +--let type=TINYINT(13) +--source sp-row-vs-var.inc + +--let type=TINYINT(14) +--source sp-row-vs-var.inc + +--let type=TINYINT(20) +--source sp-row-vs-var.inc + +--let type=TINYINT(21) +--source sp-row-vs-var.inc + +--echo # +--echo # SMALLINT +--echo # + +--let type=SMALLINT +--source sp-row-vs-var.inc + +--let type=SMALLINT(1) +--source sp-row-vs-var.inc + +--let type=SMALLINT(2) +--source sp-row-vs-var.inc + +--let type=SMALLINT(3) +--source sp-row-vs-var.inc + +--let type=SMALLINT(4) +--source sp-row-vs-var.inc + +--let type=SMALLINT(5) +--source sp-row-vs-var.inc + +--let type=SMALLINT(6) +--source sp-row-vs-var.inc + +--let type=SMALLINT(7) +--source sp-row-vs-var.inc + +--let type=SMALLINT(8) +--source sp-row-vs-var.inc + +--let type=SMALLINT(9) +--source sp-row-vs-var.inc + +--let type=SMALLINT(10) +--source sp-row-vs-var.inc + +--let type=SMALLINT(11) +--source sp-row-vs-var.inc + +--let type=SMALLINT(12) +--source sp-row-vs-var.inc + +--let type=SMALLINT(13) +--source sp-row-vs-var.inc + +--let type=SMALLINT(14) +--source sp-row-vs-var.inc + +--let type=SMALLINT(20) +--source sp-row-vs-var.inc + +--let type=SMALLINT(21) +--source sp-row-vs-var.inc + + +--echo # +--echo # MEDIUMINT +--echo # + +--let type=MEDIUMINT +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(1) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(2) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(3) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(4) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(5) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(6) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(7) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(8) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(9) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(10) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(11) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(12) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(13) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(14) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(20) +--source sp-row-vs-var.inc + +--let type=MEDIUMINT(21) +--source sp-row-vs-var.inc + + +--echo # +--echo # BIGINT +--echo # + +--let type=BIGINT +--source sp-row-vs-var.inc + +--let type=BIGINT(1) +--source sp-row-vs-var.inc + +--let type=BIGINT(2) +--source sp-row-vs-var.inc + +--let type=BIGINT(3) +--source sp-row-vs-var.inc + +--let type=BIGINT(4) +--source sp-row-vs-var.inc + +--let type=BIGINT(5) +--source sp-row-vs-var.inc + +--let type=BIGINT(6) +--source sp-row-vs-var.inc + +--let type=BIGINT(7) +--source sp-row-vs-var.inc + +--let type=BIGINT(8) +--source sp-row-vs-var.inc + +--let type=BIGINT(9) +--source sp-row-vs-var.inc + +--let type=BIGINT(10) +--source sp-row-vs-var.inc + +--let type=BIGINT(11) +--source sp-row-vs-var.inc + +--let type=BIGINT(12) +--source sp-row-vs-var.inc + +--let type=BIGINT(13) +--source sp-row-vs-var.inc + +--let type=BIGINT(14) +--source sp-row-vs-var.inc + +--let type=BIGINT(20) +--source sp-row-vs-var.inc + +--let type=BIGINT(21) +--source sp-row-vs-var.inc + + +--echo # +--echo # DOUBLE +--echo # + +--let type=DOUBLE +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,1) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,2) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,3) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,4) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,5) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,6) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,7) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,8) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,9) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,10) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,11) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,12) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,13) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,14) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,20) +--source sp-row-vs-var.inc + +--let type=DOUBLE(30,21) +--source sp-row-vs-var.inc + +--echo # +--echo # VARCHAR +--echo # + +--let type=CHAR +--source sp-row-vs-var.inc + +--let type=BINARY +--source sp-row-vs-var.inc + +--let type=CHAR(1) +--source sp-row-vs-var.inc + +--let type=CHAR(10) +--source sp-row-vs-var.inc + +--let type=NCHAR(10) +--source sp-row-vs-var.inc + +--let type=BINARY(10) +--source sp-row-vs-var.inc + +--let type=VARBINARY(10) +--source sp-row-vs-var.inc + +--let type=VARCHAR(10) +--source sp-row-vs-var.inc + +--let type=VARCHAR(10) CHARACTER SET utf8 +--source sp-row-vs-var.inc + +--let type=VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin +--source sp-row-vs-var.inc + +--echo # +--echo # TIME +--echo # + +--let type=TIME +--source sp-row-vs-var.inc + +--let type=TIME(1) +--source sp-row-vs-var.inc + +--let type=TIME(2) +--source sp-row-vs-var.inc + +--let type=TIME(3) +--source sp-row-vs-var.inc + +--let type=TIME(4) +--source sp-row-vs-var.inc + +--let type=TIME(5) +--source sp-row-vs-var.inc + +--let type=TIME(6) +--source sp-row-vs-var.inc + +--echo # +--echo # DATETIME +--echo # + +--let type=DATETIME +--source sp-row-vs-var.inc + +--let type=DATETIME(1) +--source sp-row-vs-var.inc + +--let type=DATETIME(2) +--source sp-row-vs-var.inc + +--let type=DATETIME(3) +--source sp-row-vs-var.inc + +--let type=DATETIME(4) +--source sp-row-vs-var.inc + +--let type=DATETIME(5) +--source sp-row-vs-var.inc + +--let type=DATETIME(6) +--source sp-row-vs-var.inc + + +--echo # +--echo # LOB +--echo # + +--let type=TEXT +--source sp-row-vs-var.inc + +--let type=TINYTEXT +--source sp-row-vs-var.inc + +--let type=MEDIUMTEXT +--source sp-row-vs-var.inc + +--let type=LONGTEXT +--source sp-row-vs-var.inc + +--let type=TEXT CHARACTER SET utf8 +--source sp-row-vs-var.inc + +--let type=TINYTEXT CHARACTER SET utf8 +--source sp-row-vs-var.inc + +--let type=MEDIUMTEXT CHARACTER SET utf8 +--source sp-row-vs-var.inc + +--let type=LONGTEXT CHARACTER SET utf8 +--source sp-row-vs-var.inc + + +--echo # +--echo # End of MDEV-10914 ROW data type for stored routine variables +--echo # + + +--echo # +--echo # MDEV-12133 sql_mode=ORACLE: table%ROWTYPE in variable declarations +--echo # + +--echo # +--echo # Referring to a table in a non-existing database +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec test2.t1%ROWTYPE; +BEGIN + NULL; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1(); +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +--error ER_NO_SUCH_TABLE +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Referring to a table in the current database +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec t1%ROWTYPE; +BEGIN + CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; + SHOW CREATE TABLE t2; + DROP TABLE t2; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1(); +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Referring to a table in an explicitly specified database +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec test.t1%ROWTYPE; +BEGIN + CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; + SHOW CREATE TABLE t2; + DROP TABLE t2; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1(); +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Referring to a view in the current database +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec v1%ROWTYPE; +BEGIN + CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; + SHOW CREATE TABLE t2; + DROP TABLE t2; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1(); +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CREATE VIEW v1 AS SELECT * FROM t1; +CALL p1(); +DROP VIEW v1; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Referring to a view in an explicitly specified database +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec test.v1%ROWTYPE; +BEGIN + CREATE TABLE t2 AS SELECT rec.a, rec.b, rec.c, rec.d; + SHOW CREATE TABLE t2; + DROP TABLE t2; +END; +$$ +DELIMITER ;$$ +--error ER_NO_SUCH_TABLE +CALL p1(); +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10)); +CREATE VIEW v1 AS SELECT * FROM t1; +CALL p1(); +DROP VIEW v1; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Checking that all table%ROWTYPE fields are NULL by default +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; +BEGIN + SELECT rec1.a, rec1.b, rec1.c, rec1.d; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # A table%ROWTYPE variable with a ROW expression as a default +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE DEFAULT ROW(10,'bbb'); +BEGIN + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # A table%ROWTYPE variable with an incompatible ROW expression as a default +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE DEFAULT ROW(10,'bbb','ccc'); +BEGIN + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # A table%ROWTYPE variable with a ROW variable as a default +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 ROW(a INT, b VARCHAR(10)):= ROW(10,'bbb'); + rec2 t1%ROWTYPE DEFAULT rec1; +BEGIN + SELECT rec2.a, rec2.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # A ROW variable using a table%ROWTYPE variable as a default +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE := ROW(10,'bbb'); + rec2 ROW(a INT, b VARCHAR(10)):= rec1; +BEGIN + SELECT rec2.a, rec2.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning table%ROWTYPE variables with a different column count +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE); +CREATE TABLE t2 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; + rec2 t2%ROWTYPE; +BEGIN + rec2:=rec1; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP PROCEDURE p1; +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; + rec2 t2%ROWTYPE; +BEGIN + rec1:=rec2; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning compatible table%ROWTYPE variables (equal number of fields) +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (x INT, y VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; + rec2 t2%ROWTYPE; +BEGIN + rec1.a:= 10; + rec1.b:= 'bbb'; + rec2:=rec1; + SELECT rec2.x, rec2.y; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning between incompatible table%ROWTYPE and explicit ROW variables +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; + rec2 ROW(x INT,y INT,z INT); +BEGIN + rec2.x:= 10; + rec2.y:= 20; + rec2.z:= 30; + rec1:= rec2; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning between compatible table%ROWTYPE and explicit ROW variables +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; + rec2 ROW(x INT,y INT); +BEGIN + rec2.x:= 10; + rec2.y:= 20; + rec1:= rec2; + SELECT rec1.a, rec1.b; + rec1.a:= 11; + rec1.b:= 21; + rec2:= rec1; + SELECT rec2.x, rec2.y; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Assigning table%ROWTYPE from a ROW expression +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE; +BEGIN + rec1:= ROW(10,20); + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Fetching a cursor into a table%ROWTYPE variable with a wrong field count +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +CREATE TABLE t2 (a INT, b VARCHAR(10)); +INSERT INTO t1 VALUES (10,'bb1',111.111e2, 12.31); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec2 t2%ROWTYPE; + CURSOR cur1 IS SELECT * FROM t1; +BEGIN + OPEN cur1; + FETCH cur1 INTO rec2; + CLOSE cur1; +END; +$$ +DELIMITER ;$$ +--error ER_SP_WRONG_NO_OF_FETCH_ARGS +CALL p1(); +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Fetching a cursor into a table%ROWTYPE variable +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10,2)); +CREATE TABLE t2 LIKE t1; +INSERT INTO t1 VALUES (10,'bb1',111.111e2, 12.31); +INSERT INTO t1 VALUES (20,'bb2',222.222e2, 12.32); +INSERT INTO t1 VALUES (30,'bb3',333.333e2, 12.33); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec t1%ROWTYPE; + CURSOR cur IS SELECT * FROM t1; +BEGIN + OPEN cur; + LOOP + FETCH cur INTO rec; + EXIT WHEN cur%NOTFOUND; + SELECT rec.a, rec.b, rec.c, rec.d; + INSERT INTO t2 VALUES (rec.a, rec.b, rec.c, rec.d); + END LOOP; + CLOSE cur; +END; +$$ +DELIMITER ;$$ +CALL p1(); +SELECT * FROM t2; +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + +--echo # +--echo # Fetching a cursor into a table%ROWTYPE variable with different column names +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (x INT, y VARCHAR(10)); +INSERT INTO t1 VALUES (10,'bbb'); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec2 t2%ROWTYPE; + CURSOR cur1 IS SELECT * FROM t1; +BEGIN + OPEN cur1; + FETCH cur1 INTO rec2; + SELECT rec2.x, rec2.y; + CLOSE cur1; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # Fetching a cursor into a table%ROWTYPE variable, with truncation +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t1 VALUES (10,'11x'); +DELIMITER $$; +CREATE PROCEDURE p1() +AS + rec2 t2%ROWTYPE; + CURSOR cur1 IS SELECT * FROM t1; +BEGIN + OPEN cur1; + FETCH cur1 INTO rec2; + SELECT rec2.a, rec2.b; + CLOSE cur1; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t2; +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # table%ROWTYPE variables are not allowed in LIMIT +--echo # +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,2); +DELIMITER $$; +--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +CREATE PROCEDURE p1() +AS + rec1 t1%ROWTYPE:=(1,2); +BEGIN + SELECT * FROM t1 LIMIT rec1.a; +END; +$$ +DELIMITER ;$$ +DROP TABLE t1; + + +--echo # +--echo # table%ROWTYPE variable fields as OUT parameters +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1(a OUT INT,b OUT VARCHAR(10)) +AS +BEGIN + a:=10; + b:='bb'; +END; +$$ +CREATE PROCEDURE p2() +AS + rec1 t1%ROWTYPE; +BEGIN + CALL p1(rec1.a, rec1.b); + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p2(); +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Passing the entire table%ROWTYPE variable +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1(a ROW(a INT, b VARCHAR(10))) +AS +BEGIN + SELECT a.a, a.b; +END; +$$ +CREATE PROCEDURE p2() +AS + rec1 t1%ROWTYPE:= ROW(10,'bb'); +BEGIN + CALL p1(rec1); +END; +$$ +DELIMITER ;$$ +CALL p2(); +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Passing the entire table%ROWTYPE variable as an OUT parameter +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1(a OUT ROW(a INT, b VARCHAR(10))) +AS +BEGIN + a:= ROW(10,'bb'); +END; +$$ +CREATE PROCEDURE p2() +AS + rec1 t1%ROWTYPE; +BEGIN + CALL p1(rec1); + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p2(); +DROP PROCEDURE p2; +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Assigning a table%ROWTYPE field to an OUT parameter +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1 (res IN OUT INTEGER) +AS + rec1 t1%ROWTYPE:=ROW(10,'b0'); +BEGIN + res:=rec1.a; +END; +$$ +DELIMITER ;$$ +CALL p1(@res); +SELECT @res; +SET @res=NULL; +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Testing Item_splocal_row_field_by_name::print +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN + EXPLAIN EXTENDED SELECT rec.a, rec.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + +--echo # +--echo # Non-existing field +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec t1%ROWTYPE; +BEGIN + SELECT rec.c; +END; +$$ +DELIMITER ;$$ +--error ER_ROW_VARIABLE_DOES_NOT_HAVE_FIELD +CALL p1(); +ALTER TABLE t1 ADD c INT; +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Testing that field names are case insensitive +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN + SELECT rec.A, rec.B; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Testing that table%ROWTYPE uses temporary tables vs shadowed real tables +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(10)); +CREATE TEMPORARY TABLE t1 (x INT, y VARCHAR(10)); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + rec t1%ROWTYPE:=ROW(10,'bb'); +BEGIN + SELECT rec.A, rec.B; +END; +$$ +DELIMITER ;$$ +--error ER_ROW_VARIABLE_DOES_NOT_HAVE_FIELD +CALL p1(); +DROP TEMPORARY TABLE t1; +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + +--echo # +--echo # Testing that the structure of table%ROWTYPE variables is determined at the very beginning and is not changed after ALTER +--echo # + +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + ALTER TABLE t1 ADD c INT; + DECLARE + rec t1%ROWTYPE; -- this will not have column "c" + BEGIN + rec.c:=10; + END; +END; +$$ +DELIMITER ;$$ +--error ER_ROW_VARIABLE_DOES_NOT_HAVE_FIELD +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # MDEV-12291 Allow ROW variables as SELECT INTO targets +--echo # + + +--enable_prepare_warnings +--echo # ROW variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 ROW(a INT, b VARCHAR(32), c DOUBLE); +BEGIN + SELECT * FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # Multiple ROW variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 ROW(a INT, b VARCHAR(32)); +BEGIN + SELECT * FROM t1 INTO rec1, rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # ROW variables working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 ROW(a INT, b VARCHAR(32)); +BEGIN + SELECT * FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # table%ROWTYPE variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 t1%ROWTYPE; +BEGIN + SELECT 10,'a','b' FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # Multiple table%ROWTYPE variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 t1%ROWTYPE; +BEGIN + SELECT 10,'a' FROM t1 INTO rec1, rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # table%ROWTYPE working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + rec1 t1%ROWTYPE; +BEGIN + SELECT * FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # cursor%ROWTYPE variable with a wrong column count +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + CURSOR cur1 IS SELECT 10, 'b0', 'c0'; + rec1 cur1%ROWTYPE; +BEGIN + SELECT * FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # Multiple cursor%ROWTYPE variables +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + CURSOR cur1 IS SELECT * FROM t1; + rec1 cur1%ROWTYPE; +BEGIN + SELECT * FROM t1 INTO rec1, rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +--error ER_OPERAND_COLUMNS +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # cursor%ROWTYPE working example +CREATE TABLE t1 (a INT, b VARCHAR(32)); +INSERT INTO t1 VALUES (10,'b10'); +DELIMITER $$; +CREATE PROCEDURE p1 AS + CURSOR cur1 IS SELECT * FROM t1; + rec1 cur1%ROWTYPE; +BEGIN + SELECT * FROM t1 INTO rec1; + SELECT rec1.a, rec1.b; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; +--disable_prepare_warnings + +--echo # +--echo # MDEV-12347 Valgrind reports invalid read errors in Item_field_row::element_index_by_name +--echo # + +# An additional test for MDEV-12347, to make sure that +# Column_definition::interval creates a permanent copy of TYPELIB on +# the memory root when processing %ROWTYPE for a table with ENUM/SET column, +# rather than reuses the TYPELIB from table->field[i], which is freed in the +# end of sp_rcontext::resolve_table_rowtype_ref(). + +CREATE TABLE t1 (a INT, b ENUM('b0','b1','b12','b3')); +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + DECLARE + rec t1%ROWTYPE; + BEGIN + rec.b:='b0'; + SELECT rec.b; + END; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +CREATE TABLE t1 (a INT, b SET('b0','b1','b12','b3')); +DELIMITER $$; +CREATE PROCEDURE p1 AS +BEGIN + DECLARE + rec t1%ROWTYPE; + BEGIN + rec.b:='b0'; + SELECT rec.b; + END; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP TABLE t1; +DROP PROCEDURE p1; + + +--echo # +--echo # MDEV-13273 Confusion between table alias and ROW type variable +--echo # + +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + a INT; + b INT; +BEGIN + -- a.c1 is a table column + SELECT a.c1 INTO b + FROM t1 a + WHERE a.c2 = 0; + SELECT b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + a ROW (c1 INT, c2 INT) := ROW(101,102); + b INT; +BEGIN + -- a.c1 is a ROW variable field + SELECT a.c1 INTO b + FROM t1 a + WHERE a.c2 = 102; + SELECT b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + a t1%ROWTYPE := ROW (10,20); + b INT; +BEGIN + -- a.c1 is a ROW variable field + SELECT a.c1 INTO b + FROM t1 a + WHERE a.c2 = 20; + SELECT b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + +CREATE TABLE t1 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (0,0); +DELIMITER $$; +CREATE PROCEDURE p1 +AS + CURSOR cur1 IS SELECT * FROM t1; + a cur1%ROWTYPE := ROW (10,20); + b INT; +BEGIN + -- a.c1 is a ROW variable field + SELECT a.c1 INTO b + FROM t1 a + WHERE a.c2 = 20; + SELECT b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + +--echo # +--echo # MDEV-13527 Crash when EXPLAIN SELECT .. INTO row_sp_variable.field +--echo # + +DELIMITER $$; +DECLARE + a ROW(a INT); +BEGIN + EXPLAIN SELECT 1 INTO a.a; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # MDEV-14139 Anchored data types for variables +--echo # + +DELIMITER $$; +DECLARE + row1 ROW(int11 INT,text1 TEXT); + a_row1 row1%TYPE; + aa_row1 a_row1%TYPE; +BEGIN + CREATE TABLE t1 AS SELECT a_row1.int11 AS int11, a_row1.text1 AS text1; + SHOW CREATE TABLE t1; + DROP TABLE t1; + CREATE TABLE t1 AS SELECT aa_row1.int11 AS int11, aa_row1.text1 AS text1; + SHOW CREATE TABLE t1; + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ diff --git a/mysql-test/suite/compat/oracle/t/sp-security.test b/mysql-test/suite/compat/oracle/t/sp-security.test new file mode 100644 index 00000000..1732c0b8 --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp-security.test @@ -0,0 +1,345 @@ +--source include/not_embedded.inc + +SET sql_mode=ORACLE; + +--echo # +--echo # MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations +--echo # + + +--echo # +--echo # Initiation: +--echo # - creating database db1 +--echo # - creating user user1 with access rights to db1 +--echo # + +CREATE DATABASE db1; +CREATE TABLE db1.t1 (a INT, b VARCHAR(10)); + +CREATE USER user1; + +GRANT ALL PRIVILEGES ON test.* TO user1; + +connect (conn1,localhost,user1,,test); +SET sql_mode=ORACLE; + +SELECT database(); +SELECT user(); + +--echo # +--echo # Making sure that user1 does not have privileges to db1.t1 +--echo # + +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE db1.t1; +--error ER_TABLEACCESS_DENIED_ERROR +SHOW FIELDS IN db1.t1; + + +--echo # +--echo # Trigger: using %TYPE with a table we don't have access to +--echo # +CREATE TABLE test.t1 (a INT, b INT); +INSERT INTO test.t1 (a,b) VALUES (10,20); +SELECT * FROM t1; +DELIMITER $$; +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN + DECLARE b db1.t1.b%TYPE := 20; + BEGIN + :NEW.b := 10; + END; +END +$$ +DELIMITER ;$$ +--error ER_TABLEACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +SELECT * FROM t1; +DROP TRIGGER tr1; +DROP TABLE t1; + + +--echo # +--echo # Stored procedure: Using %TYPE for with a table that we don't have access to +--echo # DEFINER user1, SQL SECURITY DEFAULT +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a db1.t1.a%TYPE := 10; +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +--error ER_TABLEACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a db1.t1%ROWTYPE; +BEGIN + SELECT a.a; +END; +$$ +DELIMITER ;$$ +--error ER_TABLEACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # Stored procedure: Using %TYPE for with a table that we don't have access to +--echo # DEFINER root, SQL SECURITY INVOKER +--echo # + +connection default; +DELIMITER $$; +CREATE PROCEDURE p1() +SQL SECURITY INVOKER +AS + a db1.t1.a%TYPE := 10; +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +connection conn1; +--error ER_TABLEACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + + +connection default; +DELIMITER $$; +CREATE PROCEDURE p1() +SQL SECURITY INVOKER +AS + a db1.t1%ROWTYPE; +BEGIN + SELECT a.a; +END; +$$ +DELIMITER ;$$ +connection conn1; +--error ER_TABLEACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # Stored procedure: Using %TYPE for with a table that we don't have access to +--echo # DEFINER root, SQL SECURITY DEFINER +--echo # + +connection default; +DELIMITER $$; +CREATE PROCEDURE p1() +SQL SECURITY DEFINER +AS + a db1.t1.a%TYPE := 10; +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +connection conn1; +CALL p1; +DROP PROCEDURE p1; + +connection default; +DELIMITER $$; +CREATE PROCEDURE p1() +SQL SECURITY DEFINER +AS + a db1.t1%ROWTYPE; +BEGIN + a.a:= 10; + SELECT a.a; +END; +$$ +DELIMITER ;$$ +connection conn1; +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # Stored function: Using %TYPE for with a table that we don't have access to +--echo # DEFINER user1, SQL SECURITY DEFAULT +--echo # + +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE FUNCTION f1() RETURN INT +AS + a db1.t1.a%TYPE:=0; +BEGIN + RETURN OCTET_LENGTH(a); +END; +$$ +DELIMITER ;$$ +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f1(); +DROP FUNCTION f1; +DROP TABLE t1; + + +--echo # +--echo # Stored function: Using %TYPE for with a table that we don't have access to +--echo # DEFINER root, SQL SECURITY INVOKER +--echo # + +connection default; +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE FUNCTION f1() RETURN INT +SQL SECURITY INVOKER +AS + a db1.t1.a%TYPE:=0; +BEGIN + RETURN OCTET_LENGTH(a); +END; +$$ +DELIMITER ;$$ +connection conn1; +--error ER_TABLEACCESS_DENIED_ERROR +SELECT f1(); +DROP FUNCTION f1; +DROP TABLE t1; + + +--echo # +--echo # Stored function: Using %TYPE for with a table that we don't have access to +--echo # DEFINER root, SQL SECURITY DEFINER +--echo # + +connection default; +CREATE TABLE t1 (a INT); +DELIMITER $$; +CREATE FUNCTION f1() RETURN INT +SQL SECURITY DEFINER +AS + a db1.t1.a%TYPE:=0; +BEGIN + RETURN OCTET_LENGTH(a); +END; +$$ +DELIMITER ;$$ +connection conn1; +SELECT f1(); +DROP FUNCTION f1; +DROP TABLE t1; + + +connection default; +GRANT SELECT (a) ON db1.t1 TO user1; +connection conn1; + +--echo # +--echo # Making sure that user1 has access to db1.t1.a, but not to db1.t1.b +--echo # + +--error ER_TABLEACCESS_DENIED_ERROR +SHOW CREATE TABLE db1.t1; +SHOW FIELDS IN db1.t1; + +--echo # +--echo # Trigger: Per-column privileges +--echo # +CREATE TABLE test.t1 (a INT, b INT); +INSERT INTO test.t1 (a,b) VALUES (10,20); +SELECT * FROM t1; +# %TYPE reference using a column we have access to +DELIMITER $$; +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN + DECLARE a db1.t1.a%TYPE := 20; + BEGIN + :NEW.b := 10; + END; +END +$$ +DELIMITER ;$$ +INSERT INTO t1 (a) VALUES (10); +SELECT * FROM t1; +DROP TRIGGER tr1; +# %TYPE reference using a column that we don't have access to +DELIMITER $$; +CREATE TRIGGER test.tr1 BEFORE INSERT ON test.t1 FOR EACH ROW +BEGIN + DECLARE b db1.t1.b%TYPE := 20; + BEGIN + :NEW.b := 10; + END; +END +$$ +DELIMITER ;$$ +--error ER_COLUMNACCESS_DENIED_ERROR +INSERT INTO t1 (a) VALUES (10); +SELECT * FROM t1; +DROP TRIGGER tr1; +DROP TABLE t1; + + + +--echo # +--echo # Stored procedure: Per-column privileges +--echo # DEFINER user1, SQL SECURITY DEFAULT +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + a db1.t1.a%TYPE := 10; +BEGIN + SELECT a; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + b db1.t1.b%TYPE := 10; +BEGIN + SELECT b; +END; +$$ +DELIMITER ;$$ +--error ER_COLUMNACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE PROCEDURE p1() +AS + b db1.t1%ROWTYPE; +BEGIN + b.b:=10; + SELECT b.b; +END; +$$ +DELIMITER ;$$ +--error ER_COLUMNACCESS_DENIED_ERROR +CALL p1; +DROP PROCEDURE p1; + + +--echo # +--echo # Clean up +--echo # +disconnect conn1; +connection default; + +DROP USER user1; +DROP DATABASE db1; + +--echo # +--echo # End of MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations +--echo # diff --git a/mysql-test/suite/compat/oracle/t/sp.test b/mysql-test/suite/compat/oracle/t/sp.test new file mode 100644 index 00000000..69b8608b --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/sp.test @@ -0,0 +1,2430 @@ +--source include/default_charset.inc + +SET sql_mode=ORACLE; + +--echo # Testing routines with no parameters +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +AS +BEGIN + RETURN 10; +END; +/ +DELIMITER ;/ +--vertical_results +SHOW CREATE FUNCTION f1; +--horizontal_results +SELECT f1(); +DROP FUNCTION f1; + + +DELIMITER /; +CREATE PROCEDURE p1 +AS +BEGIN + SET @a=10; +END; +/ +DELIMITER ;/ +--vertical_results +SHOW CREATE PROCEDURE p1; +--horizontal_results +SET @a=0; +CALL p1(); +SELECT @a; +DROP PROCEDURE p1; + +--echo # Testing ":=" to set the default value of a variable +DELIMITER /; +CREATE FUNCTION f1 () RETURN NUMBER(10) AS + a NUMBER(10) := 10; +BEGIN + DECLARE + b NUMBER(10) DEFAULT 3; + BEGIN + RETURN a+b; + END; +END; +/ +DELIMITER ;/ +SELECT f1(); +DROP FUNCTION f1; + +--echo # Testing labels + +DELIMITER /; +CREATE FUNCTION f1 (a INT) RETURN CLOB AS +BEGIN + <> + BEGIN + IF a = 1 THEN + LEAVE label1; + END IF; + RETURN 'IS NOT 1'; + END label1; + RETURN 'IS 1'; +END; +/ +DELIMITER ;/ +SELECT f1(1); +SELECT f1(2); +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 (a INT) RETURN INT IS +BEGIN + <> + LOOP + IF a = 2 THEN + LEAVE label1; + END IF; + SET a= a-1; + END LOOP; + RETURN a; +END; +/ +DELIMITER ;/ +SELECT f1(4); +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 (a INT) RETURN INT AS +BEGIN + <> + WHILE a>0 LOOP + IF a = 2 THEN + LEAVE label1; + END IF; + SET a= a-1; + END LOOP label1; + RETURN a; +END; +/ +DELIMITER ;/ +SELECT f1(4); +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 (a INT) RETURN INT AS +BEGIN + <> + REPEAT + IF a = 2 THEN + LEAVE label1; + END IF; + SET a= a-1; + UNTIL a=0 END REPEAT; + RETURN a; +END; +/ +DELIMITER ;/ +SELECT f1(4); +DROP FUNCTION f1; + +--echo # Testing IN/OUT/INOUT + +DELIMITER /; +CREATE PROCEDURE p1 (p1 IN VARCHAR2(10), p2 OUT VARCHAR2(10)) AS +BEGIN + SET p1='p1new'; + SET p2='p2new'; +END; +/ +DELIMITER ;/ +SET @p1='p1', @p2='p2'; +CALL p1(@p1, @p2); +SELECT @p1, @p2; +DROP PROCEDURE p1; + +--echo # Testing Oracle-style assigment +DELIMITER /; +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) AS +BEGIN + p1:= 'p1new'; +END; +/ +DELIMITER ;/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +DROP PROCEDURE p1; + +--echo # Testing that NULL is a valid statement +DELIMITER /; +CREATE PROCEDURE p1(a INT) AS +BEGIN + NULL; +END; +/ +DELIMITER ;/ +DROP PROCEDURE p1; + +DELIMITER /; +CREATE PROCEDURE p1(a INT) AS + a INT:=10; +BEGIN + IF a=10 THEN NULL; ELSE NULL; END IF; +END; +/ +DELIMITER ;/ +DROP PROCEDURE p1; + +--echo # Keywords that are OK for table names, but not for SP variables +CREATE TABLE function (function int); +INSERT INTO function SET function=10; +SELECT function.function FROM function; +DROP TABLE function; + +--echo # Testing that (some) keyword_sp are allowed in Oracle-style assignments +DELIMITER /; +CREATE PROCEDURE p1 (action OUT INT) AS BEGIN action:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (clob OUT INT) AS BEGIN clob:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (enum OUT INT) AS BEGIN enum:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (via OUT INT) AS BEGIN via:=10; END;/ +DROP PROCEDURE p1/ +DELIMITER ;/ + +--echo # Testing keyword_directly_assignable +DELIMITER /; +CREATE PROCEDURE p1 (ascii OUT INT) AS BEGIN ascii:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (backup OUT INT) AS BEGIN backup:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (binlog OUT INT) AS BEGIN binlog:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (byte OUT INT) AS BEGIN byte:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (cache OUT INT) AS BEGIN cache:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (checksum OUT INT) AS BEGIN checksum:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (checkpoint OUT INT) AS BEGIN checkpoint:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_add OUT INT) AS BEGIN column_add:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_check OUT INT) AS BEGIN column_check:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_create OUT INT) AS BEGIN column_create:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_delete OUT INT) AS BEGIN column_delete:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (column_get OUT INT) AS BEGIN column_get:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (deallocate OUT INT) AS BEGIN deallocate:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (examined OUT INT) AS BEGIN examined:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (execute OUT INT) AS BEGIN execute:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (flush OUT INT) AS BEGIN flush:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (format OUT INT) AS BEGIN format:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (get OUT INT) AS BEGIN get:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (help OUT INT) AS BEGIN help:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (host OUT INT) AS BEGIN host:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (install OUT INT) AS BEGIN install:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (option OUT INT) AS BEGIN option:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (options OUT INT) AS BEGIN options:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (owner OUT INT) AS BEGIN owner:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (parser OUT INT) AS BEGIN parser:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (port OUT INT) AS BEGIN port:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (prepare OUT INT) AS BEGIN prepare:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (remove OUT INT) AS BEGIN remove:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (reset OUT INT) AS BEGIN reset:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (restore OUT INT) AS BEGIN restore:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (security OUT INT) AS BEGIN security:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (server OUT INT) AS BEGIN server:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (signed OUT INT) AS BEGIN signed:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (socket OUT INT) AS BEGIN socket:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (slave OUT INT) AS BEGIN slave:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (slaves OUT INT) AS BEGIN slaves:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (soname OUT INT) AS BEGIN soname:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (start OUT INT) AS BEGIN start:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (stop OUT INT) AS BEGIN stop:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (stored OUT INT) AS BEGIN stored:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (unicode OUT INT) AS BEGIN unicode:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (uninstall OUT INT) AS BEGIN uninstall:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (upgrade OUT INT) AS BEGIN upgrade:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (wrapper OUT INT) AS BEGIN wrapper:=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (xa OUT INT) AS BEGIN xa:=10; END;/ +DROP PROCEDURE p1/ +DELIMITER ;/ + + +--echo # Testing that keyword_directly_not_assignable does not work in := +DELIMITER /; +--error ER_PARSE_ERROR +CREATE PROCEDURE p1 (commit OUT INT) AS BEGIN commit:=10; END;/ +--error ER_PARSE_ERROR +CREATE PROCEDURE p1 (rollback OUT INT) AS BEGIN rollback:=10; END;/ +--error ER_PARSE_ERROR +CREATE PROCEDURE p1 (shutdown OUT INT) AS BEGIN shutdown:=10; END;/ +--error ER_PARSE_ERROR +CREATE PROCEDURE p1 (exception OUT INT) AS BEGIN exception:=10; END;/ +DELIMITER ;/ + + +--echo # Testing that keyword_directly_not_assignable works in SET statements. +DELIMITER /; +CREATE PROCEDURE p1 (contains OUT INT) AS BEGIN SET contains=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (language OUT INT) AS BEGIN SET language=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (no OUT INT) AS BEGIN SET no=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (charset OUT INT) AS BEGIN SET charset=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (do OUT INT) AS BEGIN SET do=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (repair OUT INT) AS BEGIN SET repair=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (handler OUT INT) AS BEGIN SET handler=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (open OUT INT) AS BEGIN SET open=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (close OUT INT) AS BEGIN SET close=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (savepoint OUT INT) AS BEGIN SET savepoint=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (truncate OUT INT) AS BEGIN SET truncate=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (begin OUT INT) AS BEGIN SET begin=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (end OUT INT) AS BEGIN SET end=10; END;/ +DROP PROCEDURE p1/ +CREATE PROCEDURE p1 (exception OUT INT) AS BEGIN SET exception=10; END;/ +DROP PROCEDURE p1/ +DELIMITER ;/ + +--echo # Testing that keyword_directly_not_assignable works in table/column names +CREATE TABLE contains (contains INT); +DROP TABLE contains; +CREATE TABLE language (language INT); +DROP TABLE language; +CREATE TABLE no (no INT); +DROP TABLE no; +CREATE TABLE charset (charset INT); +DROP TABLE charset; +CREATE TABLE do (do INT); +DROP TABLE do; +CREATE TABLE repair (repair INT); +DROP TABLE repair; +CREATE TABLE handler (handler INT); +DROP TABLE handler; +CREATE TABLE open (open INT); +DROP TABLE open; +CREATE TABLE close (close INT); +DROP TABLE close; +CREATE TABLE savepoint (savepoint INT); +DROP TABLE savepoint; +CREATE TABLE truncate (truncate INT); +DROP TABLE truncate; +CREATE TABLE begin (begin INT); +DROP TABLE begin; +CREATE TABLE end (end INT); +DROP TABLE end; +CREATE TABLE exception (exception INT); +DROP TABLE exception; + +--echo # Testing ELSIF +DELIMITER /; +CREATE FUNCTION f1(a INT) RETURN CLOB +AS +BEGIN + IF a=1 THEN RETURN 'a is 1'; + ELSIF a=2 THEN RETURN 'a is 2'; + ELSE RETURN 'a is unknown'; + END IF; +END; +/ +DELIMITER ;/ +SELECT f1(2) FROM DUAL; +DROP FUNCTION f1; + + + +--echo # Testing top-level declarations +DELIMITER /; +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) +AS + p2 VARCHAR(10); +BEGIN + p2:='p1new'; + p1:=p2; +END; +/ +DELIMITER ;/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +DROP PROCEDURE p1; + +DELIMITER /; +CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20) +AS + p2 VARCHAR(10); +BEGIN + p2:='new'; + RETURN CONCAT(p1, p2); +END; +/ +DELIMITER ;/ +SET @p1='p1'; +SELECT f1(@p1); +DROP FUNCTION f1; + +--echo # Testing non-top declarations + +DELIMITER /; +CREATE PROCEDURE p1 (p1 OUT VARCHAR2(10)) +AS +BEGIN + DECLARE + p2 VARCHAR(10); + BEGIN + p2:='p1new'; + p1:=p2; + END; + DECLARE + t1 VARCHAR(10); + t2 VARCHAR(10); + BEGIN + END; +END; +/ +DELIMITER ;/ +SET @p1='p1'; +CALL p1(@p1); +SELECT @p1; +DROP PROCEDURE p1; + +DELIMITER /; +CREATE FUNCTION f1 (p1 VARCHAR2(10)) RETURN VARCHAR(20) +AS +BEGIN + DECLARE + p2 VARCHAR(10); + BEGIN + p2:='new'; + RETURN CONCAT(p1, p2); + END; + DECLARE + t1 VARCHAR(10); + t2 VARCHAR(10); + BEGIN + END; +END; +/ +DELIMITER ;/ +SET @p1='p1'; +SELECT f1(@p1); +DROP FUNCTION f1; + + +--echo # Testing exceptions + +CREATE TABLE t1 (c1 INT); + +DELIMITER /; + +CREATE PROCEDURE sp1 (p1 IN VARCHAR2(20), p2 OUT VARCHAR2(30)) +IS + v1 INT; +BEGIN + SELECT c1 INTO v1 FROM t1; + p2 := p1; +EXCEPTION + WHEN NOT FOUND THEN + BEGIN + p2 := 'def'; + END; +END; +/ + +DELIMITER ;/ + +CALL sp1('abc', @a); +SELECT @a; + +DROP PROCEDURE sp1; +DROP TABLE t1; + + +DELIMITER /; +CREATE PROCEDURE sp1 (v IN OUT INT, error IN INT) +IS +BEGIN + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=error, MESSAGE_TEXT='User defined error!'; + v:= 223; +EXCEPTION + WHEN 30001 THEN + BEGIN + v:= 113; + END; +END; +/ +DELIMITER ;/ +SET @v=10; +CALL sp1(@v, 30001); +--error 30002 +CALL sp1(@v, 30002); +SELECT @v; +DROP PROCEDURE sp1; + + +DELIMITER /; +CREATE PROCEDURE sp1 (v IN OUT INT, error IN INT) +IS +BEGIN + BEGIN + BEGIN + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=error, MESSAGE_TEXT='User defined error!'; + v:= 223; + EXCEPTION + WHEN 30001 THEN + BEGIN + v:= 113; + END; + END; + END; +END; +/ +DELIMITER ;/ +SET @v=10; +CALL sp1(@v, 30001); +SELECT @v; +SET @v=10; +--error 30002 +CALL sp1(@v, 30002); +SELECT @v; +DROP PROCEDURE sp1; + + +--echo # +--echo # Testing EXIT statement +--echo # + +DELIMITER /; +--error ER_SP_LILABEL_MISMATCH +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + EXIT; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +--error ER_SP_LILABEL_MISMATCH +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + <> + BEGIN + <> + LOOP + EXIT label1; + END LOOP; + END; +END; +/ +DELIMITER ;/ + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + LOOP + LOOP + i:= i + 1; + IF i >= 5 THEN + EXIT; + END IF; + END LOOP; + i:= i + 100; + EXIT; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + <> + LOOP + <> + LOOP + i:= i + 1; + IF i >= 5 THEN + EXIT label2; + END IF; + END LOOP; + i:= i + 100; + EXIT; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + <> + LOOP + <> + LOOP + i:= i + 1; + IF i >= 5 THEN + EXIT label1; + END IF; + END LOOP; + i:= i + 100; + EXIT; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + LOOP + i:= i + 1; + EXIT WHEN i >=5; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + <> + LOOP + <> + LOOP + i:= i + 1; + EXIT label2 WHEN i >= 5; + END LOOP; + i:= i + 100; + EXIT; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +IS + i INT := 0; +BEGIN + <> + LOOP + <> + LOOP + i:= i + 1; + EXIT label1 WHEN i >= 5; + END LOOP; + i:= i + 100; + EXIT; + END LOOP; + RETURN i; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; + + +--echo # Testing CURSOR declaration + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); +DELIMITER /; +CREATE FUNCTION f1 RETURN INT +AS + v_a INT:=10; + CURSOR c IS SELECT a FROM t1; +BEGIN + OPEN c; + FETCH c INTO v_a; + CLOSE c; + RETURN v_a; +EXCEPTION + WHEN OTHERS THEN RETURN -1; +END; +/ +DELIMITER ;/ +SELECT f1() FROM DUAL; +DROP FUNCTION f1; +DROP TABLE t1; + + +--echo # Testing RETURN in procedures + +DELIMITER /; +--error ER_SP_BADRETURN +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN + RETURN 10; +END; +/ +DELIMITER ;/ + +DELIMITER /; +--error ER_PARSE_ERROR +CREATE FUNCTION f1 (a INT) RETURN INT +AS +BEGIN + RETURN; +END; +/ +DELIMITER ;/ + +DELIMITER /; +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN + IF a < 10 THEN + BEGIN + a:= a - 1; + RETURN; + END; + END IF; + a:= a + 1; +EXCEPTION + WHEN OTHERS THEN RETURN; +END; +/ +DELIMITER ;/ +SET @v=10; +CALL p1(@v); +SELECT @v; +SET @v=9; +CALL p1(@v); +SELECT @v; +DROP PROCEDURE p1; + +DELIMITER /; +CREATE PROCEDURE p1 (a IN OUT INT) +AS +BEGIN + DROP TABLE t1_non_existent; +EXCEPTION + WHEN OTHERS THEN + BEGIN + a:= 100; + RETURN; + END; +END; +/ +DELIMITER ;/ +SET @v=10; +CALL p1(@v); +SELECT @v; +DROP PROCEDURE p1; + + +--echo # Testing WHILE loop + +DELIMITER /; +CREATE PROCEDURE p1 (a IN OUT INT) +AS + i INT:= 1; + j INT:= 3; +BEGIN + WHILE i<=j + LOOP + a:= a + i; + i:= i + 1; + END LOOP; +END; +/ +DELIMITER ;/ +SET @v=0; +CALL p1(@v); +SELECT @v; +DROP PROCEDURE p1; + +DELIMITER /; +CREATE PROCEDURE p1 (a IN OUT INT) +AS + i INT:= 1; + j INT:= 3; +BEGIN + <