File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11Revision history for SQL-Beautify
22
3+ 0.05 2022-03-09
4+ * Force new linr after a line comment
5+
360.04 2011-08-07
47 * Support for adding own keywords.
58 * Support for custom rules
@@ -15,7 +18,7 @@ Revision history for SQL-Beautify
15180.02 2009-03-29
1619 * Fix in documentation.
1720 * Line break before ORDER BY and GROUP BY.
18-
21+
1922
20230.01 2009-02-22
2124 First version, released on an unsuspecting world.
Original file line number Diff line number Diff line change @@ -115,6 +115,11 @@ sub beautify {
115115 $self -> _process_rule($rule , $token );
116116 }
117117
118+ elsif ($token =~ / ^--$ /i ) {
119+ $self -> _add_token($token );
120+ $self -> _new_line;
121+ }
122+
118123 elsif ($token eq ' (' ) {
119124 $self -> _add_token($token );
120125 $self -> _new_line;
@@ -233,8 +238,8 @@ sub _add_token {
233238 $token = uc $token
234239 if $self -> _is_keyword($token ) and $self -> {uc_keywords };
235240
236- # lowercase name
237- $token = lc $token
241+ # lowercase name
242+ $token = lc $token
238243 if $self -> {lc_names } and !$self -> _is_keyword( $token ) and !$self -> _is_constant( $token );
239244
240245 $self -> {_output } .= $token ;
Original file line number Diff line number Diff line change 1+ # !/usr/bin/perl
2+
3+ use strict;
4+ use warnings;
5+
6+ use Test::More tests => 4;
7+ use SQL::Beautify;
8+
9+ my $sql = new SQL::Beautify(spaces => 2);
10+ my $query ;
11+ my $beauty ;
12+
13+ ok($sql , ' got instance' );
14+
15+ # Test plain text formatting.
16+ $query = <DATA >;
17+ $beauty = <DATA >;
18+
19+ $beauty = eval $beauty ;
20+
21+ ok($sql -> query($query ) eq $query , ' query set' );
22+ ok($sql -> query eq $query , ' query get' );
23+
24+ ok($sql -> beautify eq $beauty , ' beautified' );
25+
26+
27+ __DATA__
28+ SELECT * FROM foo, bar, baz WHERE foo.id = bar.id -- AND bar.id = baz.id
29+ "SELECT\n *\nFROM\n foo,\n bar,\n baz\nWHERE\n foo.id = bar.id -- AND bar.id = baz.id\n"
You can’t perform that action at this time.
0 commit comments