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 'get INT)' at line 1
CREATE PROCEDURE p1()
BEGIN
DECLARE get INT DEFAULT 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 'get INT DEFAULT 1;
END' at line 3
# Quoting
CREATE TABLE t1 (`get` INT);
INSERT INTO t1 (`get`) values (1);
SELECT `get` FROM t1 WHERE `get` = 1;
get
1
DROP TABLE t1;
CREATE PROCEDURE p1()
BEGIN
DECLARE `get` INT DEFAULT 1;
SELECT `get`;
END|
CALL p1();
`get`
1
DROP PROCEDURE p1;
#
# Test non-reserved keywords: CURRENT, DIAGNOSTICS, NUMBER, RETURNED_SQLSTATE
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 '' at line 1
GET CURRENT;
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 '' at line 1
GET DIAGNOSTICS;
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 '' at line 1
GET CURRENT DIAGNOSTICS;
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 '' at line 1
# Statement information syntax
GET DIAGNOSTICS @var;
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 '' at line 1
GET DIAGNOSTICS var;
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
GET DIAGNOSTICS var;
END|
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS var;
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
GET DIAGNOSTICS @var =;
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 '' at line 1
GET DIAGNOSTICS @var = INVALID;
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 'INVALID' at line 1
GET DIAGNOSTICS @var = MORE;
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 'MORE' at line 1
GET DIAGNOSTICS @var = CLASS_ORIGIN;
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 'CLASS_ORIGIN' at line 1
GET DIAGNOSTICS @var = INVALID,;
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 'INVALID,' at line 1
GET DIAGNOSTICS @var1 = NUMBER, @var2;
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 '' at line 1
GET DIAGNOSTICS @var1 = NUMBER, @var2 = INVALID;
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 'INVALID' at line 1
GET DIAGNOSTICS @@var1 = NUMBER;
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 '@var1 = NUMBER' at line 1
GET DIAGNOSTICS @var1 = NUMBER, @@var2 = NUMBER;
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 '@var2 = NUMBER' at line 1
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS var = INVALID;
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 'INVALID;
END' at line 4
CREATE PROCEDURE p1()
BEGIN
DECLARE var CONDITION FOR SQLSTATE '12345';
GET DIAGNOSTICS var = NUMBER;
END|
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS var = NUMBER, var1 = ROW_COUNT;
END|
ERROR 42000: Undeclared variable: var1
GET DIAGNOSTICS @var = NUMBER;
GET DIAGNOSTICS @var = ROW_COUNT;
GET DIAGNOSTICS @var1 = NUMBER, @var2 = ROW_COUNT;
GET DIAGNOSTICS @var1 = ROW_COUNT, @var2 = NUMBER;
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
DECLARE var1 INT;
DECLARE var2 INT;
GET DIAGNOSTICS var = NUMBER;
GET DIAGNOSTICS var = ROW_COUNT;
GET DIAGNOSTICS var1 = NUMBER, var2 = ROW_COUNT;
GET DIAGNOSTICS var1 = ROW_COUNT, var2 = NUMBER;
END|
DROP PROCEDURE p1;
# Condition information syntax
GET DIAGNOSTICS CONDITION;
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 '' at line 1
GET DIAGNOSTICS CONDITION 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 '' at line 1
GET DIAGNOSTICS CONDITION 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 '' at line 1
GET DIAGNOSTICS CONDITION 1 @var;
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 '' at line 1
GET DIAGNOSTICS CONDITION 1 var;
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
GET DIAGNOSTICS CONDITION 1 var;
END|
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS CONDITION 1 var;
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
GET DIAGNOSTICS CONDITION 1 @var =;
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 '' at line 1
GET DIAGNOSTICS CONDITION 1 @var = INVALID;
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 'INVALID' at line 1
GET DIAGNOSTICS CONDITION 1 @var = NUMBER;
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 'NUMBER' at line 1
GET DIAGNOSTICS CONDITION 1 @var = INVALID,;
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 'INVALID,' at line 1
GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2;
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 '' at line 1
GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2 = INVALID;
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 'INVALID' at line 1
GET DIAGNOSTICS CONDITION 1 @@var1 = CLASS_ORIGIN;
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 '@var1 = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @@var2 = CLASS_ORIGIN;
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 '@var2 = CLASS_ORIGIN' at line 1
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS CONDITION 1 var = INVALID;
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 'INVALID;
END' at line 4
CREATE PROCEDURE p1()
BEGIN
DECLARE var CONDITION FOR SQLSTATE '12345';
GET DIAGNOSTICS CONDITION 1 var = NUMBER;
END|
ERROR 42000: Undeclared variable: var
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
GET DIAGNOSTICS CONDITION 1 var = CLASS_ORIGIN, var1 = SUBCLASS_ORIGIN;
END|
ERROR 42000: Undeclared variable: var1
GET DIAGNOSTICS CONDITION 1 @var = CLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 @var = SUBCLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 @var1 = CLASS_ORIGIN, @var2 = SUBCLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 @var1 = SUBCLASS_ORIGIN, @var2 = CLASS_ORIGIN;
CREATE PROCEDURE p1()
BEGIN
DECLARE var INT;
DECLARE var1 INT;
DECLARE var2 INT;
GET DIAGNOSTICS CONDITION 1 var = CLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 var = SUBCLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 var1 = CLASS_ORIGIN, var2 = SUBCLASS_ORIGIN;
GET DIAGNOSTICS CONDITION 1 var1 = SUBCLASS_ORIGIN, var2 = CLASS_ORIGIN;
END|
DROP PROCEDURE p1;
# Condition number expression
GET DIAGNOSTICS CONDITION -1 @var = CLASS_ORIGIN;
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 @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION 1+1 @var = CLASS_ORIGIN;
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 @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION ? @var = CLASS_ORIGIN;
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 '? @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION (1) @var = CLASS_ORIGIN;
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) @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION p1() @var = CLASS_ORIGIN;
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 '() @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION ABS(2) @var = CLASS_ORIGIN;
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 '(2) @var = CLASS_ORIGIN' at line 1
GET DIAGNOSTICS CONDITION 1.1 @var = CLASS_ORIGIN;
GET DIAGNOSTICS CONDITION "1" @var = CLASS_ORIGIN;
SELECT COUNT(max_questions) INTO @var FROM mysql.user;
GET DIAGNOSTICS CONDITION 9999 @var = CLASS_ORIGIN;
Warnings:
Error 1758 Invalid condition number
GET DIAGNOSTICS CONDITION NULL @var = CLASS_ORIGIN;
Warnings:
Error 1758 Invalid condition number
Error 1758 Invalid condition number
GET DIAGNOSTICS CONDITION a @var = CLASS_ORIGIN;
Warnings:
Error 1758 Invalid condition number
Error 1758 Invalid condition number
Error 1054 Unknown column 'a' in 'field list'
SELECT COUNT(max_questions) INTO @var FROM mysql.user;
SET @cond = 1;
GET DIAGNOSTICS CONDITION @cond @var1 = CLASS_ORIGIN;
Warnings:
Error 1758 Invalid condition number
SET @cond = "invalid";
GET DIAGNOSTICS CONDITION @cond @var1 = CLASS_ORIGIN;
Warnings:
Error 1758 Invalid condition number
Error 1758 Invalid condition number
SELECT COUNT(max_questions) INTO @var FROM mysql.user;
CREATE PROCEDURE p1()
BEGIN
DECLARE cond INT DEFAULT 1;
DECLARE var INT;
GET DIAGNOSTICS CONDITION cond var = CLASS_ORIGIN;
END|
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE cond TEXT;
DECLARE var INT;
GET DIAGNOSTICS CONDITION cond var = CLASS_ORIGIN;
END|
CALL p1();
DROP PROCEDURE p1;
#
# Test GET DIAGNOSTICS runtime
#
# GET DIAGNOSTICS cannot be the object of a PREPARE statement.
PREPARE stmt FROM "GET DIAGNOSTICS CONDITION 1 @var = CLASS_ORIGIN";
ERROR HY000: This command is not supported in the prepared statement protocol yet
PREPARE stmt FROM "GET DIAGNOSTICS @var = NUMBER";
ERROR HY000: This command is not supported in the prepared statement protocol yet
# GET DIAGNOSTICS does not clear the diagnostics area.
SELECT CAST(-19999999999999999999 AS SIGNED);
CAST(-19999999999999999999 AS SIGNED)
-9223372036854775808
Warnings:
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
GET DIAGNOSTICS @var = NUMBER;
SHOW WARNINGS;
Level Code Message
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
#
# If GET DIAGNOSTICS itself causes an error, an error message is appended.
#
SELECT CAST(-19999999999999999999 AS SIGNED);
CAST(-19999999999999999999 AS SIGNED)
-9223372036854775808
Warnings:
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
GET DIAGNOSTICS CONDITION 99999 @var = CLASS_ORIGIN;
Warnings:
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
Error 1758 Invalid condition number
SHOW WARNINGS;
Level Code Message
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
Error 1758 Invalid condition number
# Statement information runtime
SELECT CAST(-19999999999999999999 AS SIGNED),
CAST(-19999999999999999999 AS SIGNED);
CAST(-19999999999999999999 AS SIGNED) CAST(-19999999999999999999 AS SIGNED)
-9223372036854775808 -9223372036854775808
Warnings:
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
GET DIAGNOSTICS @var = NUMBER;
SELECT @var;
@var
2
SELECT COUNT(max_questions) INTO @var FROM mysql.user;
GET DIAGNOSTICS @var = NUMBER;
SELECT @var;
@var
0
SELECT 1;
1
1
GET DIAGNOSTICS @var = ROW_COUNT;
SELECT @var;
@var
-1
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
GET DIAGNOSTICS @var = ROW_COUNT;
SELECT @var;
@var
3
DROP TABLE t1;
CREATE PROCEDURE p1()
BEGIN
DECLARE number INT;
DECLARE row_count INT;
SELECT CAST(-19999999999999999999 AS SIGNED),
CAST(-19999999999999999999 AS SIGNED);
GET DIAGNOSTICS number = NUMBER;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
GET DIAGNOSTICS row_count = ROW_COUNT;
DROP TABLE t1;
SELECT number, row_count;
END|
CALL p1();
CAST(-19999999999999999999 AS SIGNED) CAST(-19999999999999999999 AS SIGNED)
-9223372036854775808 -9223372036854775808
number row_count
2 3
DROP PROCEDURE p1;
# Condition information runtime
SELECT CAST(-19999999999999999999 AS SIGNED);
CAST(-19999999999999999999 AS SIGNED)
-9223372036854775808
Warnings:
Warning 1916 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
GET DIAGNOSTICS CONDITION 1
@class_origin = CLASS_ORIGIN,
@subclass_origin = SUBCLASS_ORIGIN,
@constraint_catalog = CONSTRAINT_CATALOG,
@constraint_schema = CONSTRAINT_SCHEMA,
@constraint_name = CONSTRAINT_NAME,
@catalog_name = CATALOG_NAME,
@schema_name = SCHEMA_NAME,
@table_name = TABLE_NAME,
@column_name = COLUMN_NAME,
@cursor_name = CURSOR_NAME,
@message_text = MESSAGE_TEXT,
@mysql_errno = MYSQL_ERRNO,
@returned_sqlstate = RETURNED_SQLSTATE;
SELECT
@class_origin,
@subclass_origin,
@constraint_catalog,
@constraint_schema,
@constraint_name,
@catalog_name,
@schema_name,
@table_name,
@column_name,
@cursor_name,
@message_text,
@mysql_errno,
@returned_sqlstate;
@class_origin
@subclass_origin
@constraint_catalog
@constraint_schema
@constraint_name
@catalog_name
@schema_name
@table_name
@column_name
@cursor_name
@message_text Got overflow when converting '-19999999999999999999' to INT. Value truncated.
@mysql_errno 1916
@returned_sqlstate 22003
CREATE PROCEDURE p1()
BEGIN
DECLARE class_origin TEXT DEFAULT "a";
DECLARE subclass_origin TEXT DEFAULT "a";
DECLARE constraint_catalog TEXT DEFAULT "a";
DECLARE constraint_schema TEXT DEFAULT "a";
DECLARE constraint_name TEXT DEFAULT "a";
DECLARE catalog_name TEXT DEFAULT "a";
DECLARE schema_name TEXT DEFAULT "a";
DECLARE table_name TEXT DEFAULT "a";
DECLARE column_name TEXT DEFAULT "a";
DECLARE cursor_name TEXT DEFAULT "a";
DECLARE message_text TEXT DEFAULT "a";
DECLARE mysql_errno INT DEFAULT 1;
DECLARE returned_sqlstate TEXT DEFAULT "a";
SELECT CAST(-19999999999999999999 AS SIGNED);
GET DIAGNOSTICS CONDITION 1
class_origin = CLASS_ORIGIN,
subclass_origin = SUBCLASS_ORIGIN,
constraint_catalog = CONSTRAINT_CATALOG,
constraint_schema = CONSTRAINT_SCHEMA,
constraint_name = CONSTRAINT_NAME,
catalog_name = CATALOG_NAME,
schema_name = SCHEMA_NAME,
table_name = TABLE_NAME,
column_name = COLUMN_NAME,
cursor_name = CURSOR_NAME,
message_text = MESSAGE_TEXT,
mysql_errno = MYSQL_ERRNO,
returned_sqlstate = RETURNED_SQLSTATE;
SELECT
class_origin,
subclass_origin,
constraint_catalog,
constraint_schema,
constraint_name,
catalog_name,
schema_name,
table_name,
column_name,
cursor_name,
message_text,
mysql_errno,
returned_sqlstate;
END|
CALL p1();
CAST(-19999999999999999999 AS SIGNED) -9223372036854775808
class_origin
subclass_origin
constraint_catalog
constraint_schema
constraint_name
catalog_name
schema_name
table_name
column_name
cursor_name
message_text Got overflow when converting '-19999999999999999999' to INT. Value truncated.
mysql_errno 1916
returned_sqlstate 22003
Warnings:
Level Warning
Code 1916
Message Got overflow when converting '-19999999999999999999' to INT. Value truncated.
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE errno1 INT;
DECLARE errno2 INT;
DECLARE msg1 TEXT;
DECLARE msg2 TEXT;
SELECT CAST(-19999999999999999999 AS SIGNED);
GET DIAGNOSTICS CONDITION 99999 msg1 = MESSAGE_TEXT;
GET DIAGNOSTICS CONDITION 1 errno1 = MYSQL_ERRNO, msg1 = MESSAGE_TEXT;
GET DIAGNOSTICS CONDITION 2 errno2 = MYSQL_ERRNO, msg2 = MESSAGE_TEXT;
SELECT errno1, msg1, errno2, msg2;
END|
CALL p1();
CAST(-19999999999999999999 AS SIGNED) -9223372036854775808
errno1 1916
msg1 Got overflow when converting '-19999999999999999999' to INT. Value truncated.
errno2 1758
msg2 Invalid condition number
Warnings:
Level Warning
Code 1916
Message Got overflow when converting '-19999999999999999999' to INT. Value truncated.
Level Error
Code 1758
Message Invalid condition number
DROP PROCEDURE p1;
# Interaction with SIGNAL
CREATE PROCEDURE p1()
BEGIN
DECLARE errno INT DEFAULT 0;
DECLARE msg TEXT DEFAULT "foo";
DECLARE cond CONDITION FOR SQLSTATE "01234";
DECLARE CONTINUE HANDLER for 1012
BEGIN
GET DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO, msg = MESSAGE_TEXT;
END;
SIGNAL cond SET MESSAGE_TEXT = "Signal message", MYSQL_ERRNO = 1012;
SELECT errno, msg;
END|
CALL p1();
errno 1012
msg Signal message
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
SIGNAL SQLSTATE '77777' SET MYSQL_ERRNO = 1000, MESSAGE_TEXT='ÁÂÃÅÄ';