Merge 'sybase_mssql' into 'trunk'
Justin Hunter [Tue, 5 May 2009 07:27:56 +0000 (07:27 +0000)]
r6037@mullet (orig r6036):  arcanez | 2009-04-30 01:24:41 -0700
branch to work on Sybase/MSSQL subtleties
r6038@mullet (orig r6037):  arcanez | 2009-04-30 01:27:11 -0700
jump to ::DBI::Sybase::MSSQL if we are using MSSQL through Sybase
r6062@mullet (orig r6061):  arcanez | 2009-04-30 14:05:24 -0700
fixes for MSSQL via Sybase
r6126@mullet (orig r6125):  arcanez | 2009-05-05 00:27:13 -0700
add a line to Changes and add a CAVEAT

Changes
lib/DBIx/Class/Storage/DBI/Sybase.pm
lib/DBIx/Class/Storage/DBI/Sybase/MSSQL.pm
lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm [new file with mode: 0644]
t/74mssql.t

diff --git a/Changes b/Changes
index 13bb6d8..58c5737 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for DBIx::Class
 
+        - Refactor DBIx::Class::Storage::DBI::Sybase to automatically 
+          load a subclass, namely Microsoft_SQL_Server.pm
+          (similar to DBIx::Class::Storage::DBI::ODBC) 
+
 0.08102 2009-04-30 08:29:00 (UTC)
         - Fixed two subtle bugs when using columns or select/as
           paired with a join (limited prefetch)
index 87acdde..f1a8dc8 100644 (file)
@@ -5,6 +5,20 @@ use warnings;
 
 use base qw/DBIx::Class::Storage::DBI::NoBindVars/;
 
+sub _rebless {
+    my $self = shift;
+
+    my $dbtype = eval { @{$self->_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] };
+    unless ( $@ ) {
+        $dbtype =~ s/\W/_/gi;
+        my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}";
+        if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
+            bless $self, $subclass;
+            $self->_rebless;
+        }
+    }
+}
+
 1;
 
 =head1 NAME
@@ -17,10 +31,21 @@ This subclass supports L<DBD::Sybase> for real Sybase databases.  If
 you are using an MSSQL database via L<DBD::Sybase>, see
 L<DBIx::Class::Storage::DBI::Sybase::MSSQL>.
 
+=head1 CAVEATS
+
+This storage driver uses L<DBIx::Class::Storage::DBI::NoBindVars> as a base.
+This means that bind variables will be interpolated (properly quoted of course)
+into the SQL query itself, without using bind placeholders.
+
+More importantly this means that caching of prepared statements is explicitly
+disabled, as the interpolation renders it useless.
+
 =head1 AUTHORS
 
 Brandon L Black <blblack@gmail.com>
 
+Justin Hunter <justin.d.hunter@gmail.com>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
index 81222e9..f4eee43 100644 (file)
@@ -3,8 +3,7 @@ package DBIx::Class::Storage::DBI::Sybase::MSSQL;
 use strict;
 use warnings;
 
-use Class::C3;
-use base qw/DBIx::Class::Storage::DBI::MSSQL DBIx::Class::Storage::DBI::Sybase/;
+use base qw/DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server DBIx::Class::Storage::DBI::Sybase/;
 
 1;
 
@@ -29,6 +28,8 @@ after connecting.
 
 Brandon L Black <blblack@gmail.com>
 
+Justin Hunter <justin.d.hunter@gmail.com>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
new file mode 100644 (file)
index 0000000..d4485a3
--- /dev/null
@@ -0,0 +1,41 @@
+package DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server;
+
+use strict;
+use warnings;
+
+use base qw/DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server DBIx::Class::Storage::DBI::Sybase/;
+
+1;
+
+=head1 NAME
+
+DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Storage::DBI subclass for MSSQL via
+DBD::Sybase
+
+=head1 SYNOPSIS
+
+This subclass supports MSSQL connected via L<DBD::Sybase>.
+
+  $schema->storage_type('::DBI::Sybase::Microsoft_SQL_Server');
+  $schema->connect_info('dbi:Sybase:....', ...);
+
+=head1 CAVEATS
+
+This storage driver uses L<DBIx::Class::Storage::DBI::NoBindVars> as a base.
+This means that bind variables will be interpolated (properly quoted of course)
+into the SQL query itself, without using bind placeholders.
+
+More importantly this means that caching of prepared statements is explicitly
+disabled, as the interpolation renders it useless.
+
+=head1 AUTHORS
+
+Brandon L Black <blblack@gmail.com>
+
+Justin Hunter <justin.d.hunter@gmail.com>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
index 92b3103..49f7967 100644 (file)
@@ -7,23 +7,18 @@ use DBICTest;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
 
-#warn "$dsn $user $pass";
-
 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'
   unless ($dsn);
 
-plan tests => 5;
-
-my $storage_type = '::DBI::MSSQL';
-$storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/;
-# Add more for others in the future when they exist (ODBC? ADO? JDBC?)
+plan tests => 6;
 
 my $schema = DBICTest::Schema->clone;
-$schema->storage_type($storage_type);
 $schema->connection($dsn, $user, $pass);
 
 my $dbh = $schema->storage->dbh;
 
+isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server');
+
 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
     DROP TABLE artist");
 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL