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;
15 use DBIC::SqlMakerTest;
16 use DBIx::Class::SQLMaker::Oracle;
19 # Offline test for connect_by
20 # ( without active database connection)
24 connect_by => { 'parentid' => { '-prior' => \'artistid' } },
25 stmt => '"parentid" = PRIOR artistid',
27 msg => 'Simple: "parentid" = PRIOR artistid',
30 connect_by => { 'parentid' => { '!=' => { '-prior' => { -ident => 'artistid' } } } },
31 stmt => '"parentid" != ( PRIOR "artistid" )',
33 msg => 'Simple: "parentid" != ( PRIOR "artistid" )',
35 # Examples from http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
37 # CONNECT BY last_name != 'King' AND PRIOR employee_id = manager_id ...
40 last_name => { '!=' => 'King' },
41 manager_id => { '-prior' => { -ident => 'employee_id' } },
43 stmt => '( "last_name" != ? OR "manager_id" = PRIOR "employee_id" )',
45 msg => 'oracle.com example #1',
47 # CONNECT BY PRIOR employee_id = manager_id and
48 # PRIOR account_mgr_id = customer_id ...
51 manager_id => { '-prior' => { -ident => 'employee_id' } },
52 customer_id => { '>', { '-prior' => \'account_mgr_id' } },
54 stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR "employee_id" )',
56 msg => 'oracle.com example #2',
58 # CONNECT BY NOCYCLE PRIOR employee_id = manager_id AND LEVEL <= 4;
59 # TODO: NOCYCLE parameter doesn't work
62 my $sqla_oracle = DBIx::Class::SQLMaker::Oracle->new( quote_char => '"', name_sep => '.' );
63 isa_ok($sqla_oracle, 'DBIx::Class::SQLMaker::Oracle');
66 for my $case (@handle_tests) {
68 my $msg = sprintf("Offline: %s",
69 $case->{msg} || substr($case->{stmt},0,25),
73 ( $stmt, @bind ) = $sqla_oracle->_recurse_where( $case->{connect_by} );
74 is_same_sql_bind( $stmt, \@bind, $case->{stmt}, $case->{bind},$msg )
75 || diag "Search term:\n" . Dumper $case->{connect_by};
77 ,sprintf("lives is ok from '%s'",$msg));
81 $sqla_oracle->_shorten_identifier('short_id'),
83 '_shorten_identifier for short id without keywords ok'
87 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo /]),
89 '_shorten_identifier for short id with one keyword ok'
93 $sqla_oracle->_shorten_identifier('short_id', [qw/ foo bar baz /]),
95 '_shorten_identifier for short id with keywords ok'
99 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit'),
100 'VryLngIdntfrWhchExc_72M8CIDTM7',
101 '_shorten_identifier without keywords ok',
105 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo /]),
106 'Foo_72M8CIDTM7KBAUPXG48B22P4E',
107 '_shorten_identifier with one keyword ok',
110 $sqla_oracle->_shorten_identifier('very_long_identifier_which_exceeds_the_30char_limit',[qw/ foo bar baz /]),
111 'FooBarBaz_72M8CIDTM7KBAUPXG48B',
112 '_shorten_identifier with keywords ok',
115 # test SQL generation for INSERT ... RETURNING
117 sub UREF { \do { my $x } };
119 $sqla_oracle->{bindtype} = 'columns';
121 for my $q ('', '"') {
122 local $sqla_oracle->{quote_char} = $q;
124 my ($sql, @bind) = $sqla_oracle->insert(
127 'name' => 'Testartist',
130 'returning' => 'artistid',
131 'returning_container' => [],
137 "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING ${q}artistid${q} INTO ?",
138 [ [ name => 'Testartist' ], [ artistid => UREF ] ],
139 'sql_maker generates insert returning for one column'
142 ($sql, @bind) = $sqla_oracle->insert(
145 'name' => 'Testartist',
148 'returning' => \'artistid',
149 'returning_container' => [],
155 "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING artistid INTO ?",
156 [ [ name => 'Testartist' ], [ artistid => UREF ] ],
157 'sql_maker generates insert returning for one column'
161 ($sql, @bind) = $sqla_oracle->insert(
162 'computed_column_test',
164 'a_timestamp' => '2010-05-26 18:22:00',
167 'returning' => [ 'id', 'a_computed_column', 'charfield' ],
168 'returning_container' => [],
174 "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 ?, ?, ?",
175 [ [ a_timestamp => '2010-05-26 18:22:00' ], [ id => UREF ], [ a_computed_column => UREF ], [ charfield => UREF ] ],
176 'sql_maker generates insert returning for multiple columns'