1SQL-SPLIT(1)          User Contributed Perl Documentation         SQL-SPLIT(1)
2
3
4

NAME

6       sql-split - SQL splitting command line utility
7

SYNOPSIS

9           sql-split [ OPTIONS ] [ FILE(S) ]
10           sql-split --man
11

DESCRIPTION

13       This program tries to split any SQL code (even containing non-standard
14       and/or procedural extensions, at least the ones from the most popular
15       DBMSs) into the atomic statements it is composed of.
16
17       The given FILES are read and split one by one, and the resulting
18       statements are printed to the standard output, separated by a
19       customizable string (see below).  Each given file must contain only
20       full SQL statements, that is, no single atomic statement can span
21       multiple files.
22
23       If no file is given, or if one of the file names is a "-" (dash), the
24       SQL code is read from STDIN, so that this program can be used as a
25       filter or even interactively.
26
27       Consider however that this is by no means a validating parser, so that
28       errors in SQL code will not be detected (and can even lead to incorrect
29       splitting).
30

OPTIONS

32   -t, --terminators
33       It causes the trailing terminator tokens to be kept in the returned
34       atomic statements (by default they are discarded instead).
35
36       The strings currently recognized as terminators (depending on the
37       context) are:
38
39       •   ";" (the semicolon character);
40
41       •   any string defined by the MySQL "DELIMITER" command;
42
43       •   an ";" followed by an "/" (forward-slash character) on its own
44           line;
45
46       •   an ";" followed by an "." (dot character) on its own line, followed
47           by an "/" on its own line;
48
49       •   an "/" on its own line regardless of the preceding characters (only
50           if the "slash_terminates" option, explained below, is set).
51
52       The multi-line terminators above are always treated as a single token,
53       that is they are discarded (or returned) as a whole (regardless of the
54       "--no-slash-terminates" option value).
55
56   -x, --spaces, --extra-spaces
57       It causes the space characters around the statements, if any, to be
58       kept in the returned atomic statements (by default they are trimmed
59       instead). A mnemonic for the short version is "X-tra spaces".
60
61   -c, --comments
62       It causes the comments, if any, to be kept in the returned atomic
63       statements (by default any comment is discarded instead).
64
65       Both SQL and multi-line C-style comments are recognized.
66
67   -m, --empty, --empty-statements
68       It causes the empty statements to be returned (by default, they are
69       discarded instead).
70
71       A statement is considered empty when it contains no characters other
72       than the terminator and space characters. A statement composed solely
73       of comments is not recognized as empty and it is therefore returned, if
74       the "--comments" option is used. Note instead that an empty statement
75       is recognized as such regardless of the use of the "--terminators" and
76       "--extra-spaces" options.
77
78       A mnemonic for this option is keep "M-ty" statements.
79
80   --no-slash, --no-slash-terminates
81       By default a "/" (forward-slash) on its own line, even without a
82       preceding semicolon, is admitted as a candidate terminator.
83
84       When this option is used instead, a forward-slash on its own line is
85       treated as a statement terminator only if preceded by a semicolon or by
86       a dot and a semicolon.
87
88       If you are dealing with Oracle's SQL, you should not use this option,
89       since a slash (alone, without a preceding semicolon) is often used as a
90       terminator, as it is permitted by SQL*Plus (on non-block statements).
91
92       With SQL dialects other than Oracle, there is the (theoretical)
93       possibility that a slash on its own line could pass the additional
94       checks and be considered a terminator (while it shouldn't). This chance
95       should be really tiny (it has never been observed in real world code
96       indeed). Though negligible, this option will anyway rule out that risk.
97
98   -s, --oss, --output-statement-separator string
99       The string which will be printed between every pair of returned atomic
100       statements. By default, it is a "--" (double dash) on its own line.
101
102       To use special characters (such as newlines) when passing such string,
103       please consult your shell docs (for example, in Bash the above
104       mentioned default separator could be defined as "$'\n--\n'").
105
106       Note that the last returned statement (for each processed file) will
107       not be followed by such separator.
108
109   -f, --ofs, --output-file-separator string
110       The string which will be printed between the groups of statements
111       coming from different files. By default it is the "-- >>>*<<< --"
112       string on its own line.
113
114       Similarly to the statement separator, the file separator will not be
115       printed after the last file.
116
117   -e, --error, --on-error value
118       It controls the program behavior in case one of the given files is not
119       accessible.
120
121       It can take the following values:
122
123       •   "stop" or 0, which causes the program to die at the first file
124           which can not be opened, but it prints all the statements split
125           that far (this is the default);
126
127       •   "continue" or 1, which causes the program, when it encounters a
128           file error, to just emit a warning (on STDERR) and continue with
129           the next file;
130
131       •   "no-output" or 2, which, just like "stop", causes the program to
132           die at the first file error, but in this case it does not print any
133           statement, not even those coming from the previous (already read)
134           files; in other words, the statements are printed out only if (and
135           after) all of the given files have been successfully read.
136
137       The above listed string values are case-insensitive.
138
139   -h, -?, --help
140       It prints a brief help message and exits.
141
142   --man
143       It shows the full man page.
144
145   --version
146       It prints the program version and exits.
147

SUPPORTED DBMSs

149       sql-split aims to cover the widest possible range of DBMSs, SQL
150       dialects and extensions (even proprietary), in a (nearly) fully
151       transparent way for the user.
152
153       Currently it has been tested mainly on SQLite, PostgreSQL, MySQL and
154       Oracle.
155
156   Procedural Extensions
157       Procedural code is by far the most complex to handle.
158
159       Currently any block of code which start with "FUNCTION", "PROCEDURE",
160       "DECLARE", "CREATE" or "CALL" is correctly recognized, as well as
161       anonymous "BEGIN ... END" blocks, dollar quoted blocks and blocks
162       delimited by a "DELIMITER"-defined custom terminator, therefore a wide
163       range of procedural extensions should be handled correctly. However,
164       only PL/SQL, PL/PgSQL and MySQL code has been tested so far.
165

LIMITATIONS

167       None currently known (other than the lack of tests on SQL dialects
168       different from the ones described above).
169
170   Non-limitations
171       To be split correctly, the given input must, in general, be
172       syntactically valid SQL. For example, an unbalanced "BEGIN" or a
173       misspelled keyword could, under certain circumstances, confuse the
174       parser and make it trip over the next statement terminator, thus
175       returning non-split statements. This should not be a problem though, as
176       the original (invalid) SQL code would have been unusable anyway
177       (remember that this is NOT a validating parser!)
178

SEE ALSO

180       •   SQL::SplitStatement (perldoc SQL::SplitStatement)
181
183       Copyright 2011 Emanuele Zeppieri <emazep@cpan.org>.
184

LICENSE

186       This program is free software; you can redistribute it and/or modify it
187       under the same terms as Perl itself.
188
189       See <http://www.perl.com/perl/misc/Artistic.html>
190

NO WARRANTY

192       This program comes with NO WARRANTIES of any kind. It not only may
193       cause loss of data and hardware damaging, but it may also cause several
194       bad diseases to nearby people, including, but not limited to,
195       diarrhoea, gonorrhea and dysmenorrhea.  Don't say you haven't been
196       warned.
197
198
199
200perl v5.36.0                      2023-01-20                      SQL-SPLIT(1)
Impressum