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
|
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
package MT::ObjectDriver::SQL::Pg;
use strict;
use warnings;
use base qw( MT::ObjectDriver::SQL );
*distinct_stmt = \&MT::ObjectDriver::SQL::_subselect_distinct;
#--------------------------------------#
# Instance Methods
sub as_limit {
my $stmt = shift;
my $n = $stmt->limit;
my $o = $stmt->offset || 0;
$n = 'ALL' if !$n && $o;
return '' unless $n;
die "Non-numerics in limit/offset clause ($n, $o)"
if ( $o =~ /\D/ ) || ( ( $n ne 'ALL' ) && ( $n =~ /\D/ ) );
return sprintf "LIMIT %s%s\n", $n, ( $o ? " OFFSET " . int($o) : "" );
}
sub _mk_term {
my $stmt = shift;
my ( $col, $val ) = @_;
if ( ref $val eq 'HASH' ) {
if ( !exists $val->{op} ) {
if ( exists $val->{like} ) {
my $cols = $stmt->binary;
if ( !$cols || !exists $cols->{$col} ) {
$val = { op => 'ILIKE', value => $val->{like} };
}
}
}
}
$stmt->SUPER::_mk_term( $col, $val );
}
1;
|