SQL::TwoWay - Run same SQL in valid SQL and DBI placeholder.
use SQL::TwoWay; my $name = 'STARTING OVER'; my ($sql, @binds) = two_way_sql( q{SELECT * FROM cd WHERE name=/* $name */"MASTERPIECE"}, { name => $name, }); # $sql: SELECT * FROM cd WHERE name=? # $binds[0] = 'STARTING OVER'
SQL::TwoWay is a way to support 2way SQL.
I guess building complex SQL using O/R Mapper or SQL builder, like SQL::Abstract is worth. When you writing complex SQL, you should write SQL by your hand.
And then, you got a issue: "I can't run my query on MySQL console!". Yes. A query like SELECT * FROM cd WHERE name=? is not runnable on console because that contains placeholder.
SELECT * FROM cd WHERE name=?
So, the solution is SQL::TwoWay.
You can write a query like this.
SELECT * FROM cd WHERE name=/* $name */"MASTERPIECE";
This query is 100% valid SQL.
And you can make <$sql> and <@binds> from this query. SQL::TwoWay::two_way_sql() function convert this query.
<$sql
<@binds
SQL::TwoWay::two_way_sql()
Here is a example code:
my ($sql, @binds) = two_way_sql( q{SELECT * FROM cd WHERE name=/* $name */"MASTERPIECE"}, { name => 'STARTING OVER' } );
$sql is:
$sql
SELECT * FROM cd WHERE name=?;
And @binds is:
@binds
('STARTING OVER')
So, you can use same SQL in MySQL console and Perl code. It means 2way SQL.
Replace variables.
if : /* IF $var */ else : /* ELSE */ end : /* END */ variable : /* $var */ literal literal: TBD sql : . root = ( stmt )+ stmt = sql | variable | if_stmt if_stmt = "IF" statement+ "ELSE" statement+ "END" | "IF" statement+ "END"
Copyright (C) tokuhirom
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
tokuhirom <tokuhirom@gmail.com>
s2dao supports 2 way SQL in Java.
To install SQL::TwoWay, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::TwoWay
CPAN shell
perl -MCPAN -e shell install SQL::TwoWay
For more information on module installation, please visit the detailed CPAN module installation guide.