NAME

SQL::QueryBuilder::Pretty - Perl extension to beautify SQL.

VERSION

Version 0.01

SYNOPSIS

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()');

DESCRIPTION

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.

METHODS

PACKAGE->new(%options)

Initializes the object.

$obj->print($query)

Returns a beautifyed SQL query.

OPTIONS

-database

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.

-handler

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.

-indent_amount

The number of time '-indent_char' is repeated for each indentation. Default is 4.

-indent_char

Indent char used. Default is ' '.

-new_line

New line char used. default is "\n",

ADDING RULES FOR A SPECIFIC DATABASE

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.

ADDING A NEW HANDLER SUPPORT

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.

ACKNOWLEDGEMENTS

Although SQL::QueryBuilder::Pretty have a differente approach, some ideas where "borrowed" from other projects. That said ,I would like to thank to:

A special thank to Marco Neves who encourage me to make this distribuition available in CPAN.

SEE ALSO

SQL::QueryBuilder, Module::Pluggable, SQL::Tokenizer and SQL::Beautify.

AUTHOR

André Rivotti Casimiro, <rivotti at cpan.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc SQL::QueryBuilder::Pretty

You can also look for information at:

COPYRIGHT AND LICENSE

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:

Around line 222:

Non-ASCII character seen before =encoding in 'André'. Assuming UTF-8