Skip to content

Commit aaff1d2

Browse files
authored
[SQL] Fix MySql default column values (#4411)
This commit fixes MySQL default column values, which weren't being scoped correctly when preceded by `NULL` in a column definition.
1 parent b35772b commit aaff1d2

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

SQL/MySQL.sublime-syntax

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ variables:
7878
| second(?: _microsecond )? | quarter | month | week )
7979
8080
builtin_constants: |-
81-
(?xi: all | default | maxvalue
81+
(?xi: all | maxvalue
8282
# index algorithm/lock values
8383
| inplace | copy | nocopy | instant | exclusive | shared
8484
| system\s+versioning )

SQL/SQL (basic).sublime-syntax

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ contexts:
816816
- match: \b(?i:unique)\b
817817
scope: storage.modifier.sql
818818
push: maybe-column-name-list
819+
- include: logical-operators
820+
- include: constants
819821
- include: column-reference-definitions
820822

821823
column-reference-definitions:

SQL/tests/syntax/syntax_test_mysql.sql

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@
8787
-- ^^^^^ constant.language.boolean.false.sql
8888
-- ^ - constant
8989

90-
all default maxvalue
90+
all maxvalue
9191
-- ^ - constant
9292
-- ^^^ constant.language.sql
9393
-- ^ - constant
94-
-- ^^^^^^^ constant.language.sql
95-
-- ^ - constant
96-
-- ^^^^^^^^ constant.language.sql
97-
-- ^ - constant
94+
-- ^^^^^^^^ constant.language.sql
95+
-- ^ - constant
9896

9997
inplace copy nocopy instant exclusive shared
10098
-- ^ - constant
@@ -1382,6 +1380,64 @@ create table fancy_table (
13821380
-- ^^^^^^^^^^ meta.column-name
13831381
);
13841382

1383+
1384+
ALTER TABLE abc
1385+
ADD COLUMN column1 VARCHAR(10) NOT NULL DEFAULT 'Foo' AFTER bar,
1386+
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql
1387+
-- ^^^ keyword.other.ddl.sql
1388+
-- ^^^^^^ keyword.other.ddl.sql
1389+
-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql
1390+
-- ^^^^^^^^^^^ storage.type.sql
1391+
-- ^^^^ meta.parens.sql
1392+
-- ^ punctuation.definition.parens.begin.sql
1393+
-- ^^ meta.number.integer.decimal.sql constant.numeric.value.sql
1394+
-- ^ punctuation.definition.parens.end.sql
1395+
-- ^^^ keyword.operator.logical.sql
1396+
-- ^^^^ constant.language.null.sql
1397+
-- ^^^^^^^ storage.modifier.sql
1398+
-- ^^^^^ meta.string.sql string.quoted.single.sql
1399+
-- ^ punctuation.definition.string.begin.sql
1400+
-- ^ punctuation.definition.string.end.sql
1401+
-- ^^^^^ keyword.other.position.sql
1402+
-- ^^^ meta.column-name.sql
1403+
-- ^ punctuation.separator.sequence.sql
1404+
ADD COLUMN column2 DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) AFTER column1,
1405+
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql
1406+
-- ^^^ keyword.other.ddl.sql
1407+
-- ^^^^^^ keyword.other.ddl.sql
1408+
-- ^^^^^^^ meta.column-name.sql variable.other.member.declaration.sql
1409+
-- ^^^^^^^^^^^ storage.type.sql
1410+
-- ^^^ meta.parens.sql
1411+
-- ^ punctuation.definition.parens.begin.sql
1412+
-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql
1413+
-- ^ punctuation.definition.parens.end.sql
1414+
-- ^^^ keyword.operator.logical.sql
1415+
-- ^^^^ constant.language.null.sql
1416+
-- ^^^^^^^ storage.modifier.sql
1417+
-- ^^^^^^^^^^^^^^^^^^^^ meta.function-call.sql
1418+
-- ^^^^^^^^^^^^^^^^^ support.function.scalar.sql
1419+
-- ^^^ meta.group.sql
1420+
-- ^ punctuation.section.arguments.begin.sql
1421+
-- ^ meta.number.integer.decimal.sql constant.numeric.value.sql
1422+
-- ^ punctuation.section.arguments.end.sql
1423+
-- ^^^^^ keyword.other.position.sql
1424+
-- ^^^^^^^ meta.column-name.sql
1425+
-- ^ punctuation.separator.sequence.sql
1426+
ADD COLUMN column3 DATETIME(6) NULL AFTER column2,
1427+
ADD INDEX idx_abc_foo (column1, column2);
1428+
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.statement.alter.sql
1429+
-- ^^^ keyword.other.ddl.sql
1430+
-- ^^^^^ keyword.other.ddl.sql
1431+
-- ^^^^^^^^^^^ meta.index-name.sql
1432+
-- ^^^^^^^^^^^^^^^^^^ meta.group.table-columns.sql
1433+
-- ^ punctuation.section.group.begin.sql
1434+
-- ^^^^^^^ meta.column-name.sql
1435+
-- ^ punctuation.separator.sequence.sql
1436+
-- ^^^^^^^ meta.column-name.sql
1437+
-- ^ punctuation.section.group.end.sql
1438+
-- ^ punctuation.terminator.statement.sql
1439+
1440+
13851441
CREATE TABLE foo LIKE bar;
13861442
-- <- meta.statement.create.sql keyword.other.ddl.sql
13871443
-- ^^^^ meta.statement.create.sql - meta.table

0 commit comments

Comments
 (0)