- New resultsed method count_rs, returns a ::ResultSetColumn
which in turn returns a single count value
- Even better support of count with limit
+ - New on_connect_call/on_disconnect_call functionality (check
+ POD of Storage::DBI)
+ - Automatic datetime handling environment/session setup for
+ Oracle via connect_call_datetime_setup()
+ - MySQL can now be turned into a sane database by adding
+ { on_connect_call => 'set_ansi_mode' } to the connect() call
- count/all on related left-joined empty resultsets now correctly
returns 0/()
- Fixed regression when both page and offset are specified on
- Storage::DBI::connected() improvements for Oracle and Sybase
- Fixed prefetch+incomplete select regression introduced in
0.08100
+ - MSSQL limit (TOP emulation) fixes and improvements
0.08107 2009-06-14 08:21:00 (UTC)
- Fix serialization regression introduced in 0.08103 (affects
$sub_attrs->{from}, $sub_attrs->{alias}
);
+ # this is so that ordering can be thrown away in things like Top limit
+ $sub_attrs->{-for_count_only} = 1;
+
+ my $sub_rs = $rsrc->resultset_class->new ($rsrc, $sub_attrs);
+
$attrs->{from} = [{
- count_subq => $rsrc->resultset_class->new ($rsrc, $sub_attrs )->as_query
+ -alias => 'count_subq',
+ -source_handle => $rsrc->handle,
+ count_subq => $sub_rs->as_query,
}];
# the subquery replaces this
can also be passed an object representing the foreign row, and the
value will be set to its primary key.
-To create related objects, pass a hashref for the value if the related
-item is a foreign key relationship (L<DBIx::Class::Relationship/belongs_to>),
-and use the name of the relationship as the key. (NOT the name of the field,
-necessarily). For C<has_many> and C<has_one> relationships, pass an arrayref
-of hashrefs containing the data for each of the rows to create in the foreign
-tables, again using the relationship name as the key.
+To create related objects, pass a hashref of related-object column values
+B<keyed on the relationship name>. If the relationship is of type C<multi>
+(L<DBIx::Class::Relationship/has_many>) - pass an arrayref of hashrefs.
+The process will correctly identify columns holding foreign keys, and will
+transparrently populate them from the keys of the corresponding relation.
+This can be applied recursively, and will work correctly for a structure
+with an arbitrary depth and width, as long as the relationships actually
+exists and the correct column data has been supplied.
+
Instead of hashrefs of plain related data (key/value pairs), you may
also pass new or inserted objects. New objects (not inserted yet, see
];
}
- if ( $attrs->{order_by} ) {
+ if ( defined $attrs->{order_by} ) {
$attrs->{order_by} = (
ref( $attrs->{order_by} ) eq 'ARRAY'
? [ @{ $attrs->{order_by} } ]
- : [ $attrs->{order_by} ]
+ : [ $attrs->{order_by} || () ]
);
}
$attrs->{group_by} = [ $attrs->{group_by} ];
}
- # If the order_by is otherwise empty - we will use this for TOP limit
- # emulation and the like.
- # Although this is needed only if the order_by is not defined, it is
- # actually cheaper to just populate this rather than properly examining
- # order_by (stuf like [ {} ] and the like)
- $attrs->{_virtual_order_by} = [ $self->result_source->primary_columns ];
-
-
$attrs->{collapse} ||= {};
if ( my $prefetch = delete $attrs->{prefetch} ) {
$prefetch = $self->_merge_attr( {}, $prefetch );
push @{ $attrs->{select} }, @{$attrs->{prefetch_select}};
push @{ $attrs->{as} }, (map { $_->[1] } @prefetch);
- push( @{ $attrs->{order_by} }, @$prefetch_ordering );
+ push( @{$attrs->{order_by}}, @$prefetch_ordering );
$attrs->{_collapse_order_by} = \@$prefetch_ordering;
}
use strict;
use warnings;
- use base qw/DBIx::Class::Storage::DBI::MultiColumnIn/;
+ use base qw/
+ DBIx::Class::Storage::DBI::MultiColumnIn
+ DBIx::Class::Storage::DBI::AmbiguousGlob
+ DBIx::Class::Storage::DBI
+ /;
+ use mro 'c3';
__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL');
sub with_deferred_fk_checks {
my ($self, $sub) = @_;
- $self->dbh->do('SET foreign_key_checks=0');
+ $self->_do_query('SET FOREIGN_KEY_CHECKS = 0');
$sub->();
- $self->dbh->do('SET foreign_key_checks=1');
+ $self->_do_query('SET FOREIGN_KEY_CHECKS = 1');
}
sub connect_call_set_ansi_mode {
my $self = shift;
- $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
- $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
+ $self->_do_query(q|SET SQL_MODE = 'ANSI,TRADITIONAL'|);
+ $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
}
sub _dbh_last_insert_id {
$self->dbh->do("ROLLBACK TO SAVEPOINT $name")
}
-
+
sub is_replicating {
my $status = shift->dbh->selectrow_hashref('show slave status');
return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
return shift->_per_row_update_delete (@_);
}
- # MySql chokes on things like:
- # COUNT(*) FROM (SELECT tab1.col, tab2.col FROM tab1 JOIN tab2 ... )
- # claiming that col is a duplicate column (it loses the table specifiers by
- # the time it gets to the *). Thus for any subquery count we select only the
- # primary keys of the main table in the inner query. This hopefully still
- # hits the indexes and keeps mysql happy.
- # (mysql does not care if the SELECT and the GROUP BY match)
- sub _subq_count_select {
- my ($self, $source, $rs_attrs) = @_;
- my @pcols = map { join '.', $rs_attrs->{alias}, $_ } ($source->primary_columns);
- return @pcols ? \@pcols : [ 1 ];
- }
-
1;
=head1 NAME