use base qw/DBIx::Class::Storage::DBI/;
+use Carp::Clan qw/^DBIx::Class/;
+
sub _rebless {
my $self = shift;
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;
- }
-
- $self->dbh->syb_date_fmt('ISO_strict');
- $self->dbh->do('set dateformat mdy');
+ } elsif (not $self->dbh->{syb_dynamic_supported}) {
+# probably real Sybase
+ bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
+ $self->_rebless;
}
}
}
-sub _dbh_last_insert_id {
- my ($self, $dbh, $source, $col) = @_;
+{
+ 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');
- 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];
+ 1;
}
+}
+
+sub _dbh_last_insert_id {
+ my ($self, $dbh, $source, $col) = @_;
# sorry, there's no other way!
my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
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;
+
+for my $storage_type (@storage_types) {
+ $schema = DBICTest::Schema->clone;
+
+ 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::DBI::Sybase' );
+ $schema->storage->ensure_connected;
-$schema->storage->dbh_do (sub {
- my ($storage, $dbh) = @_;
- eval { $dbh->do("DROP TABLE artist") };
- eval { $dbh->do("DROP TABLE track") };
- $dbh->do(<<'SQL');
+ 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),
SQL
# we only need the DT
- $dbh->do(<<'SQL');
+ $dbh->do(<<'SQL');
CREATE TABLE track (
trackid INT IDENTITY PRIMARY KEY,
cd INT,
last_updated_on DATETIME,
)
SQL
+ });
-});
-
-my %seen_id;
+ my %seen_id;
-# fresh $schema so we start unconnected
-$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
+# so we start unconnected
+ $schema->storage->disconnect;
# 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
-
-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' );
+ ok(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' );
+ }
+}
# 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');
+ }
}