/usr/share/perl5/Alzabo/SQLMaker/MySQL.pm is in libalzabo-perl 0.92-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | package Alzabo::SQLMaker::MySQL;
use strict;
use vars qw($VERSION $AUTOLOAD @EXPORT_OK %EXPORT_TAGS);
use Alzabo::Exceptions;
use Alzabo::Utils;
use Alzabo::SQLMaker;
use base qw(Alzabo::SQLMaker);
$VERSION = 2.0;
my $MADE_FUNCTIONS;
sub import
{
_make_functions() unless $MADE_FUNCTIONS;
# used to export function functions
require Exporter;
*_import = \&Exporter::import;
goto &_import;
}
sub _make_functions
{
local *make_function = \&Alzabo::SQLMaker::make_function;
foreach ( [ PI => [ 'math' ] ],
[ CURDATE => [ 'datetime' ] ],
[ CURRENT_DATE => [ 'datetime' ] ],
[ CURTIME => [ 'datetime' ] ],
[ CURRENT_TIME => [ 'datetime' ] ],
[ NOW => [ 'datetime', 'common' ] ],
[ SYSDATE => [ 'datetime' ] ],
[ CURRENT_TIMESTAMP => [ 'datetime' ] ],
[ DATABASE => [ 'system' ] ],
[ USER => [ 'system' ] ],
[ SYSTEM_USER => [ 'system' ] ],
[ SESSION_USER => [ 'system' ] ],
[ VERSION => [ 'system' ] ],
[ CONNECTION_ID => [ 'system' ] ],
)
{
make_function( function => $_->[0],
min => 0,
max => 0,
groups => $_->[1]
);
}
foreach ( [ RAND => [ 'math' ] ],
[ UNIX_TIMESTAMP => [ 'datetime' ] ],
[ LAST_INSERT_ID => [ 'system' ] ],
)
{
make_function( function => $_->[0],
min => 0,
max => 1,
quote => [0],
groups => $_->[1]
);
}
make_function( function => 'CHAR',
min => 1,
max => undef,
quote => [0],
groups => [ 'string' ],
);
foreach ( [ ENCRYPT => [1,1], [ 'misc' ] ] )
{
make_function( function => $_->[0],
min => 0,
max => 1,
quote => $_->[1],
groups => $_->[2],
);
}
foreach ( [ MOD => [0,0], [ 'math' ] ],
[ ROUND => [0,0], [ 'math' ] ],
[ POW => [0,0], [ 'math' ] ],
[ POWER => [0,0], [ 'math' ] ],
[ ATAN2 => [0,0], [ 'math' ] ],
[ POSITION => [1,1], [ 'string' ] ],
[ INSTR => [1,1], [ 'string' ] ],
[ LEFT => [1,1], [ 'string' ] ],
[ RIGHT => [1,1], [ 'string' ] ],
[ FIND_IN_SET => [1,1], [ 'string' ] ],
[ REPEAT => [1,0], [ 'string' ] ],
[ ENCODE => [1,1], [ 'misc' ] ],
[ DECODE => [1,1], [ 'misc' ] ],
[ FORMAT => [0,0], [ 'misc' ] ],
[ PERIOD_ADD => [0,0], [ 'datetime' ] ],
[ PERIOD_DIFF => [0,0], [ 'datetime' ] ],
[ DATE_ADD => [1,0], [ 'datetime' ] ],
[ DATE_SUB => [1,0] , [ 'datetime' ]],
[ ADDDATE => [1,0], [ 'datetime' ] ],
[ SUBDATE => [1,0], [ 'datetime' ] ],
[ DATE_FORMAT => [1,1], [ 'datetime' ] ],
[ TIME_FORMAT => [1,1], [ 'datetime' ] ],
[ FROM_UNIXTIME => [0,1], [ 'datetime' ] ],
[ GET_LOCK => [1,0], [ 'system' ] ],
[ BENCHMARK => [0,1], [ 'system' ] ],
[ MASTER_POS_WAIT => [1,0], [ 'system' ] ],
[ IFNULL => [0,1], [ 'control' ] ],
[ NULLIF => [0,0], [ 'control' ] ],
)
{
make_function( function => $_->[0],
min => 2,
max => 2,
quote => $_->[1],
groups => $_->[2],
);
}
foreach ( [ LEAST => [1,1,1], [ 'string' ] ],
[ GREATEST => [1,1,1], [ 'string' ] ],
[ CONCAT => [1,1,1], [ 'string' ] ],
[ ELT => [0,1.1], [ 'string' ] ],
[ FIELD => [1,1,1], [ 'string' ] ],
[ MAKE_SET => [0,1,1], [ 'string' ] ],
)
{
make_function( function => $_->[0],
min => 2,
max => undef,
quote => $_->[1],
groups => $_->[2],
);
}
foreach ( [ LOCATE => [1,1,0], [ 'string' ] ],
[ SUBSTRING => [1,0,0], [ 'string' ] ],
[ CONV => [1,0,0], [ 'string' ] ],
[ LPAD => [1,0,1], [ 'string' ] ],
[ RPAD => [1,0,1], [ 'string' ] ],
[ MID => [1,0,0], [ 'string' ] ],
[ SUBSTRING_INDEX => [1,1,0], [ 'string' ] ],
[ REPLACE => [1,1,1], [ 'string' ] ],
[ IF => [0,1,1], [ 'control' ] ],
)
{
make_function( function => $_->[0],
min => 3,
max => 3,
quote => $_->[1],
groups => $_->[2],
);
}
foreach ( [ WEEK => [1,0], [ 'datetime' ] ],
[ YEARWEEK => [1,0], [ 'datetime' ] ],
)
{
make_function( function => $_->[0],
min => 1,
max => 2,
quote => $_->[1],
groups => $_->[2],
);
}
make_function( function => 'CONCAT_WS',
min => 3,
max => undef,
quote => [1,1,1,1],
groups => [ 'string' ],
);
make_function( function => 'EXPORT_SET',
min => 3,
max => 5,
quote => [0,1,1,1,0],
groups => [ 'string' ],
);
make_function( function => 'INSERT',
min => 3,
max => 5,
quote => [1,0,0,1],
groups => [ 'string' ],
);
foreach ( [ ABS => [0], [ 'math' ] ],
[ SIGN => [0], [ 'math' ] ],
[ FLOOR => [0], [ 'math' ] ],
[ CEILING => [0], [ 'math' ] ],
[ EXP => [0], [ 'math' ] ],
[ LOG => [0], [ 'math' ] ],
[ LOG10 => [0], [ 'math' ] ],
[ SQRT => [0], [ 'math' ] ],
[ COS => [0], [ 'math' ] ],
[ SIN => [0], [ 'math' ] ],
[ TAN => [0], [ 'math' ] ],
[ ACOS => [0], [ 'math' ] ],
[ ASIN => [0], [ 'math' ] ],
[ ATAN => [0], [ 'math' ] ],
[ COT => [0], [ 'math' ] ],
[ DEGREES => [0], [ 'math' ] ],
[ RADIANS => [0], [ 'math' ] ],
[ TRUNCATE => [0], [ 'math' ] ],
[ ASCII => [1], [ 'string' ] ],
[ ORD => [1], [ 'string' ] ],
[ BIN => [0], [ 'string' ] ],
[ OCT => [0], [ 'string' ] ],
[ HEX => [0], [ 'string' ] ],
[ LENGTH => [1], [ 'string' ] ],
[ OCTET_LENGTH => [1], [ 'string' ] ],
[ CHAR_LENGTH => [1], [ 'string' ] ],
[ CHARACTER_LENGTH => [1], [ 'string' ] ],
[ TRIM => [1], [ 'string' ] ],
[ LTRIM => [1], [ 'string' ] ],
[ RTRIM => [1], [ 'string' ] ],
[ SOUNDEX => [1], [ 'string' ] ],
[ SPACE => [0], [ 'string' ] ],
[ REVERSE => [1], [ 'string' ] ],
[ LCASE => [1], [ 'string' ] ],
[ LOWER => [1], [ 'string' ] ],
[ UCASE => [1], [ 'string' ] ],
[ UPPER => [1], [ 'string' ] ],
[ RELEASE_LOCK => [1], [ 'system' ] ],
[ DAYOFWEEK => [1], [ 'datetime' ] ],
[ WEEKDAY => [1], [ 'datetime' ] ],
[ DAYOFYEAR => [1], [ 'datetime' ] ],
[ MONTH => [1], [ 'datetime' ] ],
[ DAYNAME => [1], [ 'datetime' ] ],
[ MONTHNAME => [1], [ 'datetime' ] ],
[ QUARTER => [1], [ 'datetime' ] ],
[ YEAR => [1], [ 'datetime' ] ],
[ HOUR => [1], [ 'datetime' ] ],
[ MINUTE => [1], [ 'datetime' ] ],
[ SECOND => [1], [ 'datetime' ] ],
[ TO_DAYS => [1], [ 'datetime' ] ],
[ FROM_DAYS => [0], [ 'datetime' ] ],
[ SEC_TO_TIME => [0], [ 'datetime' ] ],
[ TIME_TO_SEC => [1], [ 'datetime' ] ],
[ 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
CONV
LPAD
RPAD
MID
SUBSTRING_INDEX
REPLACE
CONCAT_WS
EXPORT_SET
INSERT
ASCII
ORD
BIN
OCT
HEX
LENGTH
OCTET_LENGTH
CHAR_LENGTH
CHARACTER_LENGTH
TRIM
LTRIM
RTRIM
SOUNDEX
SPACE
REVERSE
LCASE
LOWER
UCASE
UPPER
=head2 :datetime
CURDATE
CURRENT_DATE
CURTIME
CURRENT_TIME
NOW
SYSDATE
CURRENT_TIMESTAMP
UNIX_TIMESTAMP
WEEK
PERIOD_ADD
PERIOD_DIFF
DATE_ADD
DATE_SUB
ADDDATE
SUBDATE
DATE_FORMAT
TIME_FORMAT
FROM_UNIXTIME
DAYOFWEEK
WEEKDAY
DAYOFYEAR
MONTH
DAYNAME
MONTHNAME
QUARTER
YEAR
YEARWEEK
HOUR
MINUTE
SECOND
TO_DAYS
FROM_DAYS
SEC_TO_TIME
TIME_TO_SEC
=head2 :aggregate
These are functions which operate on an aggregate set of values all at
once.
COUNT
AVG
MIN
MAX
SUM
STD
STDDEV
=head2 :system
These are functions which return information about the MySQL server.
DATABASE
USER
SYSTEM_USER
SESSION_USER
VERSION
CONNECTION_ID
LAST_INSERT_ID
GET_LOCK
RELEASE_LOCK
BENCHMARK
MASTER_POS_WAIT
=head2 :control
These are flow control functions:
IFNULL
NULLIF
IF
=head2 :misc
These are functions which don't fit into any other categories.
ENCRYPT
ENCODE
DECODE
FORMAT
INET_NTOA
INET_ATON
BIT_OR
BIT_AND
PASSWORD
MD5
LOAD_FILE
=head2 :fulltext
These are functions related to MySQL's fulltext searching
capabilities.
MATCH
AGAINST
IN_BOOLEAN_MODE
NOTE: In MySQL 4.0 and greater, it is possible to say that a search is
in boolean mode in order to change how MySQL handles the argument
given to AGAINST. This will not work with earlier versions.
=head2 :common
These are functions from other groups that are most commonly used.
NOW
COUNT
AVG
MIN
MAX
SUM
DISTINCT
=head1 AUTHOR
Dave Rolsky, <dave@urth.org>
=cut
|