SQL::QueryBuilder::Pretty - Perl extension to beautify SQL.
Version 0.01
use SQL::QueryBuilder::Pretty; my $pretty = SQL::QueryBuilder::Pretty->new( '-indent_ammount' => 4, '-indent_char' => ' ', '-new_line' => "\n", ); print $pretty->print('SELECT * FROM table WHERE col1 = NOW()');
The main goal of this Module was not the beautify mechanism, wich is allready well implemented in SQL::Beautify, but to provide a easy way to add new SQL languages, and related rules, in a modular and independent fashion.
Initializes the object.
Returns a beautifyed SQL query.
The database rules to apply to the query. SQL::QueryBuilder::Pretty->new( '-database' = 'MySQL' )> is the same as SQL::QueryBuilder::Pretty::Database::MySQL->new()>. Default is none.
SQL::QueryBuilder::Pretty->new( '-database' =
SQL::QueryBuilder::Pretty::Database::MySQL->new()
The database rules to apply to the query. SQL::QueryBuilder::Pretty->new( '-handler' = $dbh_mysql )> is the same as SQL::QueryBuilder::Pretty::Handler::DBD::db::mysql->new()>. Default is none.
SQL::QueryBuilder::Pretty->new( '-handler' =
SQL::QueryBuilder::Pretty::Handler::DBD::db::mysql->new()
The number of time '-indent_char' is repeated for each indentation. Default is 4.
Indent char used. Default is ' '.
New line char used. default is "\n",
If the database option is not set, SQL::QueryBuilder::Pretty will use ANSI rules to beautify the query. This rules can be found in SQL/QueryBuilder/Pretty/Database/ANSI/*.
Let's imagine we wanted to create the rules for Oracle database:
In SQL/QueryBuilder/Pretty/Database we should add the file Oracle.pm with the following code:
#!/usr/bin/perl package SQL::QueryBuilder::Pretty::Database::Oracle; use base qw(SQL::QueryBuilder::Pretty); SQL::QueryBuilder::Pretty->search_path( add => 'SQL::QueryBuilder::Pretty::Database::Oracle' ); 1;
Create the Oracle's rules directory SQL/QueryBuilder/Pretty/Database/Oracle and add the necessary rules. See SUBCLASSING in SQL::QueryBuilder::Pretty::Rule.
TO add a new handler support we need to first add the related database. See ADDING RULES FOR A SPECIFIC DATABASE.
Let's imagine we wanted to create the support for DBI::oracle handler:
Get the reference of the handler. In DBI's case it's DBI::db.
If not exists, create the directory SQL/QueryBuilder/Pretty/Handler/DBI and add the file db.pm with the following code:
#!/usr/bin/perl package SQL::QueryBuilder::Pretty::Handler::DBI::db; sub new { my $class = shift; my %self = @_; if ( $self->{'handler'}->{'Driver'}->{'Name'} eq 'oracle' ) { return SQL::QueryBuilder::Pretty::Database::Oracle->( %self ); } } 1;
This is just an example of what can be done.
Although SQL::QueryBuilder::Pretty have a differente approach, some ideas where "borrowed" from other projects. That said ,I would like to thank to:
Igor Sutton Lopes, for SQL::Tokenizer, where I got must of the regular expressions used in SQL::QueryBuilder::Pretty's rules;
Jonas Kramer, for SQL::Beautify, where I got the idea for the output manipultaion system used in SQL::QueryBuilder::Pretty::Print.
A special thank to Marco Neves who encourage me to make this distribuition available in CPAN.
SQL::QueryBuilder, Module::Pluggable, SQL::Tokenizer and SQL::Beautify.
André Rivotti Casimiro, <rivotti at cpan.org>
<rivotti at cpan.org>
Please report any bugs or feature requests to bug-sql-querybuilder-pretty at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SQL-QueryBuilder-Pretty. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-sql-querybuilder-pretty at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc SQL::QueryBuilder::Pretty
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-QueryBuilder-Pretty
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/SQL-QueryBuilder-Pretty
CPAN Ratings
http://cpanratings.perl.org/d/SQL-QueryBuilder-Pretty
Search CPAN
http://search.cpan.org/dist/SQL-QueryBuilder-Pretty
Copyright (C) 2009 by André Rivotti Casimiro. Published under the terms of the Artistic License 2.0.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'André'. Assuming UTF-8
To install SQL::QueryBuilder::Pretty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::QueryBuilder::Pretty
CPAN shell
perl -MCPAN -e shell install SQL::QueryBuilder::Pretty
For more information on module installation, please visit the detailed CPAN module installation guide.