X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F73oracle_hq.t;h=0f887fab34c37a130bae8573cc1df1877d6fa428;hb=ac0c082542;hp=07c1f409b69f67e4dd6b1d622eaf77d9e785fe43;hpb=fcb7fcbb6bde5f9a211c62011b3110f07828caec;p=dbsrgits%2FDBIx-Class.git diff --git a/t/73oracle_hq.t b/t/73oracle_hq.t index 07c1f40..0f887fa 100644 --- a/t/73oracle_hq.t +++ b/t/73oracle_hq.t @@ -3,26 +3,22 @@ use warnings; use Test::Exception; use Test::More; - +use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); -use DBIC::SqlMakerTest; - -use DBIx::Class::SQLMaker::LimitDialects; -my $ROWS = DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype, -my $TOTAL = DBIx::Class::SQLMaker::LimitDialects->__total_bindtype, +use DBICTest::RunMode; $ENV{NLS_SORT} = "BINARY"; $ENV{NLS_COMP} = "BINARY"; $ENV{NLS_LANG} = "AMERICAN"; -plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle') - unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle'); - my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test.' unless ($dsn && $user && $pass); +plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_oracle') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_oracle'); + use DBICTest::Schema::Artist; BEGIN { DBICTest::Schema::Artist->add_column('parentid'); @@ -38,6 +34,7 @@ BEGIN { ); } +use DBICTest; use DBICTest::Schema; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -112,35 +109,12 @@ do_creates($dbh); connect_by => { parentid => { -prior => { -ident => 'artistid' } } }, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - )', - [ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'] ], - ); is_deeply ( [ $rs->get_column ('name')->all ], [ qw/root child1 grandchild greatgrandchild child2/ ], 'got artist tree', ); - is_same_sql_bind ( - $rs->count_rs->as_query, - '( - SELECT COUNT( * ) - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - )', - [ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'] ], - ); - is( $rs->count, 5, 'Connect By count ok' ); } @@ -156,19 +130,6 @@ do_creates($dbh); order_siblings_by => { -desc => 'name' }, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - ORDER SIBLINGS BY name DESC - )', - [ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'] ], - ); - is_deeply ( [ $rs->get_column ('name')->all ], [ qw/root child2 child1 grandchild greatgrandchild/ ], @@ -183,19 +144,6 @@ do_creates($dbh); connect_by => { parentid => { -prior => { -ident => 'artistid' } } }, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - WHERE ( parentid IS NULL ) - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - )', - [ [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'] ], - ); - is_deeply( [ $rs->get_column('name')->all ], [ 'root' ], @@ -218,48 +166,12 @@ do_creates($dbh); } ); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - LEFT JOIN cd cds ON cds.artist = me.artistid - WHERE ( cds.title LIKE ? ) - START WITH me.name = ? - CONNECT BY parentid = PRIOR artistid - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'cds.title', 'sqlt_size' => 100 } - => '%cd'], - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'me.name', 'sqlt_size' => 100 } - => 'root'], - ], - ); - is_deeply( [ $rs->get_column('name')->all ], [ 'grandchild' ], 'Connect By with a join result name ok' ); - is_same_sql_bind ( - $rs->count_rs->as_query, - '( - SELECT COUNT( * ) - FROM artist me - LEFT JOIN cd cds ON cds.artist = me.artistid - WHERE ( cds.title LIKE ? ) - START WITH me.name = ? - CONNECT BY parentid = PRIOR artistid - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'cds.title', 'sqlt_size' => 100 } - => '%cd'], - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'me.name', 'sqlt_size' => 100 } - => 'root'], - ], - ); - is( $rs->count, 1, 'Connect By with a join; count ok' ); } @@ -271,22 +183,6 @@ do_creates($dbh); order_by => { -asc => [ 'LEVEL', 'name' ] }, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - ORDER BY LEVEL ASC, name ASC - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'], - ], - ); - - # Don't use "$rs->get_column ('name')->all" they build a query arround the $rs. # If $rs has a order by, the order by is in the subquery and this doesn't work with Oracle 8i. # TODO: write extra test and fix order by handling on Oracle 8i @@ -316,56 +212,16 @@ do_creates($dbh); my $rs = $schema->resultset('Artist')->search({}, { start_with => { name => 'root' }, connect_by => { parentid => { -prior => { -ident => 'artistid' } } }, - order_by => { -asc => 'name' }, + order_by => [ { -asc => 'name' }, { -desc => 'artistid' } ], rows => 2, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT artistid, name, rank, charfield, parentid - FROM ( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - ORDER BY name ASC - ) me - WHERE ROWNUM <= ? - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'], [ $ROWS => 2 ], - ], - ); - is_deeply ( [ $rs->get_column ('name')->all ], [qw/child1 child2/], 'LIMIT a Connect By query - correct names' ); - is_same_sql_bind ( - $rs->count_rs->as_query, - '( - SELECT COUNT( * ) - FROM ( - SELECT artistid - FROM ( - SELECT me.artistid - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - ) me - WHERE ROWNUM <= ? - ) me - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'], [ $ROWS => 2 ] , - ], - ); - is( $rs->count, 2, 'Connect By; LIMIT count ok' ); } @@ -381,27 +237,6 @@ do_creates($dbh); having => \[ 'count(rank) < ?', [ cnt => 2 ] ], }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT COUNT(rank) + ? - FROM artist me - START WITH name = ? - CONNECT BY parentid = PRIOR artistid - GROUP BY( rank + ? ) HAVING count(rank) < ? - )', - [ - [ { dbic_colname => '__cbind' } - => 3 ], - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'root'], - [ { dbic_colname => '__gbind' } - => 1 ], - [ { dbic_colname => 'cnt' } - => 2 ], - ], - ); - is_deeply ( [ $rs->get_column ('cnt')->all ], [4, 4], @@ -434,19 +269,6 @@ do_creates($dbh); connect_by_nocycle => { parentid => { -prior => { -ident => 'artistid' } } }, }); - is_same_sql_bind ( - $rs->as_query, - '( - SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid, CONNECT_BY_ISCYCLE - FROM artist me - START WITH name = ? - CONNECT BY NOCYCLE parentid = PRIOR artistid - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'cycle-root'], - ], - ); is_deeply ( [ $rs->get_column ('name')->all ], [ qw/cycle-root cycle-child1 cycle-grandchild cycle-child2/ ], @@ -458,20 +280,6 @@ do_creates($dbh); 'got artist tree with nocycle (CONNECT_BY_ISCYCLE)', ); - is_same_sql_bind ( - $rs->count_rs->as_query, - '( - SELECT COUNT( * ) - FROM artist me - START WITH name = ? - CONNECT BY NOCYCLE parentid = PRIOR artistid - )', - [ - [ { 'sqlt_datatype' => 'varchar', 'dbic_colname' => 'name', 'sqlt_size' => 100 } - => 'cycle-root'], - ], - ); - is( $rs->count, 4, 'Connect By Nocycle count ok' ); } } @@ -552,13 +360,15 @@ sub do_creates { # clean up our mess END { - eval { - my $dbh = $schema->storage->dbh; - $dbh->do("DROP SEQUENCE artist_pk_seq"); - $dbh->do("DROP SEQUENCE cd_seq"); - $dbh->do("DROP SEQUENCE track_seq"); - $dbh->do("DROP TABLE artist"); - $dbh->do("DROP TABLE track"); - $dbh->do("DROP TABLE cd"); + if ($schema and my $dbh = $schema->storage->dbh) { + eval { $dbh->do($_) } for ( + 'DROP SEQUENCE artist_pk_seq', + 'DROP SEQUENCE cd_seq', + 'DROP SEQUENCE track_seq', + 'DROP TABLE artist', + 'DROP TABLE track', + 'DROP TABLE cd', + ); }; + undef $schema; }