-ident implementation
[dbsrgits/DBIx-Class.git] / t / sqlmaker / oracle.t
CommitLineData
c2f2a718 1
2use strict;
3use warnings;
4use Test::More;
5use Test::Exception;
a84fe712 6use Data::Dumper::Concise;
c2f2a718 7use lib qw(t/lib);
8use DBIC::SqlMakerTest;
d5dedbd6 9use DBIx::Class::SQLMaker::Oracle;
c2f2a718 10
c2f2a718 11#
12# Offline test for connect_by
13# ( without acitve database connection)
14#
15my @handle_tests = (
16 {
17 connect_by => { 'parentid' => { '-prior' => \'artistid' } },
18 stmt => '"parentid" = PRIOR artistid',
19 bind => [],
20 msg => 'Simple: "parentid" = PRIOR artistid',
21 },
22 {
e6600283 23 connect_by => { 'parentid' => { '!=' => { '-prior' => { -ident => 'artistid' } } } },
24 stmt => '"parentid" != ( PRIOR "artistid" )',
c2f2a718 25 bind => [],
e6600283 26 msg => 'Simple: "parentid" != ( PRIOR "artistid" )',
c2f2a718 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' },
e6600283 34 manager_id => { '-prior' => { -ident => 'employee_id' } },
c2f2a718 35 ],
e6600283 36 stmt => '( "last_name" != ? OR "manager_id" = PRIOR "employee_id" )',
c2f2a718 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 => {
e6600283 44 manager_id => { '-prior' => { -ident => 'employee_id' } },
c2f2a718 45 customer_id => { '>', { '-prior' => \'account_mgr_id' } },
46 },
e6600283 47 stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR "employee_id" )',
c2f2a718 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 55my $sqla_oracle = DBIx::Class::SQLMaker::Oracle->new( quote_char => '"', name_sep => '.' );
56isa_ok($sqla_oracle, 'DBIx::Class::SQLMaker::Oracle');
c2f2a718 57
58
c2f2a718 59for 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 73is (
74 $sqla_oracle->_shorten_identifier('short_id'),
75 'short_id',
76 '_shorten_identifier for short id without keywords ok'
77);
78
79is (
80 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo /]),
81 'short_id',
82 '_shorten_identifier for short id with one keyword ok'
83);
84
85is (
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
91is (
92 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit'),
93 'VryLngIdntfrWhchExc_72M8CIDTM7',
94 '_shorten_identifier without keywords ok',
95);
96
97is (
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);
102is (
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 108done_testing;