6 use Data::Dumper::Concise;
8 use DBIC::SqlMakerTest;
9 use DBIx::Class::SQLMaker::Oracle;
12 # Offline test for connect_by
13 # ( without acitve database connection)
17 connect_by => { 'parentid' => { '-prior' => \'artistid' } },
18 stmt => '"parentid" = PRIOR artistid',
20 msg => 'Simple: "parentid" = PRIOR artistid',
23 connect_by => { 'parentid' => { '!=' => { '-prior' => \'artistid' } } },
24 stmt => '"parentid" != ( PRIOR artistid )',
26 msg => 'Simple: "parentid" != ( PRIOR artistid )',
28 # Examples from http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
30 # CONNECT BY last_name != 'King' AND PRIOR employee_id = manager_id ...
33 last_name => { '!=' => 'King' },
34 manager_id => { '-prior' => \'employee_id' },
36 stmt => '( "last_name" != ? OR "manager_id" = PRIOR employee_id )',
38 msg => 'oracle.com example #1',
40 # CONNECT BY PRIOR employee_id = manager_id and
41 # PRIOR account_mgr_id = customer_id ...
44 manager_id => { '-prior' => \'employee_id' },
45 customer_id => { '>', { '-prior' => \'account_mgr_id' } },
47 stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR employee_id )',
49 msg => 'oracle.com example #2',
51 # CONNECT BY NOCYCLE PRIOR employee_id = manager_id AND LEVEL <= 4;
52 # TODO: NOCYCLE parameter doesn't work
55 my $sqla_oracle = DBIx::Class::SQLMaker::Oracle->new( quote_char => '"', name_sep => '.' );
56 isa_ok($sqla_oracle, 'DBIx::Class::SQLMaker::Oracle');
59 for my $case (@handle_tests) {
61 my $msg = sprintf("Offline: %s",
62 $case->{msg} || substr($case->{stmt},0,25),
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};
70 ,sprintf("lives is ok from '%s'",$msg));
74 $sqla_oracle->_shorten_identifier('short_id'),
76 '_shorten_identifier for short id without keywords ok'
80 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo /]),
82 '_shorten_identifier for short id with one keyword ok'
86 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo bar baz /]),
88 '_shorten_identifier for short id with keywords ok'
92 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit'),
93 'VryLngIdntfrWhchExc_72M8CIDTM7',
94 '_shorten_identifier without keywords ok',
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',
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',