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