Revision history for DBIx::Class
+0.08107 2009-06-14 08:21:00 (UTC)
+ - Fix serialization regression introduced in 0.08103 (affects
+ Cursor::Cached)
+ - POD fixes
+ - Fixed incomplete ::Replicated debug output
+
0.08106 2009-06-11 21:42:00 (UTC)
- Switched SQLite storage driver to DateTime::Format::SQLite
(proper timezone handling)
# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
# brain damage and presumably various other packaging systems too
-$VERSION = '0.08106';
+$VERSION = '0.08107';
$VERSION = eval $VERSION; # numify for warning-free dev releases
my $attrs = $self->_resolved_attrs_copy;
- my ($sqlbind, $bind_attrs) = $self->result_source->storage
+ # For future use:
+ #
+ # in list ctx:
+ # my ($sql, \@bind, \%dbi_bind_attrs) = _select_args_to_query (...)
+ # $sql also has no wrapping parenthesis in list ctx
+ #
+ my $sqlbind = $self->result_source->storage
->_select_args_to_query ($attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs);
return $sqlbind;
# SELECT child.* FROM person child
# INNER JOIN person father ON child.father_id = father.id
-If you need to express really complex joins or you need a subselect, you
+You can select from a subquery by passing a resultset to from as follows.
+
+ $schema->resultset('Artist')->search(
+ undef,
+ { alias => 'artist2',
+ from => [ { artist2 => $artist_rs->as_query } ],
+ } );
+
+ # and you'll get sql like this..
+ # SELECT artist2.artistid, artist2.name, artist2.rank, artist2.charfield FROM
+ # ( SELECT me.artistid, me.name, me.rank, me.charfield FROM artists me ) artist2
+
+If you need to express really complex joins, you
can supply literal SQL to C<from> via a scalar reference. In this case
-the contents of the scalar will replace the table name asscoiated with the
+the contents of the scalar will replace the table name associated with the
resultsource.
WARNING: This technique might very well not work as expected on chained
Inserts a new row into the database, as a copy of the original
object. If a hashref of replacement data is supplied, these will take
-precedence over data in the original.
+precedence over data in the original. Also any columns which have
+the L<column info attribute|DBIx::Class::ResultSource/add_columns>
+C<< is_auto_increment => 1 >> are explicitly removed before the copy,
+so that the database can insert its own autoincremented values into
+the new object.
Relationships will be followed by the copy procedure B<only> if the
relationship specifes a true value for its
sub _select {
my $self = shift;
+
+ # localization is neccessary as
+ # 1) there is no infrastructure to pass this around (easy to do, but will wait)
+ # 2) _select_args sets it and _prep_for_execute consumes it
my $sql_maker = $self->sql_maker;
+ local $sql_maker->{for};
+
return $self->_execute($self->_select_args(@_));
}
sub _select_args_to_query {
my $self = shift;
+ # localization is neccessary as
+ # 1) there is no infrastructure to pass this around (easy to do, but will wait)
+ # 2) _select_args sets it and _prep_for_execute consumes it
+ my $sql_maker = $self->sql_maker;
+ local $sql_maker->{for};
+
# my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset)
# = $self->_select_args($ident, $select, $cond, $attrs);
my ($op, $bind, $ident, $bind_attrs, @args) =
# my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]);
my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, \@args);
+ $prepared_bind ||= [];
- return \[ "($sql)", @{ $prepared_bind || [] }];
+ return wantarray
+ ? ($sql, $prepared_bind, $bind_attrs)
+ : \[ "($sql)", @$prepared_bind ]
+ ;
}
sub _select_args {
my ($self, $ident, $select, $condition, $attrs) = @_;
- my $for = delete $attrs->{for};
my $sql_maker = $self->sql_maker;
-
- local $sql_maker->{for} = $for;
+ $sql_maker->{for} = delete $attrs->{for};
my $order = { map
{ $attrs->{$_} ? ( $_ => $attrs->{$_} ) : () }
$res = $self->$next($info, @extra);
}
- # May have to reapply role if master will be reblessed to a more specific
- # driver.
- $self->master->_determine_driver;
- DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($self->master);
+ # Make sure master is blessed into the correct class and apply role to it.
+ my $master = $self->master;
+ $master->_determine_driver;
+ Moose::Meta::Class->initialize(ref $master);
+ DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($master);
$wantarray ? @res : $res;
};
sub _build_master {
my $self = shift @_;
my $master = DBIx::Class::Storage::DBI->new($self->schema);
- DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($master);
$master
}