X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsqlmaker%2Foracle.t;h=14e74e2938c2dd1a28e7d00634848359ca3a32ab;hb=6a6394f19f31dbc44cb5382d241890555e8cebd5;hp=6b9e6f9b17915c94ba122f503f757a4fe0c8ab78;hpb=d5dedbd62928f65a9071b4d9b6d56c6b663a073b;p=dbsrgits%2FDBIx-Class.git diff --git a/t/sqlmaker/oracle.t b/t/sqlmaker/oracle.t index 6b9e6f9..14e74e2 100644 --- a/t/sqlmaker/oracle.t +++ b/t/sqlmaker/oracle.t @@ -1,17 +1,23 @@ - use strict; use warnings; use Test::More; + +BEGIN { + require DBIx::Class::Optional::Dependencies; + plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('id_shortener') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('id_shortener'); +} + use Test::Exception; use Data::Dumper::Concise; use lib qw(t/lib); use DBIC::SqlMakerTest; use DBIx::Class::SQLMaker::Oracle; -# +# # Offline test for connect_by -# ( without acitve database connection) -# +# ( without active database connection) +# my @handle_tests = ( { connect_by => { 'parentid' => { '-prior' => \'artistid' } }, @@ -20,10 +26,10 @@ my @handle_tests = ( msg => 'Simple: "parentid" = PRIOR artistid', }, { - connect_by => { 'parentid' => { '!=' => { '-prior' => \'artistid' } } }, - stmt => '"parentid" != ( PRIOR artistid )', + connect_by => { 'parentid' => { '!=' => { '-prior' => { -ident => 'artistid' } } } }, + stmt => '"parentid" != ( PRIOR "artistid" )', bind => [], - msg => 'Simple: "parentid" != ( PRIOR artistid )', + msg => 'Simple: "parentid" != ( PRIOR "artistid" )', }, # Examples from http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm @@ -31,9 +37,9 @@ my @handle_tests = ( { connect_by => [ last_name => { '!=' => 'King' }, - manager_id => { '-prior' => \'employee_id' }, + manager_id => { '-prior' => { -ident => 'employee_id' } }, ], - stmt => '( "last_name" != ? OR "manager_id" = PRIOR employee_id )', + stmt => '( "last_name" != ? OR "manager_id" = PRIOR "employee_id" )', bind => ['King'], msg => 'oracle.com example #1', }, @@ -41,10 +47,10 @@ my @handle_tests = ( # PRIOR account_mgr_id = customer_id ... { connect_by => { - manager_id => { '-prior' => \'employee_id' }, + manager_id => { '-prior' => { -ident => 'employee_id' } }, customer_id => { '>', { '-prior' => \'account_mgr_id' } }, }, - stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR employee_id )', + stmt => '( "customer_id" > ( PRIOR account_mgr_id ) AND "manager_id" = PRIOR "employee_id" )', bind => [], msg => 'oracle.com example #2', }, @@ -105,4 +111,69 @@ is ( '_shorten_identifier with keywords ok', ); +# test SQL generation for INSERT ... RETURNING + +sub UREF { \do { my $x } }; + +$sqla_oracle->{bindtype} = 'columns'; + +for my $q ('', '"') { + local $sqla_oracle->{quote_char} = $q; + + my ($sql, @bind) = $sqla_oracle->insert( + 'artist', + { + 'name' => 'Testartist', + }, + { + 'returning' => 'artistid', + 'returning_container' => [], + }, + ); + + is_same_sql_bind( + $sql, \@bind, + "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING ${q}artistid${q} INTO ?", + [ [ name => 'Testartist' ], [ artistid => UREF ] ], + 'sql_maker generates insert returning for one column' + ); + + ($sql, @bind) = $sqla_oracle->insert( + 'artist', + { + 'name' => 'Testartist', + }, + { + 'returning' => \'artistid', + 'returning_container' => [], + }, + ); + + is_same_sql_bind( + $sql, \@bind, + "INSERT INTO ${q}artist${q} (${q}name${q}) VALUES (?) RETURNING artistid INTO ?", + [ [ name => 'Testartist' ], [ artistid => UREF ] ], + 'sql_maker generates insert returning for one column' + ); + + + ($sql, @bind) = $sqla_oracle->insert( + 'computed_column_test', + { + 'a_timestamp' => '2010-05-26 18:22:00', + }, + { + 'returning' => [ 'id', 'a_computed_column', 'charfield' ], + 'returning_container' => [], + }, + ); + + is_same_sql_bind( + $sql, \@bind, + "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 ?, ?, ?", + [ [ a_timestamp => '2010-05-26 18:22:00' ], [ id => UREF ], [ a_computed_column => UREF ], [ charfield => UREF ] ], + 'sql_maker generates insert returning for multiple columns' + ); +} + done_testing;