Sugama Keita > SQL-OOP-0.20 > SQL::OOP::Select

Download:
SQL-OOP-0.20.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Source   Latest Release: SQL-OOP-0.21

NAME ^

SQL::OOP::Select

SYNOPSIS ^

    my $where = SQL::OOP::Where->new();
    my $select = SQL::OOP::Select->new();
    
    # set clause by plain text
    $select->set(
        $select->ARG_FIELDS => '*',
        $select->ARG_FROM   => 'some_table',
        $select->ARG_WHERE  => q("some_filed" > 5)
        $select->ARG_GROUPBY   => 'some_field',
        $select->ARG_ORDERBY   => 'some_field ASC',
        $select->ARG_LIMIT     => '10',
        $select->ARG_OFFSET    => '2',
    );

    # reset clauses using objects
    my $where = SQL::OOP::Where->new();
    $select->set(
        $select->ARG_FIELDS => SQL::OOP::ID->new('some_field'),
        $select->ARG_FROM   => SQL::OOP::ID->new('some_table'),
        $select->ARG_WHERE  => $where->cmp('=', "some_fileld", 'value')
        $select->ARG_ORDERBY=> SQL::OOP::Order->new('a', 'b'),
    );
    
    # clause can treats subs so that temporary variables don't mess around
    $select->set(
        $select->ARG_FIELDS => '*',
        $select->ARG_FROM   => 'some_table',
        $select->ARG_WHERE  => sub {
            my $where = SQL::OOP::Where->new();
            return $where->cmp('=', "some_fileld", 'value');
        }
    );
    
    # SQL::OOP::Select can be part of any SQL::OOP::Base sub classes
    my $select2 = SQL::OOP::Select->new();
    $select2->set(
        $select2->ARG_FIELDS => q("col1", "col2"),
        $select2->ARG_FROM   => $select,
    );
    
    my $where = SQL::OOP::Where->new();
    $where->cmp('=', q{some_field}, $select); # some_filed = (SELECT ..)
    
    my $sql  = $select->to_string;
    my @bind = $select->bind;

DESCRIPTION ^

SQL::OOP::Select class represents Select commands.

SQL::OOP::Select->new(%clause)

Constructor. It takes arguments in hash. The Hash keys are provided by following methods. They can be called as either class or instance method.

    ARG_FIELDS
    ARG_FROM
    ARG_WHERE
    ARG_GROUPBY
    ARG_ORDERBY
    ARG_LIMIT
    ARG_OFFSET

$instance->set(%clause)

This method resets the clause data. It takes same argument as SQL::OOP::Select->new().

$instance->to_string

Get SQL snippet in string

$instance->bind

Get binded values in array

CONSTANTS ^

KEYS

PREFIXES

ARG_FIELDS

argument key for FIELDS(=1)

ARG_FROM

argument key for FROM clause(=2)

ARG_WHERE

argument key for WHERE clause(=3)

ARG_GROUPBY

argument key for GROUP BY clause(=4)

ARG_ORDERBY

argument key for ORDER BY clause(=5)

ARG_LIMIT

argument key for LIMIT clause(=6)

ARG_OFFSET

argument key for OFFSET clause(=7)

EXAMPLE ^

Here is a comprehensive example for SELECT. You also can find some examples in test scripts.

    my $select = SQL::OOP::Select->new();
    $select->set(
        $select->ARG_FIELDS => '*',
        $select->ARG_FROM   => 'table',
        $select->ARG_WHERE  => sub {
            my $where = SQL::OOP::Where->new;
            return $where->and(
                $where->cmp('=', 'a', 1),
                $where->cmp('=', 'b', 1),
            )
        },
    );

AUTHOR ^

Sugama Keita, <sugama@jamadam.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2011 by Sugama Keita.

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

syntax highlighting: