6 require DBIx::Class::Optional::Dependencies;
7 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('id_shortener')
8 unless DBIx::Class::Optional::Dependencies->req_ok_for ('id_shortener');
12 use Data::Dumper::Concise;
14 use DBICTest ':DiffSQL';
15 use DBIx::Class::SQLMaker::Oracle;
18 # Offline test for connect_by
19 # ( without active database connection)
23 connect_by => { 'parentid' => { '-prior' => \'artistid' } },
24 stmt => '"parentid" = PRIOR artistid',
26 msg => 'Simple: "parentid" = PRIOR artistid',
29 connect_by => { 'parentid' => { '!=' => { '-prior' => { -ident => 'artistid' } } } },
30 stmt => '"parentid" != ( PRIOR "artistid" )',
32 msg => 'Simple: "parentid" != ( PRIOR "artistid" )',
34 # Examples from http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
36 # CONNECT BY last_name != 'King' AND PRIOR employee_id = manager_id ...
39 last_name => { '!=' => 'King' },
40 manager_id => { '-prior' => { -ident => 'employee_id' } },
42 stmt => '( "last_name" != ? OR "manager_id" = PRIOR "employee_id" )',
44 msg => 'oracle.com example #1',
46 # CONNECT BY PRIOR employee_id = manager_id and
47 # PRIOR account_mgr_id = customer_id ...
50 manager_id => { '-prior' => { -ident => 'employee_id' } },
51 customer_id => { '>', { '-prior' => \'account_mgr_id' } },
53 stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR "employee_id" )',
55 msg => 'oracle.com example #2',
57 # CONNECT BY NOCYCLE PRIOR employee_id = manager_id AND LEVEL <= 4;
58 # TODO: NOCYCLE parameter doesn't work
61 my $sqla_oracle = DBIx::Class::SQLMaker::Oracle->new( quote_char => '"', name_sep => '.' );
62 isa_ok($sqla_oracle, 'DBIx::Class::SQLMaker::Oracle');
65 for my $case (@handle_tests) {
67 my $msg = sprintf("Offline: %s",
68 $case->{msg} || substr($case->{stmt},0,25),
72 ( $stmt, @bind ) = $sqla_oracle->_recurse_where( $case->{connect_by} );
73 is_same_sql_bind( $stmt, \@bind, $case->{stmt}, $case->{bind},$msg )
74 || diag "Search term:\n" . Dumper $case->{connect_by};
76 ,sprintf("lives is ok from '%s'",$msg));
80 $sqla_oracle->_shorten_identifier('short_id'),
82 '_shorten_identifier for short id without keywords ok'
86 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo /]),
88 '_shorten_identifier for short id with one keyword ok'
92 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo bar baz /]),
94 '_shorten_identifier for short id with keywords ok'
98 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit'),
99 'VryLngIdntfrWhchExc_72M8CIDTM7',
100 '_shorten_identifier without keywords ok',
104 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo /]),
105 'Foo_72M8CIDTM7KBAUPXG48B22P4E',
106 '_shorten_identifier with one keyword ok',
109 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo bar baz /]),
110 'FooBarBaz_72M8CIDTM7KBAUPXG48B',
111 '_shorten_identifier with keywords ok',
114 # test SQL generation for INSERT ... RETURNING
116 sub UREF { \do { my $x } };
118 $sqla_oracle->{bindtype} = 'columns';
120 for my $q ('', '"') {
121 local $sqla_oracle->{quote_char} = $q;
123 my ($sql, @bind) = $sqla_oracle->insert(
126 'name' => 'Testartist',
129 'returning' => 'artistid',
130 'returning_container' => [],
136 "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING ${q}artistid${q} INTO ?",
137 [ [ name => 'Testartist' ], [ artistid => UREF ] ],
138 'sql_maker generates insert returning for one column'
141 ($sql, @bind) = $sqla_oracle->insert(
144 'name' => 'Testartist',
147 'returning' => \'artistid',
148 'returning_container' => [],
154 "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING artistid INTO ?",
155 [ [ name => 'Testartist' ], [ artistid => UREF ] ],
156 'sql_maker generates insert returning for one column'
160 ($sql, @bind) = $sqla_oracle->insert(
161 'computed_column_test',
163 'a_timestamp' => '2010-05-26 18:22:00',
166 'returning' => [ 'id', 'a_computed_column', 'charfield' ],
167 'returning_container' => [],
173 "INSERT INTO ${q}computed_column_test${q} (${q}a_timestamp${q}) VALUES (?) RETURNING ${q}id${q}, ${q}a_computed_column${q}, ${q}charfield${q} INTO ?, ?, ?",
174 [ [ a_timestamp => '2010-05-26 18:22:00' ], [ id => UREF ], [ a_computed_column => UREF ], [ charfield => UREF ] ],
175 'sql_maker generates insert returning for multiple columns'