my $rs = $schema->resultset ('Artist');
my $storage = $schema->storage;
- ok ($storage->connected, 'we are connected');
-
my $row_obj = $rs->search({}, { rows => 1})->next; # so that commits/rollbacks work
ok ($row_obj, 'row from db');
{ order_by => 'title',
rows => 3 }
);
-my $page = $it->page(2);
-is( $page->count, 2, "standard resultset paged rs count ok" );
+{
+ my $page = $it->page(2);
-is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
+ is( $page->count, 2, "standard resultset paged rs count ok" );
+ is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
+}
# test software-based limit paging
$it = $rs->search(
is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds');
is ($subsel->next->title, $cds->next->title, 'First CD title match');
is ($subsel->next->title, $cds->next->title, 'Second CD title match');
+$cds->reset;
is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');
cmp_ok($rs_year->sum, '==', 9996, "three artists returned");
-my $rso_year = $rs->search({}, { order_by => 'cdid' })->get_column('year');
-is($rso_year->next, 1999, "reset okay");
+{
+ my $rso_year = $rs->search({}, { order_by => 'cdid' })->get_column('year');
+ is($rso_year->next, 1999, "reset okay");
-is($rso_year->first, 1999, "first okay");
+ is($rso_year->first, 1999, "first okay");
-warnings_exist (sub {
- is($rso_year->single, 1999, "single okay");
-}, qr/Query returned more than one row/, 'single warned');
+ warnings_exist (sub {
+ is($rso_year->single, 1999, "single okay");
+ }, qr/Query returned more than one row/, 'single warned');
+}
# test distinct propagation
no_deploy => 1, # Deploying would cause an early rebless
);
+ my $storage = $schema->storage;
+
is(
- ref $schema->storage, 'DBIx::Class::Storage::DBI',
+ ref $storage, 'DBIx::Class::Storage::DBI',
'Starting with generic storage'
);
# Calling date_time_parser should cause the storage to be reblessed,
# so that we can pick up datetime_parser_type from subclasses
- my $parser = $schema->storage->datetime_parser();
+ my $parser = $storage->datetime_parser();
is($parser, 'DateTime::Format::SQLite', 'Got expected storage-set datetime_parser');
- isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage');
+ isa_ok($storage, 'DBIx::Class::Storage::DBI::SQLite', 'storage');
- ok(! $schema->storage->connected, 'Not yet connected');
+ ok(! $storage->connected, 'Not yet connected');
}
# so user's env doesn't screw us
);
#===== make sure make_column_dirty interacts reasonably with inflation
-$object = $rs->first;
+$object = $rs->search({}, { rows => 1 })->next;
$object->update ({serialized => { x => 'y'}});
$object->serialized->{x} = 'z'; # change state without notifying $object
my $schema;
+ my @dsn = $self->_database(%args);
+
if ($args{compose_connection}) {
$need_global_cleanup = 1;
$schema = DBICTest::Schema->compose_connection(
- 'DBICTest', $self->_database(%args)
+ 'DBICTest', @dsn
);
} else {
$schema = DBICTest::Schema->compose_namespace('DBICTest');
}
if ( !$args{no_connect} ) {
- $schema = $schema->connect($self->_database(%args));
+ $schema->connection(@dsn);
}
if ( !$args{no_deploy} ) {
use Fcntl qw(:DEFAULT :seek :flock);
use Time::HiRes 'sleep';
+use Scope::Guard ();
use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry);
use DBICTest::Util 'local_umask';
use namespace::clean;
local *DBIx::Class::Storage::DBI::_format_for_trace = sub { $_[1] };
Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
+ # can not use local() due to an unknown number of storages
+ # (think replicated)
+ my $orig_states = { map
+ { $_ => $self->storage->$_ }
+ qw(debugcb debugobj debug)
+ };
+
+ my $sg = Scope::Guard->new(sub {
+ $self->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
+ });
- local $self->storage->{debugcb};
- local $self->storage->{debugobj} = my $tracer_obj = DBICTest::SQLTracerObj->new;
- local $self->storage->{debug} = 1;
+ $self->storage->debugcb(undef);
+ $self->storage->debugobj( my $tracer_obj = DBICTest::SQLTracerObj->new );
+ $self->storage->debug(1);
local $Test::Builder::Level = $Test::Builder::Level + 2;
$cref->();
my $cd_title = "Test $type cd";
my $artist_names = [ map { "Artist via $type $_" } (1, 2) ];
- my $someartist = $artist_rs->next;
+ my $someartist = $artist_rs->search({}, { rows => 1 })->next;
lives_ok (sub {
my $cd = $schema->resultset('CD')->create ({
is($rs->next->name, 'Caterwauler McCrae', "Correct artist returned");
-$cd = $schema->resultset('Artist')->first->create_related('cds',
+$cd = $schema->resultset('Artist')->search({ artistid => 1 })->first->create_related('cds',
{
title => 'Unproduced Single',
year => 2007
# try the same sql with forced multicolumn in
$schema->is_executed_sql_bind( sub {
- local $schema->storage->{_use_multicolumn_in} = 1;
+
+ my $orig_umi = $schema->storage->_use_multicolumn_in;
+ my $sg = Scope::Guard->new(sub {
+ $schema->storage->_use_multicolumn_in($orig_umi);
+ });
+
+ $schema->storage->_use_multicolumn_in(1);
# this can't actually execute on sqlite
eval { $fks_multi->update ({ read_count => \ 'read_count + 1' }) };
# test nested aliasing
my $res = 'original';
-$storage->dbh_do (sub {
+$schema->storage->dbh_do (sub {
shift->dbh_do(sub { $_[3] = 'changed' }, @_)
}, $res);
# Catch the DBI connection error
local $SIG{__WARN__} = sub {};
throws_ok {
- my @art_three = $schema->resultset("Artist")->search( {}, { order_by => { -desc => 'name' } } );
+ $schema->resultset("Artist")->create({ name => 'not gonna happen' });
} qr/not a database/, 'The operation failed';
}
note "Testing $prefix";
- local $schema->storage->{debugobj} = my $stats = DBICTest::SVPTracerObj->new;
- local $schema->storage->{debug} = 1;
+ # can not use local() due to an unknown number of storages
+ # (think replicated)
+ my $orig_states = { map
+ { $_ => $schema->storage->$_ }
+ qw(debugcb debugobj debug)
+ };
+ my $sg = Scope::Guard->new(sub {
+ $schema->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
+ });
+ $schema->storage->debugobj (my $stats = DBICTest::SVPTracerObj->new);
+ $schema->storage->debug (1);
$schema->resultset('Artist')->create({ name => 'foo' });
'rollback from inner transaction';
### cleanupz
- $schema->storage->dbh->do ("DROP TABLE artist");
+ $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
}}
done_testing;
END {
- eval { $schema->storage->dbh->do ("DROP TABLE artist") } if defined $schema;
+ eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
undef $schema;
}
for my $want (0,1) {
my $schema = DBICTest->init_schema;
- is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
+ is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');
my @titles = map {'txn_do test CD ' . $_} (1..5);
my $artist = $schema->resultset('Artist')->find(1);
title => "txn_do test CD $_",
})->first->year, 2006, "new CD $_ year correct") for (1..5);
- is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset');
+ is( $schema->storage->transaction_depth, 0, 'txn depth has been reset');
}
# Test txn_do() @_ aliasing support
{
my $schema = DBICTest->init_schema;
- is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
+ is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');
my $nested_code = sub {
my ($schema, $artist, $code) = @_;
})->first->year, 2006, qq{nested txn_do CD$_ year ok}) for (1..10);
is($artist->cds->count, $count_before+10, 'nested txn_do added all CDs');
- is( $schema->storage->{transaction_depth}, 0, 'txn depth has been reset');
+ is( $schema->storage->transaction_depth, 0, 'txn depth has been reset');
}
# test nested txn_begin on fresh connection
# Test failed txn_do()
for my $pass (1,2) {
- is( $schema->storage->{transaction_depth}, 0, "txn depth starts at 0 (pass $pass)");
+ is( $schema->storage->transaction_depth, 0, "txn depth starts at 0 (pass $pass)");
my $artist = $schema->resultset('Artist')->find(3);
})->first;
ok(!defined($cd), qq{failed txn_do didn't change the cds table (pass $pass)});
- is( $schema->storage->{transaction_depth}, 0, "txn depth has been reset (pass $pass)");
+ is( $schema->storage->transaction_depth, 0, "txn depth has been reset (pass $pass)");
}
# Test failed txn_do() with failed rollback
{
- is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
+ is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');
my $artist = $schema->resultset('Artist')->find(3);
{
my $schema = DBICTest->init_schema();
- is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');
+ is( $schema->storage->transaction_depth, 0, 'txn depth starts at 0');
my $nested_fail_code = sub {
my ($schema, $artist, $code1, $code2) = @_;