Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/SQLMaker/MySQL.pm view on Meta::CPAN
{
make_function( function => $_->[0],
min => 1,
max => undef,
quote => $_->[1],
groups => $_->[2],
);
}
make_function( function => 'DISTINCT',
min => 1,
max => undef,
quote => [0],
groups => [ 'common' ],
allows_alias => 0,
);
make_function( function => 'IN_BOOLEAN_MODE',
is_modifier => 1,
groups => [ 'fulltext' ],
);
$MADE_FUNCTIONS = 1;
}
sub init
{
1;
}
sub select
{
my $self = shift;
#
# Special check for [ MATCH( $foo_col, $bar_col ), AGAINST('foo bar') ]
# IN_BOOLEAN_MODE is optional
#
for ( my $i = 0; $i <= $#_; $i++ )
{
if ( Alzabo::Utils::safe_isa( $_[$i], 'Alzabo::SQLMaker::Function' ) &&
$_[$i]->as_string( $self->{driver}, $self->{quote_identifiers} ) =~ /^\s*MATCH/i )
{
$_[$i] = $_[$i]->as_string( $self->{driver}, $self->{quote_identifiers} );
$_[$i] .= ' ' . $_[$i + 1]->as_string( $self->{driver}, $self->{quote_identifiers} );
splice @_, $i + 1, 1;
if ( defined $_[ $i + 1 ] &&
Alzabo::Utils::safe_isa( $_[ $i + 1 ], 'Alzabo::SQLMaker::Function' ) &&
$_[ $i + 1 ]->as_string( $self->{driver}, $self->{quote_identifiers} ) =~
/^\s*IN BOOLEAN MODE/i )
{
$_[$i] .= ' ' . $_[$i + 1]->as_string( $self->{driver}, $self->{quote_identifiers} );
splice @_, $i + 1, 1;
}
}
}
$self->SUPER::select(@_);
}
sub condition
{
my $self = shift;
#
# Special check for [ MATCH( $foo_col, $bar_col ), AGAINST('foo bar') ]
# IN_BOOLEAN_MODE is optional
#
if ( Alzabo::Utils::safe_isa( $_[0], 'Alzabo::SQLMaker::Function' ) &&
$_[0]->as_string( $self->{driver}, $self->{quote_identifiers} ) =~ /^\s*MATCH/i )
{
$self->{last_op} = 'condition';
$self->{sql} .=
join ' ', map { $_->as_string( $self->{driver}, $self->{quote_identifiers} ) } @_;
}
else
{
$self->SUPER::condition(@_);
}
}
sub limit
{
my $self = shift;
my ($max, $offset) = @_;
$self->_assert_last_op( qw( from function where and or condition order_by group_by ) );
if ($offset)
{
$self->{sql} .= " LIMIT $offset, $max";
}
else
{
$self->{sql} .= " LIMIT $max";
}
$self->{last_op} = 'limit';
return $self;
}
sub get_limit
{
return undef;
}
sub sqlmaker_id
{
return 'MySQL';
}
1;
__END__
=head1 NAME
Alzabo::SQLMaker::MySQL - Alzabo SQL making class for MySQL
=head1 SYNOPSIS
use Alzabo::SQLMaker;
my $sql = Alzabo::SQLMaker->new( sql => 'MySQL' );
=head1 DESCRIPTION
This class implementes MySQL-specific SQL creation. MySQL does not
allow subselects. Any attempt to use a subselect (by passing an
C<Alzabo::SQMaker> object in as parameter to a method) will result in
an L<C<Alzabo::Exception::SQL>|Alzabo::Exceptions> error.
=head1 METHODS
Almost all of the functionality inherited from Alzabo::SQLMaker is
used as is. The only overridden methods are C<limit()> and
C<get_limit()>, as MySQL does allow for a C<LIMIT> clause in its SQL.
( run in 0.740 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )