element, instead of gobbling up the entire parse-to-date
- Explicitly handle ROW_NUMBER() OVER as the snowflake-operator it is
- Improve signatures/documentation of is_same_sql_bind / eq_sql_bind
+ - Retire script/format-sql - the utility needs more work to be truly
+ end-user convenient
revision 1.77 2014-01-17
----------------------------
requires 'Scalar::Util' => 0;
requires 'Moo' => 1.004002;
requires 'Hash::Merge' => 0.12;
-requires 'Getopt::Long::Descriptive' => 0.091;
test_requires "Test::More" => 0.88;
test_requires "Test::Exception" => 0.31;
no_index package => 'DBIx::Class::Storage::Debug::PrettyPrint';
no_index directory => 'examples';
-install_script 'format-sql';
-
tests_recursive 't';
auto_install();
#!/sur/bin/env perl
+use warnings;
+use strict;
+
use SQL::Abstract::Tree;
my $sqlat = SQL::Abstract::Tree->new({ profile => 'console' });
#!/sur/bin/env perl
+use warnings;
+use strict;
+
use DBIx::Class::Storage::Debug::PrettyPrint;
my $pp = DBIx::Class::Storage::Debug::PrettyPrint->new({
--- /dev/null
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+use Getopt::Long;
+my $p = Getopt::Long::Parser->new(config => [qw( gnu_getopt no_ignore_case )]);
+my $opts = { profile => 'console', help => \&showhelp };
+$p->getoptions( $opts, qw(
+ profile|p=s
+ help|h
+)) or showhelp();
+
+sub showhelp {
+ require Pod::Usage;
+ Pod::Usage::pod2usage( -verbose => 0, -exitval => 2 );
+}
+
+require SQL::Abstract::Tree;
+my $sqlat = SQL::Abstract::Tree->new({ profile => $opts->{profile}, fill_in_placeholders => 0 });
+
+my $chunk = '';
+my $leftover = '';
+do {
+ $chunk = $leftover . $chunk if length $leftover;
+
+ if ($chunk =~ / \A (.+?) (?:
+ (?<=\S)\:\s+\'[^\n]+ # pasting DBIC_TRACE output directly
+ |
+ \;(?: \s | \z)
+ |
+ \z
+ |
+ ^ \s* (?=SELECT|INSERT|UPDATE|DELETE)
+ ) (.*) /smix) {
+
+ $leftover = $2;
+ print $sqlat->format($1);
+ print "\n";
+ }
+ else {
+ $leftover = $chunk;
+ }
+} while ( (read *STDIN, $chunk, 4096) or length $leftover );
+
+=head1 NAME
+
+sqla-format - An intelligent SQL formatter
+
+=head1 SYNOPSIS
+
+ ~$ sqla-format << log.sql
+
+ ~$ myprogram -v | sqla-format -p html > sqltrace.html
+
+=head1 COPYRIGHT AND LICENSE
+
+This software is copyright (c) 2014 by Arthur Axel "fREW" Schmidt.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+++ /dev/null
-#!/usr/bin/env perl
-
-use SQL::Abstract::Tree;
-use Getopt::Long::Descriptive;
-
-my ($opt, $usage) = describe_options(
- 'format-sql %o',
- [ 'profile|p=s', "the profile to use", { default => 'console' } ],
- [ 'help', "print usage message and exit" ],
-);
-
- print($usage->text), exit if $opt->help;
-
-my $sqlat = SQL::Abstract::Tree->new({ profile => $opt->profile, fill_in_placeholders => 0 });
-
-print $sqlat->format($_) . "\n" while <>;