SQL::DB::Schema::AColumn - description


SQL-DB documentation Contained in the SQL-DB distribution.

Index


Code Index:

NAME

Top

SQL::DB::Schema::AColumn - description

SYNOPSIS

Top

  use SQL::DB::Schema::AColumn;

DESCRIPTION

Top

SQL::DB::Schema::AColumn is ...

METHODS

Top

new

_column

_arow

is_null

is_not_null

SQL: IS NOT NULL

expr_not

like

asc

desc

set

FILES

Top

SEE ALSO

Top

Other

AUTHOR

Top

Mark Lawrence <nomad@null.net>

COPYRIGHT AND LICENSE

Top


SQL-DB documentation Contained in the SQL-DB distribution.

package SQL::DB::Schema::AColumn;
use strict;
use warnings;
use base qw(SQL::DB::Schema::Expr);
use Carp qw(carp croak confess);
use Scalar::Util qw(weaken);
use UNIVERSAL qw(isa);


sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = $class->SUPER::new;

    my $col   = shift;
    my $arow  = shift;
    $self->{col}  = $col;  # column definition SQL::DB::Schema::AColumn
    $self->{arow} = $arow; # abstract representation of a table row
    weaken($self->{arow});

    $self->{expr_as}   = $col->name; #FIXME shouldn't know about Expr internals
    $self->set_val($arow->_alias .'.'. $col->name);


    bless($self, $class);
    return $self;
}


sub _column {
    my $self = shift;
    return $self->{col};
}


sub _arow {
    my $self = shift;
    return $self->{arow};
}


sub expr_not {is_null(@_);}
sub is_null {
    my $self     = shift;
    $self        = $self->_clone();
    $self->set_val($self->{arow}->_alias .'.'. $self->{col}->name .' IS NULL');
    return $self;
}


sub is_not_null {
    my $self     = shift;
    $self        = $self->_clone();
    $self->set_val($self->{arow}->_alias .'.'. $self->{col}->name 
                   .' IS NOT NULL');
    return $self;
}


sub like {
    my $self     = shift;
    my $like     = shift || croak 'like() requires an argument';
    $self        = $self->_clone();
    $self->set_val($self->{arow}->_alias .'.'. $self->{col}->name .' LIKE ?');
    $self->push_bind_values($like);
    return $self;
}


sub asc {
    my $self     = shift;
    $self        = $self->_clone();
    $self->set_val($self->{arow}->_alias .'.'. $self->{col}->name .' ASC');
    return $self;
}


sub desc {
    my $self     = shift;
    $self        = $self->_clone();
    $self->set_val($self->{arow}->_alias .'.'. $self->{col}->name .' DESC');
    return $self;
}


sub set {
    my $self     = shift;
    @_ || confess 'set() requires an argument:'. $self;
    my $val      = shift;
    $self        = $self->_clone();
    if (UNIVERSAL::isa($val, 'SQL::DB::Schema::Expr')) {
        $self->set_val($self->{col}->name .' = '. $val);
        $self->push_bind_values($val->bind_values);
    }
    else {
        $self->set_val($self->{col}->name .' = ?');
        $self->push_bind_values($val);
    }
    return $self;
}


DESTROY {
    my $self = shift;
    warn "DESTROY $self" if($SQL::DB::DEBUG && $SQL::DB::DEBUG>3);
}


1;
__END__
# vim: set tabstop=4 expandtab:


# vim: set tabstop=4 expandtab: