b40ebceae6b3dee13d9bdf70416b269af2cde36e
[dbsrgits/DBIx-Class.git] / t / oracle / connect_by.t
1
2 use strict;
3 use warnings;
4 use Test::More;
5 use Test::Exception;
6 use Data::Dumper;
7 use lib qw(t/lib);
8 use DBIC::SqlMakerTest;
9 use DBIx::Class::SQLAHacks::Oracle;
10
11
12
13
14 #  Offline test for connect_by 
15 #  ( without acitve database connection)
16
17 my @handle_tests = (
18     {
19         connect_by  => { 'parentid' => { '-prior' => \'artistid' } },
20         stmt        => " parentid = PRIOR artistid ",
21         bind        => [],
22         msg         => 'Simple: parentid = PRIOR artistid',
23     },
24     # {
25         # TODO: Can't handle this...
26         # connect_by  => { 'parentid' => { '!=' => { '-prior' => \'artistid' } } },
27         # connect_by  => [ \'parentid',  ],
28         # stmt        => "parentid != PRIOR artistid ",
29         # bind        => [],
30         # msg         => 'Simple: parentid != PRIOR artistid',
31     # },
32
33     # Excample from http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
34     {
35         connect_by => [
36             'last_name' => { '!=' => 'King' },
37             '-prior' => [ \'employee_id', \'manager_id' ],
38         ],
39         stmt => "( last_name != ? AND PRIOR employee_id = manager_id )",
40         bind => ['King'],
41     },
42     {
43         connect_by => [
44             '-prior' => [ \'employee_id', \'manager_id' ],
45             '-prior' => [ \'account_mgr_id', \'customer_id' ],
46         ],
47         stmt => "( PRIOR employee_id = manager_id AND PRIOR account_mgr_id = customer_id )",
48         bind => [],
49     },
50 );
51
52 my $sqla_oracle = DBIx::Class::SQLAHacks::Oracle->new();
53 isa_ok($sqla_oracle, 'DBIx::Class::SQLAHacks::Oracle');
54
55
56 my $test_count = ( @handle_tests * 2 ) + 1;
57
58 for my $case (@handle_tests) {
59     local $Data::Dumper::Terse = 1;
60     my ( $stmt, @bind );
61     my $msg = sprintf("Offline: %s",
62         $case->{msg} || substr($case->{stmt},0,25),
63     );
64     lives_ok(
65         sub {
66             ( $stmt, @bind ) = $sqla_oracle->_recurse_where( $case->{connect_by}, 'and' );
67             is_same_sql_bind( $stmt, \@bind, $case->{stmt}, $case->{bind},$msg )
68               || diag "Search term:\n" . Dumper $case->{connect_by};
69         }
70     ,sprintf("lives is ok from '%s'",$msg));
71 }
72
73
74 #   Online Tests?
75
76 $test_count += 0;
77
78 done_testing( $test_count );