SQL-SPLIT(1)

πŸ“¦
version 1.00023 Β· 4 versions
, in opensuse-leap 16.0

πŸ’… SQL-SPLIT(1) β€” the perl-y little splitter that ate

okay bestie, buckle up, because this is sql-split, a User Contributed Perl situation, and it's about to become your new fave little command line utility πŸŽ€

✨ NAME ✨

sql-split β€” the SQL splitting command line utility. that's it, that's the name, she's literally that girl πŸ’–

🌸 SYNOPSIS 🌸

sql-split [ OPTIONS ] [ FILE(S) ]
sql-split --man

like, that's the whole vibe. options, files, go. or just ask for the man page, no judgment 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

so this program tries to split any SQL code into the atomic statements it's composed of β€” and when I say any, I mean even the messy stuff with non-standard and/or procedural extensions, at least the ones from the most popular DBMSs. she's ambitious, okay? πŸ’…

the given FILES get read and split one by one, and the resulting statements are printed to the standard output, separated by a customizable string (see below, there's a whole thing about it). important though: each given file must contain only full SQL statements, meaning no single atomic statement can span multiple files. one statement = one file, no crossing the streams πŸ™ˆ

if no file is given, or if one of the file names is a - (dash), the SQL code is read from STDIN, so this program can be used as a filter or even interactively. main character energy fr fr ⭐

but consider yourself warned: this is by no means a validating parser, so errors in SQL code will not be detected (and can even lead to incorrect splitting). she splits, she does not judge your syntax, she does not fix your life πŸ’€

πŸ‘‘ OPTIONS πŸ‘‘

πŸŽ€ -t, --terminators

it causes the trailing terminator tokens to be kept in the returned atomic statements (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 own line;
  • 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 is they are discarded (or returned) as a whole (regardless of the --no-slash-terminates option value). iconic behavior, no notes ✨

πŸ’– -x, --spaces, --extra-spaces

it causes the space characters around the statements, if any, to be kept in the returned atomic statements (by default they are trimmed instead). a mnemonic for the short version is "X-tra spaces". cute, right? πŸŽ€

🌈 -c, --comments

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. she sees them all πŸ‘€

πŸ“ -m, --empty, --empty-statements

it causes the empty statements to be returned (by default, they are discarded instead).

a statement is considered empty when it contains no characters other than the terminator and space characters. a statement composed solely of comments is not recognized as empty and it is therefore returned, if the --comments option is used. note instead that an empty statement is recognized as such regardless of the use of the --terminators and --extra-spaces options. okay so the empty-girlies get their own rules, we respect it πŸ’…

a mnemonic for this option is keep "M-ty" statements.

🧚 --no-slash, --no-slash-terminates

by default a "/" (forward-slash) on its own line, even without a preceding semicolon, is admitted as a candidate terminator.

when this option is used instead, a forward-slash on its own line is treated as a statement terminator only if preceded by a semicolon or by a dot and a semicolon.

if you are dealing with Oracle's SQL, you should not use this option, since a slash (alone, without a preceding semicolon) is often used as a terminator, as it is permitted by SQL*Plus (on non-block statements). like, do not. seriously πŸ™ˆ

with SQL dialects other than Oracle, there is the (theoretical) possibility that a slash on its own line could pass the additional checks and be considered a terminator (while it shouldn't). this chance should be really tiny (it has never been observed in real world code indeed). though negligible, this option will anyway rule out that risk. tiny risk, still slayed πŸ’€

πŸ’œ -s, --oss, --output-statement-separator string

the string which will be printed between every pair of returned atomic statements. by default, it is a "--" (double dash) on its own line.

to use special characters (such as newlines) when passing such string, please consult your shell docs (for example, in Bash the above mentioned default separator could be defined as $'\n--\n'). your shell, your rules, iykyk 🐚

note that the last returned statement (for each processed file) will not be followed by such separator. she's not gonna trail off, she knows when to stop 🫢

πŸ¦‹ -f, --ofs, --output-file-separator string

the string which will be printed between the groups of statements coming from different files. by default it is the "-- >>>*<<< --" string on its own line.

similarly to the statement separator, the file separator will not be printed after the last file. consistent queen πŸ‘‘

πŸ”₯ -e, --error, --on-error value

it controls the program behavior in case one of the given files is not accessible. melodramatic? maybe. useful? yes.

it can take the following values:

  • "stop" or 0, which causes the program to die at the first file which can not be opened, but it prints all the statements split that far (this is the default);
  • "continue" or 1, which causes the program, when it encounters a file error, to just emit a warning (on STDERR) and continue with the next file;
  • "no-output" or 2, which, just like "stop", causes the program to die 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 have been successfully read.

the above listed string values are case-insensitive. slay πŸŽ€

🌸 -h, -?, --help

it prints a brief help message and exits.

⭐ --man

it shows the full man page. hi, that's this one, you're here πŸ’–

πŸŽ€ --version

it prints the program version and exits.


🌈 SUPPORTED DBMSs 🌈

sql-split aims to cover the widest possible range of DBMSs, SQL dialects and extensions (even proprietary), in a (nearly) fully transparent way for the user. she's an overachiever, we love her πŸ’…

currently it has been tested mainly on SQLite, PostgreSQL, MySQL and Oracle.

πŸ’– Procedural Extensions

procedural code is by far the most complex to handle. the girlies with the most baggage, honestly 😭

currently any block of code which start with "FUNCTION", "PROCEDURE", "DECLARE", "CREATE" or "CALL" is correctly recognized, as well as anonymous "BEGIN ... END" blocks, dollar quoted blocks and blocks delimited by a "DELIMITER"-defined custom terminator, therefore a wide range of procedural extensions should be handled correctly. however, only PL/SQL, PL/PgSQL and MySQL code has been tested so far. no cap 🫢


πŸ’€ LIMITATIONS πŸ’€

none currently known (other than the lack of tests on SQL dialects different from the ones described above). she's flawless, allegedly ✨

🧚 Non-limitations

to be split correctly, the given input must, in general, be syntactically valid SQL. for example, an unbalanced "BEGIN" or a misspelled keyword could, under certain circumstances, confuse the parser and make it trip over the next statement terminator, thus returning non-split statements. this should not be a problem though, as the original (invalid) SQL code would have been unusable anyway (remember that this is NOT a validating parser!). garbage in, garbage out, bestie πŸ’€


πŸ‘€ SEE ALSO πŸ‘€

  • SQL::SplitStatement (perldoc SQL::SplitStatement)

Copyright 2011 Emanuele Zeppieri <emazep@cpan.org>.

πŸ¦‹ LICENSE πŸ¦‹

this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

see <http://www.perl.com/perl/misc/Artistic.html>

πŸ’– NO WARRANTY πŸ’–

this program comes with NO WARRANTIES of any kind. it not only may cause loss of data and hardware damaging, but it may also cause several bad diseases to nearby people, including, but not limited to, diarrhoea, gonorrhea and dysmenorrhea. Don't say you haven't been warned.

she's a little chaotic, but she's OUR little chaotic πŸ’…

and that's the whole page, bestie ✨ this icon was brought to you by perl v5.42.0, dated 2021-06-06, and it's SQL-SPLIT(1) forever and always πŸŽ€πŸ«ΆπŸ’–

πŸ“¦ where this page comes from