Fix updating multiple CLOB/BLOB columns on Oracle
[dbsrgits/DBIx-Class.git] / t / 751msaccess.t
index 27eeac9..8ea0e2a 100644 (file)
@@ -5,11 +5,25 @@ use Test::More;
 use Test::Exception;
 use Scope::Guard ();
 use Try::Tiny;
+use DBIx::Class::Optional::Dependencies ();
 use lib qw(t/lib);
 use DBICTest;
-use DBIC::DebugObj ();
-use DBIC::SqlMakerTest;
 
+my ($dsn,  $user,  $pass)  = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/};
+my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" }  qw/DSN USER PASS/};
+
+plan skip_all => 'Test needs ' .
+  (join ' or ', map { $_ ? $_ : () }
+    DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_odbc'),
+    DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_ado'))
+  unless
+    $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_odbc')
+    or
+    $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_ado')
+    or
+    (not $dsn || $dsn2);
+
+require DBICTest::Schema;
 DBICTest::Schema->load_classes('ArtistGUID');
 
 # Example DSNs (32bit only):
@@ -17,37 +31,23 @@ DBICTest::Schema->load_classes('ArtistGUID');
 # dbi:ADO:Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb
 # dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb;Persist Security Info=False'
 
-my ($dsn,  $user,  $pass)  = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/};
-my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" }  qw/DSN USER PASS/};
-
 plan skip_all => <<'EOF' unless $dsn || $dsn2;
 Set $ENV{DBICTEST_MSACCESS_ODBC_DSN} and/or $ENV{DBICTEST_MSACCESS_ADO_DSN} (and optionally _USER and _PASS) to run these tests.
 Warning: this test drops and creates the tables 'artist', 'cd', 'bindtype_test' and 'artist_guid'.
 EOF
 
-plan skip_all => 'Test needs ' .
-DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_odbc')
-. ' or ' .
-DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_ado')
-  unless
-    DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_odbc')
-    or
-    DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_ado');
-
 my @info = (
   [ $dsn,  $user  || '', $pass  || '' ],
   [ $dsn2, $user2 || '', $pass2 || '' ],
 );
 
-my $schema;
-
 foreach my $info (@info) {
   my ($dsn, $user, $pass) = @$info;
 
   next unless $dsn;
 
 # Check that we can connect without any options.
-  $schema = DBICTest::Schema->connect($dsn, $user, $pass);
+  my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
   lives_ok {
     $schema->storage->ensure_connected;
   } 'connection without any options';
@@ -63,7 +63,7 @@ foreach my $info (@info) {
     LongReadLen => $maxloblen,
   });
 
-  my $guard = Scope::Guard->new(\&cleanup);
+  my $guard = Scope::Guard->new(sub { cleanup($schema) });
 
   my $dbh = $schema->storage->dbh;
 
@@ -143,12 +143,7 @@ EOF
     title => 'my track',
   });
 
-  my ($sql, @bind);
-
   my $joined_track = try {
-    local $schema->storage->{debug} = 1;
-    local $schema->storage->{debugobj} = DBIC::DebugObj->new(\$sql, \@bind);
-
     $schema->resultset('Artist')->search({
       artistid => $first_artistid,
     }, {
@@ -161,25 +156,10 @@ EOF
     diag "Could not execute two-step left join: $_";
   };
 
-  s/^'//, s/'\z// for @bind;
-
-  is_same_sql_bind(
-    $sql,
-    \@bind,
-    'SELECT [me].[artistid], [me].[name], [me].[rank], [me].[charfield], [tracks].[title] FROM ( ( [artist] [me] LEFT JOIN cd [cds] ON [cds].[artist] = [me].[artistid] ) LEFT JOIN [track] [tracks] ON [tracks].[cd] = [cds].[cdid] ) WHERE ( [artistid] = ? )',
-    [1],
-    'correct SQL for two-step left join',
-  );
-
   is try { $joined_track->get_column('track_title') }, 'my track',
     'two-step left join works';
 
-  ($sql, @bind) = ();
-
   $joined_artist = try {
-    local $schema->storage->{debug} = 1;
-    local $schema->storage->{debugobj} = DBIC::DebugObj->new(\$sql, \@bind);
-
     $schema->resultset('Track')->search({
       trackid => $track->trackid,
     }, {
@@ -192,16 +172,6 @@ EOF
     diag "Could not execute two-step inner join: $_";
   };
 
-  s/^'//, s/'\z// for @bind;
-
-  is_same_sql_bind(
-    $sql,
-    \@bind,
-    'SELECT [me].[trackid], [me].[cd], [me].[position], [me].[title], [me].[last_updated_on], [me].[last_updated_at], [artist].[name] FROM ( ( [track] [me] INNER JOIN cd [cd] ON [cd].[cdid] = [me].[cd] ) INNER JOIN [artist] [artist] ON [artist].[artistid] = [cd].[artist] ) WHERE ( [trackid] = ? )',
-    [$track->trackid],
-    'correct SQL for two-step inner join',
-  );
-
   is try { $joined_artist->get_column('artist_name') }, 'foo',
     'two-step inner join works';
 
@@ -318,7 +288,9 @@ EOF
       id     INT          NOT NULL PRIMARY KEY,
       bytea  INT          NULL,
       blob   IMAGE        NULL,
+      blob2  IMAGE        NULL,
       clob   TEXT         NULL,
+      clob2  TEXT         NULL,
       a_memo MEMO         NULL
     )
     ],{ RaiseError => 1, PrintError => 1 });
@@ -439,6 +411,8 @@ SQL
 done_testing;
 
 sub cleanup {
+  my $schema = shift;
+
   if (my $storage = eval { $schema->storage }) {
     # cannot drop a table if it has been used, have to reconnect first
     $schema->storage->disconnect;