Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 7ec7dfb

Browse files
committed
Use unquoted string value as column DEFAULT.
This is an undocumented SQLite feature that allows you to specify a default column value as an _unquoted_ (e.g., DEFAULT foo) or a double-quoted string value (e.g., DEFAULT "foo").
1 parent da40692 commit 7ec7dfb

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/grammar.pegjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ definition_args_loop
187187
* {@link https://www.sqlite.org/syntax/literal-value.html}
188188
*/
189189
literal_value
190-
= literal_number
191-
/ literal_string
190+
= literal_number_signed
191+
/ literal_number
192192
/ literal_blob
193193
/ literal_null
194194
/ literal_date
195+
/ literal_string
195196

196197
literal_null "Null Literal"
197198
= n:( NULL ) o
@@ -256,6 +257,21 @@ literal_blob "Blob Literal"
256257
};
257258
}
258259

260+
/**
261+
* @note
262+
* This is an undocumented SQLite feature that allows you to specify a
263+
* default column value as an _unquoted_ (e.g., DEFAULT foo) or a
264+
* double-quoted string value (e.g., DEFAULT "foo").
265+
*/
266+
literal_text
267+
= n:( name_unquoted / name_dblquoted ) {
268+
return {
269+
'type': 'literal',
270+
'variant': 'text',
271+
'value': n
272+
};
273+
}
274+
259275
number_sign "Number Sign"
260276
= s:( sym_plus / sym_minus ) { return s; }
261277

@@ -1936,14 +1952,19 @@ column_constraint_check "CHECK Column Constraint"
19361952
= constraint_check
19371953

19381954
column_constraint_default "DEFAULT Column Constraint"
1939-
= s:( DEFAULT ) o v:( expression_wrapped / literal_number_signed / literal_value )
1955+
= s:( DEFAULT ) o v:( column_default_values ) o
19401956
{
19411957
return {
19421958
'type': 'constraint',
19431959
'variant': keyNode(s),
19441960
'value': v
19451961
};
19461962
}
1963+
column_default_values
1964+
= expression_wrapped
1965+
/ literal_number_signed
1966+
/ literal_value
1967+
/ literal_text
19471968

19481969
column_constraint_collate "COLLATE Column Constraint"
19491970
= c:( column_collate )

0 commit comments

Comments
 (0)