Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / sqlmaker / limit_dialects / custom.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Warn;
8
9
10 use DBICTest ':DiffSQL';
11
12 # This is legacy stuff from SQL::Absract::Limit
13 # Keep it around just in case someone is using it
14
15 {
16   package DBICTest::SQLMaker::CustomDialect;
17   use base qw/DBIx::Class::SQLMaker/;
18   sub emulate_limit {
19     my ($self, $sql, $rs_attrs, $limit, $offset) = @_;
20     return sprintf ('shiny sproc ((%s), %d, %d)',
21       $sql,
22       $limit || 0,
23       $offset || 0,
24     );
25   }
26 }
27 my $s = DBICTest::Schema->connect (DBICTest->_database);
28 $s->storage->sql_maker_class ('DBICTest::SQLMaker::CustomDialect');
29
30 my $rs = $s->resultset ('CD');
31
32 warnings_exist { is_same_sql_bind (
33   $rs->search ({}, { rows => 1, offset => 3,columns => [
34       { id => 'foo.id' },
35       { 'artist.id' => 'bar.id' },
36       { bleh => \ 'TO_CHAR (foo.womble, "blah")' },
37     ]})->as_query,
38   '(
39     shiny sproc (
40       (
41         SELECT foo.id, bar.id, TO_CHAR (foo.womble, "blah")
42           FROM cd me
43       ),
44       1,
45       3
46     )
47   )',
48   [],
49   'Rownum subsel aliasing works correctly'
50  )}
51   qr/\Qthe legacy emulate_limit() mechanism inherited from SQL::Abstract::Limit has been deprecated/,
52   'deprecation warning'
53 ;
54
55 done_testing;