SQL::DB::Expr - Build SQL expressions with Perl
0.19_9. Development release.
use SQL::DB::Expr; my $col1 = SQL::DB::Expr->new( _txt => 'col1', _btype => 'SQL_INTEGER', ); my $col2 = SQL::DB::Expr->new( _txt => 'col2', ); my $expr = ($col1->is_not_null .AND. $col2->between(1,2))->as('alias');
SQL::DB::Expr provides an object class that supports mapping Perl syntax to SQL text, values and types suitable for passing to DBI methods. This class is the basis for SQL::DB and is not generally used directly.
new( _txt => $_txt, _btype => $bind_type, _multi => $_multi, );
The SQL representation of the expression suitable for passing to DBI methods such as do(), selectall_arrayref(), prepare(), etc.
The DBD bind_type suitable for passing to a DBI statement-handle bind_param() method.
Whether the expression requires surrounding brackets.
A subroutine called during an object's instantiation phase.
Makes a deep copy of the object.
Returns a string representation of the expression, providing surrounding brackets for '_multi' expressions.
Maps '!' to 'NOT'.
Maps '==' to "==".
Maps '!=' to "!=".
Maps '&' to "&";
Maps '|' to "|";
Maps '<' to "<";
Maps '>' to ">";
Maps '<=' to "<=";
Maps '>=' to ">=";
Maps '+' to "+";
Maps '-' to "-";
Maps '*' to "*";
Maps '/' to "/";
Maps to "IS NULL".
Maps to "IS NOT NULL".
Maps to "IN (@VALUES)"
Maps to "NOT IN ( @VALUES )".
Maps to "BETWEEN $a AND $b".
Maps to "NOT BETWEEN $a AND $b".
Maps to "AS $as".
Maps to "LIKE $like".
Maps to "ASC".
Maps to "DESC".
The following functions are exported on demand.
Returns an object which is recognized by SQL::DB as something which should be quoted before being prepared.
Returns an object which is recognized by SQL::DB as something which should be bound (via a placeholder) before being prepared.
A method for building binary operator expressions.
Does the same as Perl's 'join' built-in. but for SQL::DB::Expr objects. See BUGS below for why this is needed.
These subroutines let you write SQL logical expressions in Perl using string concatenation:
( $e1 .AND. $e2 ) .OR. ( $e3 .AND. $e4 )
Note that due to operator precedence, expressions either side of .AND. or .OR. should be bracketed if they are not already single expression objects.
Things are implemented this way due to Perl not allowing the overloading of the 'and' and 'or' built-ins.
Using SQL::DB::Expr objects with the Perl "join" command does not work as expected, apparently because join does not trigger either the '.' or '.=' overload methods. The work around is to use the _expr_join subroutine.
SQL::DB, DBI
Mark Lawrence <nomad@null.net>
Copyright (C) 2007-2011 Mark Lawrence <nomad@null.net>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
To install SQL::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::DB
CPAN shell
perl -MCPAN -e shell install SQL::DB
For more information on module installation, please visit the detailed CPAN module installation guide.