fail_on_internal_wantarray fail_on_internal_call UNRESOLVABLE_CONDITION
);
use DBIx::Class::SQLMaker::Util qw( normalize_sqla_condition extract_equality_conditions );
+use DBIx::Class::ResultSource::FromSpec::Util 'find_join_path_to_alias';
BEGIN {
# De-duplication in _merge_attr() is disabled, but left in for reference
# At this point assume either hashes or arrays
my $rsrc = $self->result_source;
+ my $storage = $rsrc->schema->storage;
if(defined wantarray) {
my (@results, $guard);
# column names only, nothing to do
return if @$data == 1;
- $guard = $rsrc->schema->storage->txn_scope_guard
+ $guard = $storage->txn_scope_guard
if @$data > 2;
@results = map
}
else {
- $guard = $rsrc->schema->storage->txn_scope_guard
+ $guard = $storage->txn_scope_guard
if @$data > 1;
@results = map { $self->new_result($_)->insert } @$data;
### start work
my $guard;
- $guard = $rsrc->schema->storage->txn_scope_guard
+ $guard = $storage->txn_scope_guard
if $slices_with_rels;
### main source data
# FIXME - need to switch entirely to a coderef-based thing,
# so that large sets aren't copied several times... I think
- $rsrc->schema->storage->_insert_bulk(
+ $storage->_insert_bulk(
$rsrc,
[ @$colnames, sort keys %$rs_data ],
[ map {
my $attrs = $self->_chain_relationship($rel);
- my $storage = $rsrc->schema->storage;
-
# Previously this atribute was deleted (instead of being set as it is now)
# Doing so seems to be harmless in all available test permutations
# See also 01d59a6a6 and mst's comment below
#
- $attrs->{alias} = $storage->relname_to_table_alias(
+ $attrs->{alias} = $rsrc->schema->storage->relname_to_table_alias(
$rel,
$attrs->{seen_join}{$rel}
);
# the top of the stack, and if not - make sure the chain is inner-joined down
# to the root.
#
- my $switch_branch = $storage->_find_join_path_to_node(
+ my $switch_branch = find_join_path_to_alias(
$attrs->{from},
$attrs->{alias},
);
refdesc emit_loud_diag
);
use DBIx::Class::SQLMaker::Util qw( normalize_sqla_condition extract_equality_conditions );
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use SQL::Abstract 'is_literal_value';
use Devel::GlobalDestruction;
use Scalar::Util qw( blessed weaken isweak refaddr );
;
my $rel_rsrc = $self->related_source($args->{rel_name});
- my $storage = $self->schema->storage;
if (exists $args->{foreign_values}) {
# there is no way to know who is right and who is left in a cref
# therefore a full blown resolution call, and figure out the
# direction a bit further below
- $colinfos ||= $storage->_resolve_column_info([
+ $colinfos ||= fromspec_columns_info([
{ -alias => $args->{self_alias}, -rsrc => $self },
{ -alias => $args->{foreign_alias}, -rsrc => $rel_rsrc },
]);
--- /dev/null
+package #hide from PAUSE
+ DBIx::Class::ResultSource::FromSpec::Util;
+
+use strict;
+use warnings;
+
+use base 'Exporter';
+our @EXPORT_OK = qw(
+ fromspec_columns_info
+ find_join_path_to_alias
+);
+
+use Scalar::Util 'blessed';
+
+# Takes $fromspec, \@column_names
+#
+# returns { $column_name => \%column_info, ... } for fully qualified and
+# where possible also unqualified variants
+# also note: this adds -result_source => $rsrc to the column info
+#
+# If no columns_names are supplied returns info about *all* columns
+# for all sources
+sub fromspec_columns_info {
+ my ($fromspec, $colnames) = @_;
+
+ return {} if $colnames and ! @$colnames;
+
+ my $sources = (
+ # this is compat mode for insert/update/delete which do not deal with aliases
+ (
+ blessed($fromspec)
+ and
+ $fromspec->isa('DBIx::Class::ResultSource')
+ ) ? +{ me => $fromspec }
+
+ # not a known fromspec - no columns to resolve: return directly
+ : ref($fromspec) ne 'ARRAY' ? return +{}
+
+ : +{
+ # otherwise decompose into alias/rsrc pairs
+ map
+ {
+ ( $_->{-rsrc} and $_->{-alias} )
+ ? ( @{$_}{qw( -alias -rsrc )} )
+ : ()
+ }
+ map
+ {
+ ( ref $_ eq 'ARRAY' and ref $_->[0] eq 'HASH' ) ? $_->[0]
+ : ( ref $_ eq 'HASH' ) ? $_
+ : ()
+ }
+ @$fromspec
+ }
+ );
+
+ $_ = { rsrc => $_, colinfos => $_->columns_info }
+ for values %$sources;
+
+ my (%seen_cols, @auto_colnames);
+
+ # compile a global list of column names, to be able to properly
+ # disambiguate unqualified column names (if at all possible)
+ for my $alias (keys %$sources) {
+ (
+ ++$seen_cols{$_}{$alias}
+ and
+ ! $colnames
+ and
+ push @auto_colnames, "$alias.$_"
+ ) for keys %{ $sources->{$alias}{colinfos} };
+ }
+
+ $colnames ||= [
+ @auto_colnames,
+ ( grep { keys %{$seen_cols{$_}} == 1 } keys %seen_cols ),
+ ];
+
+ my %return;
+ for (@$colnames) {
+ my ($colname, $source_alias) = reverse split /\./, $_;
+
+ my $assumed_alias =
+ $source_alias
+ ||
+ # if the column was seen exactly once - we know which rsrc it came from
+ (
+ $seen_cols{$colname}
+ and
+ keys %{$seen_cols{$colname}} == 1
+ and
+ ( %{$seen_cols{$colname}} )[0]
+ )
+ ||
+ next
+ ;
+
+ DBIx::Class::Exception->throw(
+ "No such column '$colname' on source " . $sources->{$assumed_alias}{rsrc}->source_name
+ ) unless $seen_cols{$colname}{$assumed_alias};
+
+ $return{$_} = {
+ %{ $sources->{$assumed_alias}{colinfos}{$colname} },
+ -result_source => $sources->{$assumed_alias}{rsrc},
+ -source_alias => $assumed_alias,
+ -fq_colname => "$assumed_alias.$colname",
+ -colname => $colname,
+ };
+
+ $return{"$assumed_alias.$colname"} = $return{$_}
+ unless $source_alias;
+ }
+
+ \%return;
+}
+
+sub find_join_path_to_alias {
+ my ($fromspec, $target_alias) = @_;
+
+ # subqueries and other oddness are naturally not supported
+ return undef if (
+ ref $fromspec ne 'ARRAY'
+ ||
+ ref $fromspec->[0] ne 'HASH'
+ ||
+ ! defined $fromspec->[0]{-alias}
+ );
+
+ # no path - the head *is* the alias
+ return [] if $fromspec->[0]{-alias} eq $target_alias;
+
+ for my $i (1 .. $#$fromspec) {
+ return $fromspec->[$i][0]{-join_path} if ( ($fromspec->[$i][0]{-alias}||'') eq $target_alias );
+ }
+
+ # something else went quite wrong
+ return undef;
+}
+
+1;
if (ref $rhs eq 'HASH' and ! keys %$rhs) {
# FIXME - SQLA seems to be doing... nothing...?
}
- # normalize top level -ident, for saner extract_fixed_condition_columns code
+ # normalize top level -ident, for saner extract_equality_conditions() code
elsif (ref $rhs eq 'HASH' and keys %$rhs == 1 and exists $rhs->{-ident}) {
push @conds, { $lhs => { '=', $rhs } };
}
use Scalar::Util qw/refaddr weaken reftype blessed/;
use Context::Preserve 'preserve_context';
use SQL::Abstract qw(is_plain_value is_literal_value);
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use DBIx::Class::_Util qw(
quote_sub perlstring serialize dump_value
dbic_internal_try dbic_internal_catch
my $resolve_bindinfo = sub {
#my $infohash = shift;
- $colinfos ||= { %{ $self->_resolve_column_info($ident) } };
+ # shallow copy to preempt autoviv
+ $colinfos ||= { %{ fromspec_columns_info($ident) } };
my $ret;
if (my $col = $_[0]->{dbic_colname}) {
use strict;
use warnings;
+
use base qw/
DBIx::Class::Storage::DBI::ADO
DBIx::Class::Storage::DBI::ACCESS
/;
use mro 'c3';
+
use DBIx::Class::Storage::DBI::ADO::CursorUtils '_normalize_guids';
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use namespace::clean;
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
return @row unless
$self->cursor_class->isa('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
- my $col_infos = $self->_resolve_column_info($ident);
+ my $col_infos = fromspec_columns_info($ident);
_normalize_guids($select, $col_infos, \@row, $self);
use warnings;
use base 'DBIx::Class::Storage::DBI::Cursor';
use mro 'c3';
+
use DBIx::Class::Storage::DBI::ADO::CursorUtils '_normalize_guids';
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use namespace::clean;
=head1 NAME
_normalize_guids(
$self->args->[1],
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]),
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
\@row,
$self->storage
);
_normalize_guids(
$self->args->[1],
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]),
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
$_,
$self->storage
) for @rows;
DBIx::Class::Storage::DBI::MSSQL
/;
use mro 'c3';
+
use DBIx::Class::Carp;
use DBIx::Class::Storage::DBI::ADO::CursorUtils qw/_normalize_guids _strip_trailing_binary_nulls/;
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use namespace::clean;
__PACKAGE__->cursor_class(
'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor'
);
- my $col_infos = $self->_resolve_column_info($ident);
+ my $col_infos = fromspec_columns_info($ident);
_normalize_guids($select, $col_infos, \@row, $self);
use strict;
use warnings;
+
use base 'DBIx::Class::Storage::DBI::Cursor';
use mro 'c3';
+
use DBIx::Class::Storage::DBI::ADO::CursorUtils qw/_normalize_guids _strip_trailing_binary_nulls/;
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
use namespace::clean;
=head1 NAME
my @row = $self->next::method(@_);
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]);
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]);
_normalize_guids(
$self->args->[1],
my @rows = $self->next::method(@_);
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]);
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]);
for (@rows) {
_normalize_guids(
use warnings;
use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/;
use mro 'c3';
+use DBIx::Class::_Util 'dbic_internal_try';
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
+use namespace::clean;
__PACKAGE__->mk_group_accessors(simple => qw/_identity/);
__PACKAGE__->sql_limit_dialect ('RowNumberOver');
my ($ident, $select) = @_;
- my $col_info = $self->_resolve_column_info($ident);
+ my $col_info = fromspec_columns_info($ident);
for my $select_idx (0..$#$select) {
my $selected = $select->[$select_idx];
use base 'DBIx::Class::Storage::DBI::Cursor';
use mro 'c3';
+use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
+use namespace::clean;
+
=head1 NAME
DBIx::Class::Storage::DBI::SQLAnywhere::Cursor - GUID Support for SQL Anywhere
$unpack_guids->(
$self->args->[1],
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]),
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
\@row,
$self->storage
);
$unpack_guids->(
$self->args->[1],
- $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]),
+ $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
$_,
$self->storage
) for @rows;
dump_value fail_on_internal_call
);
use DBIx::Class::SQLMaker::Util 'extract_equality_conditions';
+use DBIx::Class::ResultSource::FromSpec::Util qw(
+ fromspec_columns_info
+ find_join_path_to_alias
+);
use DBIx::Class::Carp;
use namespace::clean;
unless $root_node;
# use the heavy duty resolver to take care of aliased/nonaliased naming
- my $colinfo = $self->_resolve_column_info($inner_attrs->{from});
+ my $colinfo = fromspec_columns_info($inner_attrs->{from});
my $selected_root_columns;
for my $i (0 .. $#{$outer_attrs->{select}}) {
}
# get a column to source/alias map (including unambiguous unqualified ones)
- my $colinfo = $self->_resolve_column_info ($attrs->{from});
+ my $colinfo = fromspec_columns_info($attrs->{from});
# set up a botched SQLA
my $sql_maker = $self->sql_maker;
sub _group_over_selection {
my ($self, $attrs) = @_;
- my $colinfos = $self->_resolve_column_info ($attrs->{from});
+ my $colinfos = fromspec_columns_info($attrs->{from});
my (@group_by, %group_index);
$_[2] ? 'MAX' : 'MIN';
}
-# Takes $ident, \@column_names
-#
-# returns { $column_name => \%column_info, ... }
-# also note: this adds -result_source => $rsrc to the column info
-#
-# If no columns_names are supplied returns info about *all* columns
-# for all sources
-sub _resolve_column_info {
- my ($self, $ident, $colnames) = @_;
-
- return {} if $colnames and ! @$colnames;
-
- my $sources = (
- # this is compat mode for insert/update/delete which do not deal with aliases
- (
- blessed($ident)
- and
- $ident->isa('DBIx::Class::ResultSource')
- ) ? +{ me => $ident }
-
- # not a known fromspec - no columns to resolve: return directly
- : ref($ident) ne 'ARRAY' ? return +{}
-
- : +{
- # otherwise decompose into alias/rsrc pairs
- map
- {
- ( $_->{-rsrc} and $_->{-alias} )
- ? ( @{$_}{qw( -alias -rsrc )} )
- : ()
- }
- map
- {
- ( ref $_ eq 'ARRAY' and ref $_->[0] eq 'HASH' ) ? $_->[0]
- : ( ref $_ eq 'HASH' ) ? $_
- : ()
- }
- @$ident
- }
- );
-
- $_ = { rsrc => $_, colinfos => $_->columns_info }
- for values %$sources;
-
- my (%seen_cols, @auto_colnames);
-
- # compile a global list of column names, to be able to properly
- # disambiguate unqualified column names (if at all possible)
- for my $alias (keys %$sources) {
- (
- ++$seen_cols{$_}{$alias}
- and
- ! $colnames
- and
- push @auto_colnames, "$alias.$_"
- ) for keys %{ $sources->{$alias}{colinfos} };
- }
-
- $colnames ||= [
- @auto_colnames,
- ( grep { keys %{$seen_cols{$_}} == 1 } keys %seen_cols ),
- ];
-
- my %return;
- for (@$colnames) {
- my ($colname, $source_alias) = reverse split /\./, $_;
-
- my $assumed_alias =
- $source_alias
- ||
- # if the column was seen exactly once - we know which rsrc it came from
- (
- $seen_cols{$colname}
- and
- keys %{$seen_cols{$colname}} == 1
- and
- ( %{$seen_cols{$colname}} )[0]
- )
- ||
- next
- ;
-
- $self->throw_exception(
- "No such column '$colname' on source " . $sources->{$assumed_alias}{rsrc}->source_name
- ) unless $seen_cols{$colname}{$assumed_alias};
-
- $return{$_} = {
- %{ $sources->{$assumed_alias}{colinfos}{$colname} },
- -result_source => $sources->{$assumed_alias}{rsrc},
- -source_alias => $assumed_alias,
- -fq_colname => "$assumed_alias.$colname",
- -colname => $colname,
- };
-
- $return{"$assumed_alias.$colname"} = $return{$_}
- unless $source_alias;
- }
-
- return \%return;
-}
-
-sub _find_join_path_to_node {
- my ($self, $from, $target_alias) = @_;
-
- # subqueries and other oddness are naturally not supported
- return undef if (
- ref $from ne 'ARRAY'
- ||
- ref $from->[0] ne 'HASH'
- ||
- ! defined $from->[0]{-alias}
- );
-
- # no path - the head is the alias
- return [] if $from->[0]{-alias} eq $target_alias;
-
- for my $i (1 .. $#$from) {
- return $from->[$i][0]{-join_path} if ( ($from->[$i][0]{-alias}||'') eq $target_alias );
- }
-
- # something else went quite wrong
- return undef;
-}
-
sub _extract_order_criteria {
my ($self, $order_by, $sql_maker) = @_;
( $where ? keys %{ extract_equality_conditions( $where ) } : () ),
) or return 0;
- my $colinfo = $self->_resolve_column_info($ident, \@cols);
+ my $colinfo = fromspec_columns_info($ident, \@cols);
return keys %$colinfo
? $self->_columns_comprise_identifying_set( $colinfo, \@cols )
sub _extract_colinfo_of_stable_main_source_order_by_portion {
my ($self, $attrs) = @_;
- my $nodes = $self->_find_join_path_to_node($attrs->{from}, $attrs->{alias});
+ my $nodes = find_join_path_to_alias($attrs->{from}, $attrs->{alias});
return unless defined $nodes;
map { values %$_ } @$nodes,
) };
- my $colinfos = $self->_resolve_column_info($attrs->{from});
+ my $colinfos = fromspec_columns_info($attrs->{from});
my ($colinfos_to_return, $seen_main_src_cols);
]) ? $colinfos_to_return : ();
}
+sub _resolve_column_info :DBIC_method_is_indirect_sugar {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
+ carp_unique("_resolve_column_info() is deprecated, ask on IRC for a better alternative");
+
+ fromspec_columns_info( @_[1,2] );
+}
+
+sub _find_join_path_to_node :DBIC_method_is_indirect_sugar {
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
+ carp_unique("_find_join_path_to_node() is deprecated, ask on IRC for a better alternative");
+
+ find_join_path_to_alias( @_[1,2] );
+}
+
sub _collapse_cond :DBIC_method_is_indirect_sugar {
DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
carp_unique("_collapse_cond() is deprecated, ask on IRC for a better alternative");
# utility classes, not part of the inheritance chain
'DBIx::Class::Optional::Dependencies',
'DBIx::Class::ResultSource::RowParser::Util',
+ 'DBIx::Class::ResultSource::FromSpec::Util',
'DBIx::Class::SQLMaker::Util',
'DBIx::Class::_Util',
) };