-package DBIx::Class::CDBICompat::ImaDBI;
+package # hide from PAUSE
+ DBIx::Class::CDBICompat::ImaDBI;
use strict;
use warnings;
use base qw/DBIx::Class/;
+__PACKAGE__->mk_classdata('sql_transformer_class' =>
+ 'DBIx::Class::CDBICompat::SQLTransformer');
+
__PACKAGE__->mk_classdata('_transform_sql_handler_order'
- => [ qw/TABLE ESSENTIAL JOIN/ ] );
+ => [ qw/TABLE ESSENTIAL JOIN IDENTIFIER/ ] );
__PACKAGE__->mk_classdata('_transform_sql_handlers' =>
{
'TABLE' =>
sub {
my ($self, $class, $data) = @_;
- return $class->_table_name unless $data;
+ return $class->result_source_instance->name unless $data;
my ($f_class, $alias) = split(/=/, $data);
$f_class ||= $class;
$self->{_classes}{$alias} = $f_class;
- return $f_class->_table_name." ${alias}";
+ return $f_class->result_source_instance->name." ${alias}";
},
'ESSENTIAL' =>
sub {
my ($self, $class, $data) = @_;
- return join(' ', $class->columns('Essential')) unless $data;
- return join(' ', $self->{_classes}{$data}->columns('Essential'));
+ $class = $data ? $self->{_classes}{$data} : $class;
+ return join(', ', $class->columns('Essential'));
+ },
+ 'IDENTIFIER' =>
+ sub {
+ my ($self, $class, $data) = @_;
+ $class = $data ? $self->{_classes}{$data} : $class;
+ return join ' AND ', map "$_ = ?", $class->primary_columns;
},
'JOIN' =>
sub {
my ($from, $to) = split(/ /, $data);
my ($from_class, $to_class) = @{$self->{_classes}}{$from, $to};
my ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
- values %{ $from_class->_relationships };
+ map { $from_class->relationship_info($_) }
+ $from_class->relationships;
unless ($rel_obj) {
($from, $to) = ($to, $from);
($from_class, $to_class) = ($to_class, $from_class);
($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
- values %{ $from_class->_relationships };
+ map { $from_class->relationship_info($_) }
+ $from_class->relationships;
}
- $self->throw( "No relationship to JOIN from ${from_class} to ${to_class}" )
+ $self->throw_exception( "No relationship to JOIN from ${from_class} to ${to_class}" )
unless $rel_obj;
- my $attrs = {
- %$self,
- _aliases => { self => $from, foreign => $to },
- _action => 'join',
- };
my $join = $from_class->storage->sql_maker->_join_condition(
- $from_class->resolve_condition($rel_obj->{cond}, $attrs) );
+ $from_class->result_source_instance->resolve_condition(
+ $rel_obj->{cond}, $to, $from) );
return $join;
}
sub set_sql {
my ($class, $name, $sql) = @_;
- my $table = $class->_table_name;
- #$sql =~ s/__TABLE__/$table/;
no strict 'refs';
*{"${class}::sql_${name}"} =
sub {
sub {
my ($class, @args) = @_;
my $sth = $class->$meth;
- $sth->execute(@args);
- return $class->sth_to_objects($sth);
+ return $class->sth_to_objects($sth, \@args);
};
}
}
sub sth_to_objects {
- my ($class, $sth) = @_;
- my @cols = $class->_select_columns;
+ my ($class, $sth, $execute_args) = @_;
+
+ $sth->execute(@$execute_args);
+
my @ret;
- while (my @row = $sth->fetchrow_array) {
- push(@ret, $class->_row_to_object(\@cols,\@row));
+ while (my $row = $sth->fetchrow_hashref) {
+ push(@ret, $class->inflate_result($class->result_source_instance, $row));
}
+
return @ret;
}
sub transform_sql {
my ($class, $sql, @args) = @_;
- my $table = $class->_table_name;
- my $attrs = { };
- foreach my $key (@{$class->_transform_sql_handler_order}) {
- my $h = $class->_transform_sql_handlers->{$key};
- $sql =~ s/__$key(?:\(([^\)]+)\))?__/$h->($attrs, $class, $1)/eg;
- }
- #warn $sql;
- return sprintf($sql, @args);
+
+ my $tclass = $class->sql_transformer_class;
+ $class->ensure_class_loaded($tclass);
+ my $t = $tclass->new($class, $sql, @args);
+
+ return sprintf($t->sql, $t->args);
}
-package DBIx::ContextualFetch::st;
+package
+ DBIx::ContextualFetch::st; # HIDE FROM PAUSE THIS IS NOT OUR CLASS
no warnings 'redefine';