The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SQL::Object::Interp - Yet another SQL condition builder with SQL::Interp

SYNOPSIS

use SQL::Object::Interp qw/isql_obj/;

my $sql = isql_obj('foo.id =', \1, 'AND', 'bar.name =', \'nekokak');
$sql->as_sql; # 'foo.id = ? AND bar.name = ?'
$sql->bind; # qw/1 nekokak/

my $class = 5;
$sql->and('baz.class =', \$class);
$sql->as_sql; # 'foo.id = ? AND bar.name = ? AND baz.class = ?'
$sql->bind; # qw/1 nekokak 5/

my $bar_age = 33;
$sql->or('bar.age =', \$bar_age);
$sql->as_sql; # '(foo.id = ? AND bar.name = ? AND baz.class = ?) OR bar.age = ?'
$sql->bind; # qw/1 nekokak 5 33/

my $cond = isql_obj('foo.id =', \2);
$sql = $sql | $cond;
$sql->as_sql; # '((foo.id = ? AND bar.name = ? AND baz.class = ?) OR bar.age = ?) OR (foo.id = ?)'
$sql->bind; # qw/1 nekokak 5 33 2/

$cond = isql_obj('bar.name =',\'tokuhirom');
$sql = $sql & $cond;
$sql->as_sql; # '((foo.id = ? AND bar.name = ? AND baz.class = ?) OR bar.age = ?) OR (foo.id = ?) AND bar.name = ?'
$sql->bind; # qw/1 nekokak 5 33 2 tokuhirom/

$sql = isql_obj('SELECT * FROM user WHERE ') + $sql;

$sql->as_sql; # 'SELECT * FROM user WHERE ((foo.id = ? AND bar.name = ? AND baz.class = ?) OR bar.age = ?) OR (foo.id = ?) AND bar.name = ?'

my $sql_no = isql_obj;
$sql_no->and('foo.id =', \2);
$sql_no->as_sql; # 'foo.id = ?'
$sql_no->bind; # 2

DESCRIPTION

SQL::Object::Interp is an extension of raw level SQL maker "SQL::Object".

SQL::Object::sql_obj is incompatible with SQL::Interp::sql_interp which returns ($stmt, @binds).

SQL::Object::Interp::isql_obj is a substitute of sql_obj which is compatible with SQL::Interp (like DBIx::Simple::iquery).

METHODS

SQL::Object::Interp inherits SQL::Object.

my $sql = isql_obj(args for sql_interp)

create SQL::Object::Interp's instance.

Uses SQL::Interp to generate $stmt, $bind(s). See SQL::Interp's documentation for usage information.

my $sql = SQL::Object->new(sql => $sql, bind => \@bind); # SQL::Object's method

create SQL::Object::Interp's instance

$sql = $sql->and(args for sql_interp)

compose sql. operation 'AND'.

$sql = $sql->or(args for sql_interp)

compose sql. operation 'OR'.

$sql = $sql->compose_and($sql)

compose sql object. operation 'AND'.

$sql = $sql->compose_or($sql)

compose sql object. operation 'OR'.

$sql->add_parens() # SQL::Object's method

bracket off current SQL.

$sql->as_sql() # SQL::Object's method

get sql statement.

$sql->bind() # SQL::Object's method

get sql bind variables.

AUTHOR

Narazaka (http://narazaka.net/)

SEE ALSO

SQL::Object

SQL::Interp

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.