Class SqlParser
Some MySQL command-line directives (e.g. 'DELIMITER') are processed whilst parsing.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
consumeStatements
(InputStream is, boolean includeComments, SqlParser.Consumer<String> consumer) convert a text file of SQL statements into a List of individual statements.void
consumeStatements
(Reader is, boolean includeComments, SqlParser.Consumer<String> consumer) parseStatements
(InputStream is, boolean includeComments) Convert an InputStream of SQL statements into a List of individual statements.parseStatements
(Reader r, boolean includeComments) Convert an InputStream of SQL statements into a List of individual statements.
-
Constructor Details
-
SqlParser
public SqlParser()
-
-
Method Details
-
parseStatements
public List<String> parseStatements(InputStream is, boolean includeComments) throws IOException, ParseException Convert an InputStream of SQL statements into a List of individual statements. Statements are delimited by ";" strings that occur outside of strings or comments. The delimiter string is not included in the returned list of statements.The delimiter string may be changed using the 'delimiter str' command. This command may end with a newline instead of a delimiter.
Comments may also be returned in the result.
Comments are defined by '-- to-end-of-line' or '/* within slash-star star-slash **/' syntax. Comments that are created with '--' and that occur within a statement are returned before that statement has finished parsing.
NB: Does not handle escape sequences found within double or single quotes (i.e. escape sequences are handled by the underlying database, not by this Parser)
- Parameters:
is
- inputStream to parseincludeComments
- include comment strings in result- Throws:
IOException
ParseException
- unclosed /*-style comment or single/double-quoted string
-
parseStatements
public List<String> parseStatements(Reader r, boolean includeComments) throws IOException, ParseException Convert an InputStream of SQL statements into a List of individual statements. Statements are delimited by ";" strings that occur outside of strings or comments. The delimiter string is not included in the returned list of statements.The delimiter string may be changed using the 'delimiter str' command. This command may end with a newline instead of a delimiter.
Comments may also be returned in the result.
Comments are defined by '-- to-end-of-line' or '/* within slash-star star-slash **/' syntax. Comments that are created with '--' and that occur within a statement are returned before that statement has finished parsing.
NB: Does not handle escape sequences found within double or single quotes (i.e. escape sequences are handled by the underlying database, not by this Parser)
- Parameters:
includeComments
- include comment strings in resultreader
- Reader to parse- Throws:
IOException
ParseException
- unclosed /*-style comment or single/double-quoted string
-
consumeStatements
public void consumeStatements(InputStream is, boolean includeComments, SqlParser.Consumer<String> consumer) throws IOException, ParseException convert a text file of SQL statements into a List of individual statements. Comments may also be returned in the result.NB: Does not handle escape sequences found within double or single quotes
- Parameters:
includeComments
- include comment strings in result- Throws:
IOException
ParseException
- unclosed /*-style comment or single/double-quoted string
-
consumeStatements
public void consumeStatements(Reader is, boolean includeComments, SqlParser.Consumer<String> consumer) throws IOException, ParseException - Throws:
IOException
ParseException
-