MAN page from OpenSuSE perl-SQL-SplitStatement-1.00020-lp150.1.2.noarch.rpm
Section: User Contributed Perl Documentation (1)
sql-split - SQL splitting command line utility
sql-split [ OPTIONS ] [ FILE(S) ] sql-split --man
This program tries to split any SQL
code (even containing non-standard and/orprocedural extensions, at least the ones from the most popular DBMSs) into theatomic statements it is composed of.
The given FILES are read and split one by one, and the resulting statements areprinted to the standard output, separated by a customizable string (see below).Each given file must contain only full SQL statements, that is, no single atomicstatement can span multiple files.
If no file is given, or if one of the file names is a "-" (dash), the SQL codeis read from STDIN, so that this program can be used as a filter or eveninteractively.
Consider however that this is by no means a validating parser, so that errors inSQL code will not be detected (and can even lead to incorrect splitting).
It causes the trailing terminator tokens to be kept in the returned atomicstatements (by default they are discarded instead).
The strings currently recognized as terminators (depending on the context) are:
- ";" (the semicolon character);
- any string defined by the MySQL "DELIMITER" command;
- an ";" followed by an "/" (forward-slash character) on its ownline;
- an ";" followed by an "." (dot character) on its own line,followed by an "/" on its own line;
- an "/" on its own line regardless of the preceding characters(only if the "slash_terminates" option, explained below, is set).
The multi-line terminators above are always treated as a single token, that isthey are discarded (or returned) as a whole (regardless of the"--no-slash-terminates" option value).
-S, --spaces, --extra-spaces
It causes the space characters around the statements, if any, to be kept in thereturned atomic statements (by default they are trimmed instead).
It causes the comments, if any, to be kept in the returned atomic statements(by default any comment is discarded instead).
Both SQL and multi-line C-style comments are recognized.
-E, --empty, --empty-statements
It causes the empty statements to be returned (by default, they are discardedinstead).
A statement is considered empty when it contains no characters other than theterminator and space characters. A statement composed solely of comments is notrecognized as empty and it is therefore returned, if the "--comments" option isused. Note instead that an empty statement is recognized as such regardless ofthe use of the "--terminators" and "--extra-spaces" options.
By default a "/"
) on its own line, even without a precedingsemicolon, is admitted as a candidate terminator.
When this option is used instead, a forward-slash on its own line is treated asa statement terminator only if preceded by a semicolon or by a dot and asemicolon.
If you are dealing with Oracle's SQL, you should not use this option, since aslash (alone, without a preceding semicolon) is often used as a terminator, asit is permitted by SQL*Plus (on non-block statements).
With SQL dialects other than Oracle, there is the (theoretical) possibility thata slash on its own line could pass the additional checks and be considered aterminator (while it shouldn't). This chance should be really tiny (it has neverbeen observed in real world code indeed). Though negligible, this option willanyway rule out that risk.
-s, --oss, --output-statement-separator string
The string which will be printed between every pair of returned atomicstatements. By default, it is a "--"
) on its own line.
To use special characters (such as newlines) when passing such string, pleaseconsult your shell docs (for example, in Bash the above mentioned defaultseparator could be defined as "$'\n--\n'").
Note that the last returned statement (for each processed file) will not befollowed by such separator.
-f, --ofs, --output-file-separator string
The string which will be printed between the groups of statements coming fromdifferent files. By default it is the "-- >>>*<<< --"
string on its ownline.
Similarly to the statement separator, the file separator will not be printedafter the last file.
-e, --error, --on-error value
It controls the program behavior in case one of the given files is notaccessible.
It can take the following values:
- "stop" or 0, which causes the program to die at the first file whichcan not be opened, but it prints all the statements split that far (this is thedefault);
- "continue" or 1, which causes the program, when it encounters a fileerror, to just emit a warning (on STDERR) and continue with the next file;
- "no-output" or 2, which, just like "stop", causes the program todie at the first file error, but in this case it does not print any statement,not even those coming from the previous (already read) files; in other words,the statements are printed out only if (and after) all of the given files havebeen successfully read.
The above listed string values are case-insensitive.
-h, -?, --help
It prints a brief help message and exits.
It shows the full man page.
It prints the program version and exits.
sql-split aims to cover the widest possible range of DBMSs, SQL
dialects andextensions (even proprietary), in a (nearly) fully transparent way for the user.
Currently it has been tested mainly on SQLite, PostgreSQL, MySQL and Oracle.
Procedural code is by far the most complex to handle.
Currently any block of code which start with "FUNCTION", "PROCEDURE","DECLARE", "CREATE" or "CALL" is correctly recognized, as well asanonymous "BEGIN ... END" blocks, dollar quoted blocks and blocksdelimited by a "DELIMITER"-defined custom terminator, therefore a wide rangeof procedural extensions should be handled correctly. However, only PL/SQL,PL/PgSQL and MySQL code has been tested so far.
None currently known (other than the lack of tests on SQL
dialects differentfrom the ones described above).
To be split correctly, the given input must, in general, be syntactically validSQL.
For example, an unbalanced "BEGIN"
or a misspelled keyword could, undercertain circumstances, confuse the parser and make it trip over the nextstatement terminator, thus returning non-split statements. This should notbe a problem though, as the original (invalid) SQL
code would have been unusableanyway (remember that this is NOT
a validating parser!)
- SQL::SplitStatement (perldoc SQL::SplitStatement)
Copyright 2011 Emanuele Zeppieri
This program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.
This program comes with NO WARRANTIES
of any kind. It not only may cause loss ofdata and hardware damaging, but it may also cause several bad diseases to nearbypeople, including, but not limited to, diarrhoea, gonorrhea and dysmenorrhea.Don't say you haven't been warned.
- -T, --terminators
- -S, --spaces, --extra-spaces
- -C, --comments
- -E, --empty, --empty-statements
- --no-slash, --no-slash-terminates
- -s, --oss, --output-statement-separator string
- -f, --ofs, --output-file-separator string
- -e, --error, --on-error value
- -h, -?, --help
- SUPPORTED DBMSs
- Procedural Extensions
- SEE ALSO
- NO WARRANTY
This document was created byman2html,using the manual pages.