HHH-14152 Preserve end-of-line chars in MultiLineImportExtractor

This commit is contained in:
Nathan Xu 2020-08-18 11:26:32 -04:00 committed by Sanne Grinovero
parent b49c333198
commit 4716262645
3 changed files with 23 additions and 23 deletions

View File

@ -56,7 +56,7 @@ script
;
statement
: { statementStarted(); } (statementPart)* DELIMITER { statementEnded(); }
: { statementStarted(); } (statementPart)* DELIMITER (WS_CHAR)* { statementEnded(); }
;
statementPart
@ -71,8 +71,11 @@ quotedString
;
nonSkippedChar
: c:CHAR {
out( c );
: w:WS_CHAR {
out( w );
}
| o:OTHER_CHAR {
out( o );
}
;
@ -105,18 +108,13 @@ QUOTED_TEXT
protected
ESCqs : '\'' '\'' ;
CHAR
: ( ' ' | '\t' ) => ( ' ' | '\t' )
| ~( ';' | '\n' | '\r' )
WS_CHAR
: ' '
| '\t'
| ( "\r\n" | '\r' | '\n' ) {newline();}
;
NEWLINE
: ( '\r' | '\n' | '\r''\n' ) {
newline();
// skip the entire match from the lexer stream
$setType( Token.SKIP );
}
;
OTHER_CHAR : ~( ';' | ' ' | '\t' | '\n' | '\r' );
LINE_COMMENT
// match `//` or `--` followed by anything other than \n or \r until NEWLINE

View File

@ -44,7 +44,7 @@ public class MultiLineImportExtractorTest {
assertThat( commands[1], is( "INSERT INTO test_data VALUES (1, 'sample')" ) );
assertThat( commands[2], is( "DELETE FROM test_data" ) );
assertThat( commands[2], is( "DELETE\n FROM test_data" ) );
assertThat( commands[3], startsWith( "INSERT INTO test_data VALUES (2," ) );
assertThat( commands[3], containsString( "-- line 2" ) );
@ -52,7 +52,7 @@ public class MultiLineImportExtractorTest {
assertThat( commands[4], startsWith( "INSERT INTO test_data VALUES (3" ) );
assertThat( commands[4], not( containsString( "third record" ) ) );
assertThat( commands[5], containsString( "INSERT INTO test_data (id, text)" ) );
assertThat( commands[5], startsWith( "INSERT INTO test_data\nVALUES\n" ) );
}
}
}

View File

@ -23,12 +23,14 @@ INSERT INTO test_data VALUES (2, 'Multi-line comment line 1
-- INSERT INTO test_data VALUES (1, NULL);
INSERT INTO test_data VALUES (3 /* 'third record' */, NULL /* value */); -- with NULL value
INSERT INTO test_data (id, text)
VALUES
(
4 -- another record
, NULL
);
INSERT INTO test_data
VALUES
(
4 -- another record
, NULL
);
-- comment;
-- comment;
-- comment;
-- comment;