[Bast-commits] r6491 - in DBIx-Class/0.08/branches/sybase:
lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Sybase t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Jun 3 23:51:39 GMT 2009
Author: caelum
Date: 2009-06-03 23:51:39 +0000 (Wed, 03 Jun 2009)
New Revision: 6491
Modified:
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm
DBIx-Class/0.08/branches/sybase/t/746sybase.t
Log:
fix Sybase DT stuff and storage bases
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm 2009-06-03 21:21:42 UTC (rev 6490)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm 2009-06-03 23:51:39 UTC (rev 6491)
@@ -5,8 +5,7 @@
use base qw/
DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server
- DBIx::Class::Storage::DBI::Sybase
- DBIx::Class::Storage::DBI::NoBindVars
+ DBIx::Class::Storage::DBI::Sybase::NoBindVars
/;
1;
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm 2009-06-03 21:21:42 UTC (rev 6490)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm 2009-06-03 23:51:39 UTC (rev 6491)
@@ -1,9 +1,16 @@
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::Sybase::NoBindVars;
+package DBIx::Class::Storage::DBI::Sybase::NoBindVars;
use base qw/
DBIx::Class::Storage::DBI::NoBindVars
DBIx::Class::Storage::DBI::Sybase
/;
+sub _dbh_last_insert_id {
+ my ($self, $dbh, $source, $col) = @_;
+
+ # @@identity works only if not using placeholders
+ # Should this query be cached?
+ return ($dbh->selectrow_array('select @@identity'))[0];
+}
+
1;
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-03 21:21:42 UTC (rev 6490)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-03 23:51:39 UTC (rev 6491)
@@ -5,6 +5,8 @@
use base qw/DBIx::Class::Storage::DBI/;
+use Carp::Clan qw/^DBIx::Class/;
+
sub _rebless {
my $self = shift;
@@ -20,27 +22,39 @@
if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
bless $self, $subclass;
$self->_rebless;
- } else { # probably real Sybase
- if (not $self->dbh->{syb_dynamic_supported}) {
- bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
- $self->_rebless;
- }
+ } elsif (not $self->dbh->{syb_dynamic_supported}) {
+# probably real Sybase
+ bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
+ $self->_rebless;
+ }
+ }
+}
- $self->dbh->syb_date_fmt('ISO_strict');
- $self->dbh->do('set dateformat mdy');
+{
+ my $old_dbd_warned = 0;
+
+ sub _populate_dbh {
+ my $self = shift;
+ $self->next::method(@_);
+ my $dbh = $self->_dbh;
+
+ if ($dbh->can('syb_date_fmt')) {
+ $dbh->syb_date_fmt('ISO_strict');
+ } elsif (not $old_dbd_warned) {
+ carp "Your DBD::Sybase is too old to support ".
+ "DBIx::Class::InflateColumn::DateTime, please upgrade!";
+ $old_dbd_warned = 1;
}
+
+ $dbh->do('set dateformat mdy');
+
+ 1;
}
}
sub _dbh_last_insert_id {
my ($self, $dbh, $source, $col) = @_;
- if (not $self->dbh->{syb_dynamic_supported}) {
- # @@identity works only if not using placeholders
- # Should this query be cached?
- return ($dbh->selectrow_array('select @@identity'))[0];
- }
-
# sorry, there's no other way!
my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
return ($dbh->selectrow_array($sth))[0];
Modified: DBIx-Class/0.08/branches/sybase/t/746sybase.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-03 21:21:42 UTC (rev 6490)
+++ DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-03 23:51:39 UTC (rev 6491)
@@ -11,18 +11,31 @@
plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
unless ($dsn && $user);
-plan tests => 15;
+plan tests => 16*2;
-my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
+my @storage_types = (
+ 'DBI::Sybase',
+ 'DBI::Sybase::NoBindVars',
+);
+my $schema;
-$schema->storage->ensure_connected;
-isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::Sybase' );
+for my $storage_type (@storage_types) {
+ $schema = DBICTest::Schema->clone;
-$schema->storage->dbh_do (sub {
- my ($storage, $dbh) = @_;
- eval { $dbh->do("DROP TABLE artist") };
- eval { $dbh->do("DROP TABLE track") };
- $dbh->do(<<'SQL');
+ unless ($storage_type eq 'DBI::Sybase') { # autodetect
+ $schema->storage_type("::$storage_type");
+ }
+ $schema->connection($dsn, $user, $pass, {AutoCommit => 1});
+
+ $schema->storage->ensure_connected;
+
+ isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
+
+ $schema->storage->dbh_do (sub {
+ my ($storage, $dbh) = @_;
+ eval { $dbh->do("DROP TABLE artist") };
+ eval { $dbh->do("DROP TABLE track") };
+ $dbh->do(<<'SQL');
CREATE TABLE artist (
artistid INT IDENTITY PRIMARY KEY,
name VARCHAR(100),
@@ -32,7 +45,7 @@
SQL
# we only need the DT
- $dbh->do(<<'SQL');
+ $dbh->do(<<'SQL');
CREATE TABLE track (
trackid INT IDENTITY PRIMARY KEY,
cd INT,
@@ -40,66 +53,67 @@
last_updated_on DATETIME,
)
SQL
+ });
-});
+ my %seen_id;
-my %seen_id;
+# so we start unconnected
+ $schema->storage->disconnect;
-# fresh $schema so we start unconnected
-$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
-
# test primary key handling
-my $new = $schema->resultset('Artist')->create({ name => 'foo' });
-ok($new->artistid > 0, "Auto-PK worked");
+ my $new = $schema->resultset('Artist')->create({ name => 'foo' });
+ ok($new->artistid > 0, "Auto-PK worked");
-$seen_id{$new->artistid}++;
+ $seen_id{$new->artistid}++;
# test LIMIT support
-for (1..6) {
+ for (1..6) {
$new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
$seen_id{$new->artistid}++;
-}
+ }
-my $it = $schema->resultset('Artist')->search( {}, {
+ my $it = $schema->resultset('Artist')->search( {}, {
rows => 3,
order_by => 'artistid',
-});
+ });
-TODO: {
+ TODO: {
local $TODO = 'Sybase is very very fucked in the limit department';
is( $it->count, 3, "LIMIT count ok" );
-}
+ }
-# The iterator still works correctly with rows => 3, even though the sql is
-# fucked, very interesting.
+ is( $it->next->name, "foo", "iterator->next ok" );
+ $it->next;
+ is( $it->next->name, "Artist 2", "iterator->next ok" );
+ is( $it->next, undef, "next past end of resultset ok" );
-is( $it->next->name, "foo", "iterator->next ok" );
-$it->next;
-is( $it->next->name, "Artist 2", "iterator->next ok" );
-is( $it->next, undef, "next past end of resultset ok" );
+ SKIP: {
+ skip 'quoting bug with NoBindVars', 4
+ if $storage_type eq 'DBI::Sybase::NoBindVars';
# Test DateTime inflation
+ ok(my $dt = DBIx::Class::Storage::DBI::Sybase::DateTime
+ ->parse_datetime('2004-08-21T14:36:48.080Z'));
-my $dt = DBIx::Class::Storage::DBI::Sybase::DateTime
- ->parse_datetime('2004-08-21T14:36:48.080Z');
+ my $row;
+ ok( $row = $schema->resultset('Track')->create({
+ last_updated_on => $dt,
+ cd => 1,
+ }));
+ ok( $row = $schema->resultset('Track')
+ ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
+ ->first
+ );
+ is( $row->updated_date, $dt, 'DateTime inflation works' );
+ }
+}
-my $row;
-ok( $row = $schema->resultset('Track')->create({
- last_updated_on => $dt,
- cd => 1,
-}));
-ok( $row = $schema->resultset('Track')
- ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
- ->first
-);
-is( $row->updated_date, $dt, 'DateTime inflation works' );
-
# clean up our mess
END {
- if (my $dbh = eval { $schema->storage->_dbh }) {
- $dbh->do('DROP TABLE artist');
- $dbh->do('DROP TABLE track');
- }
+ if (my $dbh = eval { $schema->storage->_dbh }) {
+ $dbh->do('DROP TABLE artist');
+ $dbh->do('DROP TABLE track');
+ }
}
More information about the Bast-commits
mailing list