1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::ImaDBI;
6 use DBIx::ContextualFetch;
8 use base qw/DBIx::Class/;
10 __PACKAGE__->mk_classdata('sql_transformer_class' =>
11 'DBIx::Class::CDBICompat::SQLTransformer');
13 __PACKAGE__->mk_classdata('_transform_sql_handler_order'
14 => [ qw/TABLE ESSENTIAL JOIN IDENTIFIER/ ] );
16 __PACKAGE__->mk_classdata('_transform_sql_handlers' =>
20 my ($self, $class, $data) = @_;
21 return $class->result_source_instance->name unless $data;
22 my ($f_class, $alias) = split(/=/, $data);
24 $self->{_classes}{$alias} = $f_class;
25 return $f_class->result_source_instance->name." ${alias}";
29 my ($self, $class, $data) = @_;
30 $class = $data ? $self->{_classes}{$data} : $class;
31 return join(', ', $class->columns('Essential'));
35 my ($self, $class, $data) = @_;
36 $class = $data ? $self->{_classes}{$data} : $class;
37 return join ' AND ', map "$_ = ?", $class->primary_columns;
41 my ($self, $class, $data) = @_;
42 my ($from, $to) = split(/ /, $data);
43 my ($from_class, $to_class) = @{$self->{_classes}}{$from, $to};
44 my ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
45 map { $from_class->relationship_info($_) }
46 $from_class->relationships;
48 ($from, $to) = ($to, $from);
49 ($from_class, $to_class) = ($to_class, $from_class);
50 ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
51 map { $from_class->relationship_info($_) }
52 $from_class->relationships;
54 $self->throw_exception( "No relationship to JOIN from ${from_class} to ${to_class}" )
56 my $join = $from_class->storage->sql_maker->_join_condition(
57 $from_class->result_source_instance->resolve_condition(
58 $rel_obj->{cond}, $to, $from) );
65 return $_[0]->storage->dbh;
69 my ($class, @info) = @_;
70 $info[3] = { %{ $info[3] || {}} };
71 $info[3]->{RootClass} = 'DBIx::ContextualFetch';
72 return $class->next::method(@info);
76 return $_[0]->storage->dbh->{Driver}->{Name};
80 my ($class, $name, $sql) = @_;
82 *{"${class}::sql_${name}"} =
86 return $class->storage->sth($class->transform_sql($sql, @_));
88 if ($sql =~ /select/i) {
89 my $meth = "sql_${name}";
90 *{"${class}::search_${name}"} =
92 my ($class, @args) = @_;
93 my $sth = $class->$meth;
94 return $class->sth_to_objects($sth, \@args);
100 my ($class, $sth, $execute_args) = @_;
102 $sth->execute(@$execute_args);
105 while (my $row = $sth->fetchrow_hashref) {
106 push(@ret, $class->inflate_result($class->result_source_instance, $row));
113 my ($class, $sql, @args) = @_;
115 my $tclass = $class->sql_transformer_class;
116 $class->ensure_class_loaded($tclass);
117 my $t = $tclass->new($class, $sql, @args);
119 return sprintf($t->sql, $t->args);
123 DBIx::ContextualFetch::st; # HIDE FROM PAUSE THIS IS NOT OUR CLASS
125 no warnings 'redefine';
127 sub _untaint_execute {
129 my $old_value = $sth->{Taint};
133 no warnings 'uninitialized';
134 $ret = $sth->SUPER::execute(@_);
136 $sth->{Taint} = $old_value;