@@ -447,6 +447,7 @@ cmd_stmt
447447 / grant_stmt
448448 / explain_stmt
449449 / transaction_stmt
450+ / load_data_stmt
450451
451452create_stmt
452453 = create_table_stmt
@@ -2091,6 +2092,69 @@ transaction_stmt
20912092 }
20922093 }
20932094
2095+ load_data_field
2096+ = k :('FIELDS' i / 'COLUMNS' i ) __ t :('TERMINATED' i __ 'BY' i __ ident_without_kw_type )? __ en :(('OPTIONALLY' i )? __ 'ENCLOSED' i __ 'BY' i __ ident_without_kw_type )? __ es :('ESCAPED' i __ 'BY' i __ ident_without_kw_type )? {
2097+ if (t) t[4 ].prefix = ' TERMINATED BY'
2098+ if (en) en[6 ].prefix = ` ${ en[0 ] && en[0 ].toUpperCase () === ' OPTIONALLY' ? ' OPTIONALLY ' : ' ' } ENCLOSED BY`
2099+ if (es) es[4 ].prefix = ' ESCAPED BY'
2100+ return {
2101+ keyword: k,
2102+ terminated: t && t[4 ],
2103+ enclosed: en && en[6 ],
2104+ escaped: es && es[4 ]
2105+ }
2106+ }
2107+
2108+ load_data_line_starting
2109+ = k :('STARTING' i / 'TERMINATED' i ) __ 'BY' i __ s :ident_without_kw_type {
2110+ s .prefix = ` ${ k .toUpperCase ()} BY`
2111+ return {
2112+ type: k .toLowerCase (),
2113+ [k .toLowerCase ()]: s
2114+ }
2115+ }
2116+ load_data_line
2117+ = k :'LINES' i __ s :load_data_line_starting ? __ t :load_data_line_starting ? {
2118+ if (s && t && s .type === t .type ) throw new Error (' LINES cannot be specified twice' )
2119+ if (s) Reflect .deleteProperty (s, ' type' )
2120+ if (t) Reflect .deleteProperty (t, ' type' )
2121+ return {
2122+ keyword: k,
2123+ ... (s || {}),
2124+ ... (t || {})
2125+ }
2126+ }
2127+
2128+ load_data_stmt
2129+ = 'LOAD' i __ 'DATA' i __ lc :('LOW_PRIORITY' i / 'CONCURRENT' i )? __ lo :('LOCAL' i )? __
2130+ 'INFILE' i __ file :ident_without_kw_type __ ri :replace_insert ? __
2131+ 'INTO' i __ 'TABLE' i __ table :table_name __
2132+ pa :insert_partition ? __
2133+ cs :(create_option_character_set_kw __ ident_without_kw_type )? __
2134+ fields :load_data_field ? __
2135+ lines :load_data_line ? __
2136+ ig :(KW_IGNORE __ literal_numeric __ ('LINES' i / 'ROWS' i ))? __
2137+ co :column_clause ? __
2138+ set :(KW_SET __ set_list )? {
2139+ return {
2140+ type: ' load_data' ,
2141+ mode: lc,
2142+ local: lo,
2143+ file: file,
2144+ replace_ignore: ri,
2145+ table: table,
2146+ partition: pa,
2147+ character_set: cs,
2148+ fields: fields,
2149+ lines: lines,
2150+ ignore: ig && {
2151+ count: ig[2 ],
2152+ suffix: ig[4 ]
2153+ },
2154+ column: co,
2155+ set: set && set[2 ]
2156+ }
2157+ }
20942158priv_type_table
20952159 = p :(KW_ALL / KW_ALTER / KW_CREATE __ 'VIEW' i / KW_CREATE / KW_DELETE / KW_DROP / 'GRANT' i __ 'OPTION' i / KW_INDEX / KW_INSERT / KW_REFERENCES / KW_SELECT / KW_SHOW __ KW_VIEW / KW_TRIGGER / KW_UPDATE ) {
20962160 return {
@@ -2814,7 +2878,7 @@ set_list
28142878 * 'col1 = (col2 > 3)'
28152879 */
28162880set_item
2817- = tbl :(ident __ DOT )? __ c :column_without_kw __ '=' __ v :additive_expr {
2881+ = tbl :(ident __ DOT )? __ c :column_without_kw __ '=' __ v :expr {
28182882 return { column: c, value: v, table: tbl && tbl[0 ] };
28192883 }
28202884 / tbl :(ident __ DOT )? __ c :column_without_kw __ '=' __ KW_VALUES __ LPAREN __ v :column_ref __ RPAREN {
@@ -3372,7 +3436,7 @@ double_quoted_ident
33723436 }
33733437
33743438single_quoted_ident
3375- = "'" chars :[^']+ "'" {
3439+ = "'" chars :[^']* "'" {
33763440 return {
33773441 type: ' single_quote_string' ,
33783442 value: chars .join (' ' )
0 commit comments