File: Oracle.pm

package info (click to toggle)
libdata-objectdriver-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 736 kB
  • ctags: 473
  • sloc: perl: 3,529; sql: 60; makefile: 25
file content (63 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (4)
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
# $Id$
# Contributor(s): Xiaoou Wu <xiaoou.wu@oracle.com>
#
package Data::ObjectDriver::SQL::Oracle;

use strict;
use base qw(Data::ObjectDriver::SQL);

## Oracle doesn't have the LIMIT clause.
sub as_limit {
    return '';
}

## Override as_sql to emulate the LIMIT clause.
sub as_sql {
    my $stmt   = shift;
    my $limit  = $stmt->limit;
    my $offset = $stmt->offset;

    if (defined $limit && defined $offset) {
        my @fields = $stmt->select;
        push @fields, "ROW_NUMBER() OVER (ORDER BY 1) R";
    }

    my $sql = $stmt->SUPER::as_sql(@_);

    if (defined $limit) {
        $sql = "SELECT * FROM ( $sql ) WHERE ";
        if (defined $offset) {
            $sql = $sql . " R BETWEEN $offset + 1 AND $limit + $offset";
        } else {
            $sql = $sql . " rownum <= $limit";
        }
    }
    return $sql;
}

1;

__END__

=head1 NAME

Data::ObjectDriver::SQL::Oracle - an SQL statement for Oracle

=head1 DESCRIPTION

This module overrides methods of the Data::ObjectDriver::SQL module
with Oracle specific implementation.

=head1 LICENSE

This module is free software;
you may redistribute and/or modify it under the same
terms as Perl itself.

=head1 AUTHOR & COPYRIGHT

This module is
copyright (c) 2009 Xiaoou Wu E<lt>xiaoou.wu@oracle.comE<gt>.
All rights reserved.

=cut