1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::ImaDBI;
6 use DBIx::ContextualFetch;
9 use base qw(Class::Data::Inheritable);
11 __PACKAGE__->mk_classdata('sql_transformer_class' =>
12 'DBIx::Class::CDBICompat::SQLTransformer');
14 __PACKAGE__->mk_classdata('_transform_sql_handler_order'
15 => [ qw/TABLE ESSENTIAL JOIN IDENTIFIER/ ] );
17 __PACKAGE__->mk_classdata('_transform_sql_handlers' =>
21 my ($self, $class, $data) = @_;
22 return $class->result_source_instance->name unless $data;
23 my ($f_class, $alias) = split(/=/, $data);
25 $self->{_classes}{$alias} = $f_class;
26 return $f_class->result_source_instance->name." ${alias}";
30 my ($self, $class, $data) = @_;
31 $class = $data ? $self->{_classes}{$data} : $class;
32 return join(', ', $class->columns('Essential'));
36 my ($self, $class, $data) = @_;
37 $class = $data ? $self->{_classes}{$data} : $class;
38 return join ' AND ', map "$_ = ?", $class->primary_columns;
42 my ($self, $class, $data) = @_;
43 my ($from, $to) = split(/ /, $data);
44 my ($from_class, $to_class) = @{$self->{_classes}}{$from, $to};
45 my ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
46 map { $from_class->relationship_info($_) }
47 $from_class->relationships;
49 ($from, $to) = ($to, $from);
50 ($from_class, $to_class) = ($to_class, $from_class);
51 ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
52 map { $from_class->relationship_info($_) }
53 $from_class->relationships;
55 $self->throw_exception( "No relationship to JOIN from ${from_class} to ${to_class}" )
57 my $join = $from_class->storage->sql_maker->_join_condition(
58 $from_class->result_source_instance->resolve_condition(
59 $rel_obj->{cond}, $to, $from) );
66 return $_[0]->storage->dbh;
70 my ($class, @info) = @_;
71 $info[3] = { %{ $info[3] || {}} };
72 $info[3]->{RootClass} = 'DBIx::ContextualFetch';
73 return $class->next::method(@info);
77 return $_[0]->storage->dbh->{Driver}->{Name};
81 my ($class, $name, $sql) = @_;
83 my $sql_name = "sql_${name}";
84 my $full_sql_name = join '::', $class, $sql_name;
85 *$full_sql_name = Sub::Name::subname $full_sql_name,
89 return $class->storage->sth($class->transform_sql($sql, @_));
91 if ($sql =~ /select/i) {
92 my $search_name = "search_${name}";
93 my $full_search_name = join '::', $class, $search_name;
94 *$full_search_name = Sub::Name::subname $full_search_name,
96 my ($class, @args) = @_;
97 my $sth = $class->$sql_name;
98 return $class->sth_to_objects($sth, \@args);
104 my ($class, $sth, $execute_args) = @_;
106 $sth->execute(@$execute_args);
109 while (my $row = $sth->fetchrow_hashref) {
110 push(@ret, $class->inflate_result($class->result_source_instance, $row));
117 my ($class, $sql, @args) = @_;
119 my $tclass = $class->sql_transformer_class;
120 $class->ensure_class_loaded($tclass);
121 my $t = $tclass->new($class, $sql, @args);
123 return sprintf($t->sql, $t->args);
127 DBIx::ContextualFetch::st; # HIDE FROM PAUSE THIS IS NOT OUR CLASS
129 no warnings 'redefine';
131 sub _untaint_execute {
133 my $old_value = $sth->{Taint};
137 no warnings 'uninitialized';
138 $ret = $sth->SUPER::execute(@_);
140 $sth->{Taint} = $old_value;