Skip to content

Commit c5520a3

Browse files
author
Alexander Barkov
committed
MDEV-12390 Wrong error line numbers reported with sql_mode=IGNORE_SPACE
1 parent 3f7455c commit c5520a3

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

mysql-test/r/sql_mode.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,24 @@ a b
759759
1 NULL
760760
1 NULL
761761
DROP TABLE t1;
762+
#
763+
# MDEV-12390 Wrong error line numbers reported with sql_mode=IGNORE_SPACE
764+
#
765+
SET sql_mode=IGNORE_SPACE;
766+
CREATE PROCEDURE p1()
767+
BEGIN
768+
SELECT 1+1;
769+
syntax error;
770+
END;
771+
$$
772+
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 'error;
773+
END' at line 4
774+
SET sql_mode=DEFAULT;
775+
CREATE PROCEDURE p1()
776+
BEGIN
777+
SELECT 1+1;
778+
syntax error;
779+
END;
780+
$$
781+
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 'error;
782+
END' at line 4

mysql-test/t/sql_mode.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,30 @@ ALTER TABLE t1 ADD b INT;
527527
EXECUTE stmt;
528528
SELECT * FROM t1;
529529
DROP TABLE t1;
530+
531+
--echo #
532+
--echo # MDEV-12390 Wrong error line numbers reported with sql_mode=IGNORE_SPACE
533+
--echo #
534+
535+
SET sql_mode=IGNORE_SPACE;
536+
DELIMITER $$;
537+
--error ER_PARSE_ERROR
538+
CREATE PROCEDURE p1()
539+
BEGIN
540+
SELECT 1+1;
541+
syntax error;
542+
END;
543+
$$
544+
DELIMITER ;$$
545+
546+
547+
SET sql_mode=DEFAULT;
548+
DELIMITER $$;
549+
--error ER_PARSE_ERROR
550+
CREATE PROCEDURE p1()
551+
BEGIN
552+
SELECT 1+1;
553+
syntax error;
554+
END;
555+
$$
556+
DELIMITER ;$$

sql/sql_lex.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,10 @@ static int lex_one_token(YYSTYPE *yylval, THD *thd)
14481448
below by checking start != lex->ptr.
14491449
*/
14501450
for (; state_map[(uchar) c] == MY_LEX_SKIP ; c= lip->yyGet())
1451-
;
1451+
{
1452+
if (c == '\n')
1453+
lip->yylineno++;
1454+
}
14521455
}
14531456
if (start == lip->get_ptr() && c == '.' &&
14541457
ident_map[(uchar) lip->yyPeek()])

0 commit comments

Comments
 (0)