X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F749sqlanywhere.t;h=d4067b5bfd7397b11d5d89a81d6c5a2d0c76f504;hb=12a184d0a0c1868708e43aaabefe08f9e7ac9ec4;hp=d8a33a394201b4ea38820970ad3c57c5aafcf126;hpb=b1bdb76d043ec2057ffa8dcf00f5fade9f98a1fa;p=dbsrgits%2FDBIx-Class.git diff --git a/t/749sqlanywhere.t b/t/749sqlanywhere.t index d8a33a3..d4067b5 100644 --- a/t/749sqlanywhere.t +++ b/t/749sqlanywhere.t @@ -1,19 +1,34 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; use Test::Exception; -use Scope::Guard (); -use lib qw(t/lib); +use Try::Tiny; +use DBIx::Class::Optional::Dependencies (); +use DBIx::Class::_Util 'scope_guard'; + use DBICTest; +my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/}; +my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/}; + +plan skip_all => 'Test needs ' . + (join ' or ', map { $_ ? $_ : () } + DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere'), + DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere_odbc')) + unless + $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere') + or + $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere_odbc') + or + (not $dsn || $dsn2); + DBICTest::Schema->load_classes('ArtistGUID'); # tests stolen from 748informix.t -my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/}; -my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/}; - plan skip_all => <<'EOF' unless $dsn || $dsn2; Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN}, _USER and _PASS to run these tests @@ -35,7 +50,7 @@ foreach my $info (@info) { auto_savepoint => 1 }); - my $guard = Scope::Guard->new(\&cleanup); + my $guard = scope_guard { cleanup($schema) }; my $dbh = $schema->storage->dbh; @@ -134,10 +149,11 @@ EOF $dbh->do(qq[ CREATE TABLE bindtype_test ( - id INT NOT NULL PRIMARY KEY, - bytea INT NULL, - blob LONG BINARY NULL, - clob LONG VARCHAR NULL + id INT NOT NULL PRIMARY KEY, + bytea INT NULL, + blob LONG BINARY NULL, + clob LONG VARCHAR NULL, + a_memo INT NULL ) ],{ RaiseError => 1, PrintError => 1 }); @@ -163,10 +179,11 @@ EOF ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" ); } } - + my @uuid_types = qw/uniqueidentifier uniqueidentifierstr/; -# test uniqueidentifiers +# test uniqueidentifiers (and the cursor_class). + for my $uuid_type (@uuid_types) { local $schema->source('ArtistGUID')->column_info('artistid')->{data_type} = $uuid_type; @@ -189,6 +206,9 @@ CREATE TABLE artist_guid ( SQL }); + local $TODO = 'something wrong with uniqueidentifierstr over ODBC' + if $dsn =~ /:ODBC:/ && $uuid_type eq 'uniqueidentifierstr'; + my $row; lives_ok { $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' }) @@ -206,20 +226,42 @@ SQL ); diag $@ if $@; - my $row_from_db = $schema->resultset('ArtistGUID') - ->search({ name => 'mtfnpy' })->first; + my $row_from_db = try { $schema->resultset('ArtistGUID') + ->search({ name => 'mtfnpy' })->first } + catch { diag $_ }; + + is try { $row_from_db->artistid }, $row->artistid, + 'PK GUID round trip (via ->search->next)'; + + is try { $row_from_db->a_guid }, $row->a_guid, + 'NON-PK GUID round trip (via ->search->next)'; + + $row_from_db = try { $schema->resultset('ArtistGUID') + ->find($row->artistid) } + catch { diag $_ }; + + is try { $row_from_db->artistid }, $row->artistid, + 'PK GUID round trip (via ->find)'; + + is try { $row_from_db->a_guid }, $row->a_guid, + 'NON-PK GUID round trip (via ->find)'; + + ($row_from_db) = try { $schema->resultset('ArtistGUID') + ->search({ name => 'mtfnpy' })->all } + catch { diag $_ }; - is $row_from_db->artistid, $row->artistid, - 'PK GUID round trip'; + is try { $row_from_db->artistid }, $row->artistid, + 'PK GUID round trip (via ->search->all)'; - is $row_from_db->a_guid, $row->a_guid, - 'NON-PK GUID round trip'; + is try { $row_from_db->a_guid }, $row->a_guid, + 'NON-PK GUID round trip (via ->search->all)'; } } done_testing; sub cleanup { + my $schema = shift; eval { $schema->storage->dbh->do("DROP TABLE $_") } for qw/artist artist_guid bindtype_test/; }