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

NAME

6       sql-split - SQL splitting command line utility
7

VERSION

9       version 1.00020
10

SYNOPSIS

12           sql-split [ OPTIONS ] [ FILE(S) ]
13           sql-split --man
14

DESCRIPTION

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

OPTIONS

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

SUPPORTED DBMSs

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

LIMITATIONS

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

SEE ALSO

181       ·   SQL::SplitStatement (perldoc SQL::SplitStatement)
182
184       Copyright 2011 Emanuele Zeppieri <emazep@cpan.org>.
185

LICENSE

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

NO WARRANTY

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