Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/SQLMaker/MySQL.pm view on Meta::CPAN
[ INET_NTOA => [0], [ 'misc' ] ],
[ INET_ATON => [1], [ 'misc' ] ],
[ COUNT => [0], [ 'aggregate', 'common' ] ],
[ AVG => [0], [ 'aggregate', 'common' ] ],
[ MIN => [0], [ 'aggregate', 'common' ] ],
[ MAX => [0], [ 'aggregate', 'common' ] ],
[ SUM => [0], [ 'aggregate', 'common' ] ],
[ STD => [0], [ 'aggregate' ] ],
[ STDDEV => [0], [ 'aggregate' ] ],
[ BIT_OR => [0], [ 'misc' ] ],
[ PASSWORD => [1], [ 'misc' ] ],
[ MD5 => [1], [ 'misc' ] ],
[ BIT_AND => [0], [ 'misc' ] ],
[ LOAD_FILE => [1], [ 'misc' ] ],
[ AGAINST => [1], [ 'fulltext' ] ],
)
{
make_function( function => $_->[0],
min => 1,
max => 1,
quote => $_->[1],
groups => $_->[2],
);
}
foreach ( [ MATCH => [0], [ 'fulltext' ] ],
)
{
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.
=head1 EXPORTED SQL FUNCTIONS
SQL may be imported by name or by tags. They take arguments as
documented in the MySQL documentation (version 3.23.39). The
functions (organized by tag) are:
=head2 :math
PI
RAND
MOD
ROUND
POW
POWER
ATAN2
ABS
SIGN
FLOOR
CEILING
EXP
LOG
LOG10
SQRT
COS
SIN
TAN
ACOS
ASIN
ATAN
COT
DEGREES
RADIANS
TRUNCATE
=head2 :string
CHAR
POSITION
INSTR
LEFT
RIGHT
FIND_IN_SET
REPEAT
LEAST
GREATEST
CONCAT
ELT
FIELD
MAKE_SET
LOCATE
SUBSTRING
( run in 0.556 second using v1.01-cache-2.11-cpan-39bf76dae61 )