use List::Util();
__PACKAGE__->mk_group_accessors('simple' =>
- qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts
- _conn_pid _conn_tid transaction_depth _dbh_autocommit _on_connect_do
- _on_disconnect_do _on_connect_do_store _on_disconnect_do_store
- savepoints/
+ qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts
+ _conn_pid _conn_tid transaction_depth _dbh_autocommit savepoints/
);
# the values for these accessors are picked out (and deleted) from
# the attribute hashref passed to connect_info
my @storage_options = qw/
- on_connect_call on_disconnect_call disable_sth_caching unsafe auto_savepoint
+ on_connect_call on_disconnect_call on_connect_do on_disconnect_do
+ disable_sth_caching unsafe auto_savepoint
/;
__PACKAGE__->mk_group_accessors('simple' => @storage_options);
$self->_sql_maker_opts->{$sql_maker_opt} = $opt_val;
}
}
- for my $connect_do_opt (qw/on_connect_do on_disconnect_do/) {
- if(my $opt_val = delete $attrs{$connect_do_opt}) {
- $self->$connect_do_opt($opt_val);
- }
- }
}
%attrs = () if (ref $args[0] eq 'CODE'); # _connect() never looks past $args[0] in this case
=cut
-sub on_connect_do {
- my $self = shift;
- $self->_setup_connect_do(on_connect_do => @_);
-}
-
=head2 on_disconnect_do
This method is deprecated in favour of setting via L</connect_info>.
=cut
-sub on_disconnect_do {
- my $self = shift;
- $self->_setup_connect_do(on_disconnect_do => @_);
-}
-
-sub _setup_connect_do {
- my ($self, $opt) = (shift, shift);
-
- my $accessor = "_$opt";
- my $store = "_${opt}_store";
+sub _parse_connect_do {
+ my ($self, $type) = @_;
- return $self->$accessor if not @_;
+ my $val = $self->$type;
+ return () if not defined $val;
- my $val = shift;
-
- if (not defined $val) {
- $self->$accessor(undef);
- $self->$store(undef);
- return;
- }
-
- my @store;
+ my @res;
if (not ref($val)) {
- push @store, [ 'do_sql', $val ];
+ push @res, [ 'do_sql', $val ];
} elsif (ref($val) eq 'CODE') {
- push @store, $val;
+ push @res, $val;
} elsif (ref($val) eq 'ARRAY') {
- push @store, map [ 'do_sql', $_ ], @$val;
+ push @res, map { [ 'do_sql', $_ ] } @$val;
} else {
- $self->throw_exception("Invalid type for $opt ".ref($val));
+ $self->throw_exception("Invalid type for $type: ".ref($val));
}
- $self->$store(\@store);
- $self->$accessor($val);
+ return \@res;
}
=head2 dbh_do
my ($self) = @_;
if( $self->connected ) {
- if (my $connection_call = $self->on_disconnect_call) {
- $self->_do_connection_actions(disconnect_call_ => $connection_call)
- }
- if (my $connection_do = $self->_on_disconnect_do_store) {
- $self->_do_connection_actions(disconnect_call_ => $connection_do)
- }
+ my @actions;
+
+ push @actions, ( $self->on_disconnect_call || () );
+ push @actions, $self->_parse_connect_do ('on_disconnect_do');
+
+ $self->_do_connection_actions(disconnect_call_ => $_) for @actions;
$self->_dbh->rollback unless $self->_dbh_autocommit;
$self->_dbh->disconnect;
sub _sql_maker_args {
my ($self) = @_;
-
+
return ( bindtype=>'columns', array_datatypes => 1, limit_dialect => $self->dbh, %{$self->_sql_maker_opts} );
}
# there is no transaction in progress by definition
$self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;
- if (my $connection_call = $self->on_connect_call) {
- $self->_do_connection_actions(connect_call_ => $connection_call)
- }
- if (my $connection_do = $self->_on_connect_do_store) {
- $self->_do_connection_actions(connect_call_ => $connection_do)
- }
+ my @actions;
+
+ push @actions, ( $self->on_connect_call || () );
+ push @actions, $self->_parse_connect_do ('on_connect_do');
+
+ $self->_do_connection_actions(connect_call_ => $_) for @actions;
}
sub _determine_driver {
} @bind;
}
+sub _flatten_bind_params {
+ my ($self, @bind) = @_;
+
+ ### Turn @bind from something like this:
+ ### ( [ "artist", 1 ], [ "cdid", 1, 3 ] )
+ ### to this:
+ ### ( 1, 1, 3 )
+ return
+ map {
+ if ( defined( $_ && $_->[1] ) ) {
+ @{$_}[ 1 .. $#$_ ];
+ }
+ else { undef; }
+ } @bind;
+}
+
sub _query_start {
my ( $self, $sql, @bind ) = @_;