/[SQLSession]/trunk/lib/SQLSession/Utils.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/SQLSession/Utils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations)
Sat Sep 8 11:58:41 2007 UTC (16 years, 7 months ago) by dpavlin
File size: 732 byte(s)
tweak
1 dpavlin 99 # Dobrica Pavlinusic, <dpavlin@rot13.org> 02/16/07 21:42:21 CET
2    
3     use strict;
4     use warnings;
5    
6     package SQLSession::Utils;
7     use Exporter qw/import/;
8     our @EXPORT_OK = qw(
9     reformat_sql
10     );
11    
12     =head2 reformat_sql
13    
14     Pretty-print (but still plain ASCII) SQL statement;
15    
16     print $self->reformat_sql( $sql );
17    
18     =cut
19    
20     sub reformat_sql {
21     my $self = shift;
22    
23     my $sql = shift || return;
24    
25     warn "<<<< original SQL:\t$sql";
26    
27     sub sql_uc {
28     my ($prefix,$sql,$suff) = @_;
29     return uc($sql).$suff if (! $prefix || $prefix eq '');
30     return "\n" . uc($sql) . $suff;
31     }
32    
33 dpavlin 109 $sql =~ s/(\s*)(select|from|inner\s+join|order\s+by|where|group\s+by|having|limit|offset|union)(\s+)/sql_uc($1,$2,$3)/egis;
34 dpavlin 99
35 dpavlin 116 warn ">>>> canonicalize SQL:\n$sql\n";
36 dpavlin 99
37     return $sql;
38     }
39    
40     1;

  ViewVC Help
Powered by ViewVC 1.1.26