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; |
d5dedbd6 |
9 | use DBIx::Class::SQLMaker::Oracle; |
c2f2a718 |
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 | |
d5dedbd6 |
55 | my $sqla_oracle = DBIx::Class::SQLMaker::Oracle->new( quote_char => '"', name_sep => '.' ); |
56 | isa_ok($sqla_oracle, 'DBIx::Class::SQLMaker::Oracle'); |
c2f2a718 |
57 | |
58 | |
c2f2a718 |
59 | for my $case (@handle_tests) { |
c2f2a718 |
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} ); |
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 | |
63ca94e1 |
73 | is ( |
74 | $sqla_oracle->_shorten_identifier('short_id'), |
75 | 'short_id', |
76 | '_shorten_identifier for short id without keywords ok' |
77 | ); |
78 | |
79 | is ( |
80 | $sqla_oracle->_shorten_identifier('short_id', [qw/ foo /]), |
81 | 'short_id', |
82 | '_shorten_identifier for short id with one keyword ok' |
83 | ); |
84 | |
85 | is ( |
86 | $sqla_oracle->_shorten_identifier('short_id', [qw/ foo bar baz /]), |
87 | 'short_id', |
88 | '_shorten_identifier for short id with keywords ok' |
89 | ); |
90 | |
91 | is ( |
92 | $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit'), |
93 | 'VryLngIdntfrWhchExc_72M8CIDTM7', |
94 | '_shorten_identifier without keywords ok', |
95 | ); |
96 | |
97 | is ( |
98 | $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo /]), |
99 | 'Foo_72M8CIDTM7KBAUPXG48B22P4E', |
100 | '_shorten_identifier with one keyword ok', |
101 | ); |
102 | is ( |
103 | $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo bar baz /]), |
104 | 'FooBarBaz_72M8CIDTM7KBAUPXG48B', |
105 | '_shorten_identifier with keywords ok', |
106 | ); |
c2f2a718 |
107 | |
63ca94e1 |
108 | done_testing; |