Revision history for DBIx::Class
- - Add DBIC_MULTICREATE_DEBUG env var (undocumented, quasi-internal)
- - Fix up multi-create to:
- - correctly propagate columns loaded during multi-insert of rels
- - not try and insert things tagged on via new_related unless required
- Possible to set locale in IC::DateTime extra => {} config
- - Calling the accessor of a belongs_to when the foreign_key
- was NULL and the row was not stored would unexpectedly fail (groditi)
- - Split sql statements for deploy only if SQLT::Producer returned a scalar
- containing all statements to be executed
- - Add as_query() for ResultSet and ResultSetColumn. This makes subqueries
- possible. See the Cookbook for details. (robkinyon, michaelr)
0.08099_06 2009-01-23 07:30:00 (UTC)
- Allow a scalarref to be supplied to the 'from' resultset attribute
- PG array datatype supported with SQLA >= 1.50
- insert should use store_column, not set_column to avoid marking
clean just-stored values as dirty. New test for this (groditi)
- - regression test for source_name (groditi)
0.08099_05 2008-10-30 21:30:00 (UTC)
- Rewritte of Storage::DBI::connect_info(), extended with an
rjbs: Ricardo Signes <rjbs@cpan.org>
-robkinyon: Rob Kinyon <rkinyon@cpan.org>
-
sc_: Just Another Perl Hacker
scotty: Scotty Allen <scotty@scottyallen.com>
$resultset->search(
{
- numbers => \[ '= ?', [numbers => [1, 2, 3]] ]
+ numbers => \[ '= ?', [1, 2, 3] ]
}
);
See L<SQL::Abstract/array_datatypes> and L<SQL::Abstract/Literal SQL with
-placeholders and bind values (subqueries)> for more explanation. Note that
-L<DBIx::Class> sets L<SQL::Abstract/bindtype> to C<columns>, so you must pass
-the bind values (the C<[1, 2, 3]> arrayref in the above example) wrapped in
-arrayrefs together with the column name, like this: C<< [column_name => value]
->>.
+placeholders and bind values (subqueries)> for more explanation.
=head1 BOOTSTRAPPING/MIGRATING
$rel_info->{cond}, $rel, $self
);
if ($rel_info->{attrs}->{undef_on_null_fk}){
- return unless ref($cond) eq 'HASH';
return if grep { not defined } values %$cond;
}
my $val = $self->find_related($rel, {}, {});
local *Class::C3::reinitialize = sub { };
use warnings 'redefine';
- foreach my $result (keys %results) {
+ # ensure classes are loaded and fetch properly sorted classes
+ $class->ensure_class_loaded($_) foreach(values %results);
+ my @subclass_last = sort { $results{$a}->isa($results{$b}) } keys(%results);
+
+ foreach my $result (@subclass_last) {
my $result_class = $results{$result};
- $class->ensure_class_loaded($result_class);
my $rs_class = delete $resultsets{$result};
my $rs_set = $result_class->resultset_class;
+
if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') {
if($rs_class && $rs_class ne $rs_set) {
warn "We found ResultSet class '$rs_class' for '$result', but it seems "
sub _safely_ensure_connected {
my ($self, $replicant, @args) = @_;
- eval {
- $replicant->ensure_connected(@args);
- };
- if ($@) {
+ my $return; eval {
+ $return = $replicant->ensure_connected(@args);
+ }; if ($@) {
$replicant
- ->debugobj
- ->print(
- sprintf( "Exception trying to ->ensure_connected for replicant %s, error is %s",
- $replicant->_dbi_connect_info->[0], $@)
+ ->debugobj
+ ->print(
+ sprintf( "Exception trying to ->ensure_connected for replicant %s, error is %s",
+ $self->_dbi_connect_info->[0], $@)
);
- return;
}
- return 1;
+ return $return;
}
=head2 connected_replicants
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+use lib 't/lib';
+
+plan tests => 4;
+
+sub _chk_warning {
+ defined $_[0]?
+ $_[0] !~ qr/We found ResultSet class '([^']+)' for '([^']+)', but it seems that you had already set '([^']+)' to use '([^']+)' instead/ :
+ 1
+}
+
+my $warnings;
+eval {
+ local $SIG{__WARN__} = sub { $warnings .= shift };
+ package DBICNSTest::RtBug41083;
+ use base 'DBIx::Class::Schema';
+ __PACKAGE__->load_namespaces(
+ result_namespace => 'Schema_A',
+ resultset_namespace => 'ResultSet_A',
+ default_resultset_class => 'ResultSet'
+ );
+};
+ok(!$@) or diag $@;
+ok(_chk_warning($warnings), 'expected no complaint');
+
+eval {
+ local $SIG{__WARN__} = sub { $warnings .= shift };
+ package DBICNSTest::RtBug41083;
+ use base 'DBIx::Class::Schema';
+ __PACKAGE__->load_namespaces(
+ result_namespace => 'Schema',
+ resultset_namespace => 'ResultSet',
+ default_resultset_class => 'ResultSet'
+ );
+};
+ok(!$@) or diag $@;
+ok(_chk_warning($warnings), 'expected no complaint') or diag $warnings;
my $schema = DBICTest->init_schema();
-plan tests => 69;
+plan tests => 74;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
my $count;
lives_ok {
$count = $schema->resultset('ArrayTest')->search({
- arrayfield => \[ '= ?' => [arrayfield => [3, 4]] ], #TODO anything less ugly than this?
+ arrayfield => \[ '= ?' => [3, 4] ], #TODO anything less ugly than this?
})->count;
} 'comparing arrayref to pg array data does not blow up';
is($count, 1, 'comparing arrayref to pg array data gives correct result');
my $schema = DBICTest->init_schema;
-plan tests => 133;
+plan tests => 132;
my $translator = SQL::Translator->new(
parser_args => {
$schema->source('Track')->sqlt_deploy_callback(sub {
my ($self, $sqlt_table) = @_;
- if ($schema->storage->sqlt_type eq 'SQLite' ) {
+ if ($sqlt_table->schema->translator->producer_type =~ /SQLite$/ ) {
$sqlt_table->add_index( name => 'track_title', fields => ['title'] )
or die $sqlt_table->error;
}
$dbh->do('DROP TABLE IF EXISTS bindtype_test');
# the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
+
+ # the blob/clob are for reference only, will be useful when we switch to SQLT and can test Oracle along the way
$dbh->do(qq[
CREATE TABLE bindtype_test
(
],{ RaiseError => 1, PrintError => 1 });
}
-my $big_long_string = "\x00\x01\x02 abcd" x 125000;
-
-my $new;
-# test inserting a row
-{
- $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
-
- ok($new->id, "Created a bytea row");
- is($new->bytea, $big_long_string, "Set the blob correctly.");
-}
-
# test retrieval of the bytea column
{
my $row = $schema->resultset('BindType')->find({ id => $new->id });
is($row->get_column('bytea'), $big_long_string, "Created the blob correctly.");
}
-TODO: {
- local $TODO =
- 'Passing bind attributes to $sth->bind_param() should be implemented (it only works in $storage->insert ATM)';
+my $new = $schema->resultset('BindType')->create({ bytea => $big_long_string });
- my $rs = $schema->resultset('BindType')->search({ bytea => $big_long_string });
+ok($new->id, "Created a bytea row");
+is($new->bytea, $big_long_string, "Set the blob correctly.");
- # search on the bytea column (select)
- {
- my $row = $rs->first;
- is($row ? $row->id : undef, $new->id, "Found the row searching on the bytea column.");
- }
+my $rs = $schema->resultset('BindType')->find({ id => $new->id });
- # search on the bytea column (update)
- {
- my $new_big_long_string = $big_long_string . "2";
- $schema->txn_do(sub {
- $rs->update({ bytea => $new_big_long_string });
- my $row = $schema->resultset('BindType')->find({ id => $new->id });
- is($row ? $row->get_column('bytea') : undef, $new_big_long_string,
- "Updated the row correctly (searching on the bytea column)."
- );
- $schema->txn_rollback;
- });
- }
+is($rs->get_column('bytea'), $big_long_string, "Created the blob correctly.");
- # search on the bytea column (delete)
- {
- $schema->txn_do(sub {
- $rs->delete;
- my $row = $schema->resultset('BindType')->find({ id => $new->id });
- is($row, undef, "Deleted the row correctly (searching on the bytea column).");
- $schema->txn_rollback;
- });
- }
-}
+$dbh->do("DROP TABLE bindtype_test");
$dbh->do("DROP TABLE bindtype_test");
our @EXPORT = qw/
&is_same_sql_bind
- &is_same_sql
- &is_same_bind
&eq_sql
&eq_bind
- &eq_sql_bind
/;
$tb->ok($same_sql && $same_bind, $msg);
if (!$same_sql) {
- _sql_differ_diag($sql1, $sql2);
+ $tb->diag("SQL expressions differ\n"
+ . " got: $sql1\n"
+ . "expected: $sql2\n"
+ );
}
if (!$same_bind) {
- _bind_differ_diag($bind_ref1, $bind_ref2);
+ $tb->diag("BIND values differ\n"
+ . " got: " . Dumper($bind_ref1)
+ . "expected: " . Dumper($bind_ref2)
+ );
}
}
- sub is_same_sql
- {
- my ($sql1, $sql2, $msg) = @_;
-
- my $same_sql = eq_sql($sql1, $sql2);
-
- $tb->ok($same_sql, $msg);
-
- if (!$same_sql) {
- _sql_differ_diag($sql1, $sql2);
- }
- }
-
- sub is_same_bind
- {
- my ($bind_ref1, $bind_ref2, $msg) = @_;
-
- my $same_bind = eq_bind($bind_ref1, $bind_ref2);
-
- $tb->ok($same_bind, $msg);
-
- if (!$same_bind) {
- _bind_differ_diag($bind_ref1, $bind_ref2);
- }
- }
-
- sub _sql_differ_diag
- {
- my ($sql1, $sql2) = @_;
-
- $tb->diag("SQL expressions differ\n"
- . " got: $sql1\n"
- . "expected: $sql2\n"
- );
- }
-
- sub _bind_differ_diag
- {
- my ($bind_ref1, $bind_ref2) = @_;
-
- $tb->diag("BIND values differ\n"
- . " got: " . Dumper($bind_ref1)
- . "expected: " . Dumper($bind_ref2)
- );
- }
-
sub eq_sql
{
my ($left, $right) = @_;
return eq_deeply($bind_ref1, $bind_ref2);
}
-
- sub eq_sql_bind
- {
- my ($sql1, $bind_ref1, $sql2, $bind_ref2) = @_;
-
- return eq_sql($sql1, $sql2) && eq_bind($bind_ref1, $bind_ref2);
- }
}
eval "use SQL::Abstract::Test;";
# SQL::Abstract::Test available
*is_same_sql_bind = \&SQL::Abstract::Test::is_same_sql_bind;
- *is_same_sql = \&SQL::Abstract::Test::is_same_sql;
- *is_same_bind = \&SQL::Abstract::Test::is_same_bind;
*eq_sql = \&SQL::Abstract::Test::eq_sql;
*eq_bind = \&SQL::Abstract::Test::eq_bind;
- *eq_sql_bind = \&SQL::Abstract::Test::eq_sql_bind;
} else {
# old SQL::Abstract
*is_same_sql_bind = \&DBIC::SqlMakerTest::SQLATest::is_same_sql_bind;
- *is_same_sql = \&DBIC::SqlMakerTest::SQLATest::is_same_sql;
- *is_same_bind = \&DBIC::SqlMakerTest::SQLATest::is_same_bind;
*eq_sql = \&DBIC::SqlMakerTest::SQLATest::eq_sql;
*eq_bind = \&DBIC::SqlMakerTest::SQLATest::eq_bind;
- *eq_sql_bind = \&DBIC::SqlMakerTest::SQLATest::eq_sql_bind;
}
Compares given and expected pairs of C<($sql, \@bind)>, and calls
L<Test::Builder/ok> on the result, with C<$test_msg> as message.
-=head2 is_same_sql
-
- is_same_sql(
- $given_sql,
- $expected_sql,
- $test_msg
- );
-
-Compares given and expected SQL statement, and calls L<Test::Builder/ok> on the
-result, with C<$test_msg> as message.
-
-=head2 is_same_bind
-
- is_same_bind(
- \@given_bind,
- \@expected_bind,
- $test_msg
- );
-
-Compares given and expected bind value lists, and calls L<Test::Builder/ok> on
-the result, with C<$test_msg> as message.
-
=head2 eq_sql
my $is_same = eq_sql($given_sql, $expected_sql);
Compares two lists of bind values. Returns true IFF their values are the same.
-=head2 eq_sql_bind
-
- my $is_same = eq_sql_bind(
- $given_sql, \@given_bind,
- $expected_sql, \@expected_bind
- );
-
-Compares the two SQL statements and the two lists of bind values. Returns true
-IFF they are equivalent and the bind values are the same.
-
=head1 SEE ALSO
--- /dev/null
+package DBICNSTest::RtBug41083::ResultSet;
+use strict;
+use warnings;
+use base 'DBIx::Class::ResultSet';
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::ResultSet::Foo;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::ResultSet';
+
+sub fooBar { 1; }
+
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::ResultSet_A::A;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::ResultSet';
+
+sub fooBar { 1; }
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::Schema::Foo;
+use strict;
+use warnings;
+use base 'DBIx::Class';
+__PACKAGE__->load_components('Core');
+__PACKAGE__->table('foo');
+__PACKAGE__->add_columns('foo');
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::Schema::Foo::Sub;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::Schema::Foo';
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::Schema_A::A;
+use strict;
+use warnings;
+use base 'DBIx::Class';
+__PACKAGE__->load_components('Core');
+__PACKAGE__->table('a');
+__PACKAGE__->add_columns('a');
+1;
--- /dev/null
+package DBICNSTest::RtBug41083::Schema_A::A::Sub;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::Schema_A::A';
+1;
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Sat Jan 24 19:42:15 2009
+-- Created on Sat Jan 17 19:40:47 2009
--
BEGIN TRANSACTION;
CREATE INDEX cd_artwork_idx_cd_id_cd_artwor ON cd_artwork (cd_id);
--
--- Table: artwork_to_artist
---
-CREATE TABLE artwork_to_artist (
- artwork_cd_id integer NOT NULL,
- artist_id integer NOT NULL,
- PRIMARY KEY (artwork_cd_id, artist_id)
-);
-
-CREATE INDEX artwork_to_artist_idx_artist_id_artwork_to_arti ON artwork_to_artist (artist_id);
-CREATE INDEX artwork_to_artist_idx_artwork_cd_id_artwork_to_ ON artwork_to_artist (artwork_cd_id);
-
---
-- Table: bindtype_test
--
CREATE TABLE bindtype_test (