| SQL-Entity documentation | Contained in the SQL-Entity distribution. |
SQL::Query::Limit::MySQL - LIMIT emulation for MySQL database.
SQL::Query::Limit::Oracle
use SQL::Query::Limit::MySQL;
SQL navigation wrapper for MySQL.
None.
TODO. Improve collision in threads, - add ower to PLSQL
The SQL::Query::Limit::MySQL module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Adrian Witas, adrian@webapp.strefa.pl
| SQL-Entity documentation | Contained in the SQL-Entity distribution. |
package SQL::Query::Limit::MySQL; use warnings; use strict; use vars qw($VERSION); $VERSION = '0.02'; use Abstract::Meta::Class ':all'; use SQL::Entity::Column ':all'; use SQL::Entity::Condition ':all'; use base 'SQL::Entity';
has '$.the_rownum';
sub query { my ($self, $offset, $limit, $requested_columns, $condition) = @_; my ($sql, $bind_variables) = $self->SUPER::query($requested_columns, $condition); $sql = "SELECT " . $self->alias . ".*," . $self->the_rownum_column->as_string . "\nFROM (\n" . $sql . ") " . $self->alias . "\nLIMIT ? OFFSET ?"; push @$bind_variables, $limit, ($offset - 1); ($sql, $bind_variables); }
sub the_rownum_column { my ($self) = @_; my $the_rownum = $self->the_rownum; $the_rownum ||= $self->the_rownum(SQL::Entity::Column->new(name => '@rownum = @rownum + 1', id => 'the_rownum')); }
sub sequence_name { 'rownum'; }
sub query_setup { my ($self, $connection) = @_; my $sequence_name = $self->sequence_name; $connection->do('SET @rownum = 1;'); } 1; __END__