REH...@cvs.perl.org
unread,Dec 21, 2012, 11:44:36 AM12/21/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to svn-commit-...@perl.org
Author: REHSACK
Date: Fri Dec 21 08:44:36 2012
New Revision: 15541
Modified:
dbi/branches/sqlengine/lib/DBI/DBD/SqlEngine.pm
Log:
put initialization funcs at the very end of initialization procedure
Modified: dbi/branches/sqlengine/lib/DBI/DBD/SqlEngine.pm
==============================================================================
--- dbi/branches/sqlengine/lib/DBI/DBD/SqlEngine.pm (original)
+++ dbi/branches/sqlengine/lib/DBI/DBD/SqlEngine.pm Fri Dec 21 08:44:36 2012
@@ -118,6 +118,8 @@
use vars qw(@ISA $imp_data_size);
+use Carp qw/carp/;
+
$imp_data_size = 0;
sub connect ($$;$$$)
@@ -141,6 +143,7 @@
my $two_phased_init;
defined $dbh->{sql_init_phase} and $two_phased_init = ++$dbh->{sql_init_phase};
my %second_phase_attrs;
+ my @func_inits;
my ( $var, $val );
while ( length $dbname )
@@ -154,69 +157,69 @@
$var = $dbname;
$dbname = "";
}
+
if ( $var =~ m/^(.+?)=(.*)/s )
{
$var = $1;
( $val = $2 ) =~ s/\\(.)/$1/g;
- if ($two_phased_init)
- {
- eval { $dbh->STORE( $var, $val ); };
- $@ and $second_phase_attrs{$var} = $val;
- }
- else
- {
- $dbh->STORE( $var, $val );
- }
+ exists $attr->{$var} and carp("$var is given in DSN *and* \$attr during DBI->connect()") if($^W);
+ exists $attr->{$var} or $attr->{$var} = $val;
}
elsif ( $var =~ m/^(.+?)=>(.*)/s )
{
$var = $1;
( $val = $2 ) =~ s/\\(.)/$1/g;
my $ref = eval $val;
- $dbh->$var($ref);
+ # $dbh->$var($ref);
+ push(@func_inits, $var, $ref);
}
}
- if ($two_phased_init)
- {
- # The attributes need to be sorted in a specific way as the
- # assignment is through tied hashes and calls STORE on each
- # attribute. Some attributes require to be called prior to
- # others
- # e.g. f_dir *must* be done before xx_tables in DBD::File
- # The dbh attribute sql_init_order is a hash with the order
- # as key (low is first, 0 .. 100) and the attributes that
- # are set to that oreder as anon-list as value:
- # { 0 => [qw( AutoCommit PrintError RaiseError Profile ... )],
- # 10 => [ list of attr to be dealt with immediately after first ],
- # 50 => [ all fields that are unspecified or default sort order ],
- # 90 => [ all fields that are needed after other initialisation ],
- # }
-
- my %order = map {
- my $order = $_;
- map { ( $_ => $order ) } @{ $dbh->{sql_init_order}{$order} };
- } sort { $a <=> $b } keys %{ $dbh->{sql_init_order} || {} };
- my @ordered_attr =
- map { $_->[0] }
- sort { $a->[1] <=> $b->[1] }
- map { [ $_, defined $order{$_} ? $order{$_} : 50 ] }
- keys %$attr;
+ # The attributes need to be sorted in a specific way as the
+ # assignment is through tied hashes and calls STORE on each
+ # attribute. Some attributes require to be called prior to
+ # others
+ # e.g. f_dir *must* be done before xx_tables in DBD::File
+ # The dbh attribute sql_init_order is a hash with the order
+ # as key (low is first, 0 .. 100) and the attributes that
+ # are set to that oreder as anon-list as value:
+ # { 0 => [qw( AutoCommit PrintError RaiseError Profile ... )],
+ # 10 => [ list of attr to be dealt with immediately after first ],
+ # 50 => [ all fields that are unspecified or default sort order ],
+ # 90 => [ all fields that are needed after other initialisation ],
+ # }
+
+ my %order = map {
+ my $order = $_;
+ map { ( $_ => $order ) } @{ $dbh->{sql_init_order}{$order} };
+ } sort { $a <=> $b } keys %{ $dbh->{sql_init_order} || {} };
+ my @ordered_attr =
+ map { $_->[0] }
+ sort { $a->[1] <=> $b->[1] }
+ map { [ $_, defined $order{$_} ? $order{$_} : 50 ] }
+ keys %$attr;
+
+ # initialize given attributes ... lower weighted before higher weighted
+ foreach my $a (@ordered_attr)
+ {
+ exists $attr->{$a} or next;
+ $two_phased_init and eval {
+ $dbh->{$a} = $attr->{$a};
+ delete $attr->{$a};
+ };
+ $@ and $second_phase_attrs{$a} = delete $attr->{$a};
+ $two_phased_init or $dbh->STORE($a, delete $attr->{$a});
+ }
- # initialize given attributes ... lower weighted before higher weighted
- foreach my $a (@ordered_attr)
- {
- exists $attr->{$a} or next;
- eval {
- $dbh->{$a} = $attr->{$a};
- delete $attr->{$a};
- };
- $@ and $second_phase_attrs{$a} = delete $attr->{$a};
- }
+ $two_phased_init and $dbh->func( 1, "init_default_attributes" );
+ %$attr = %second_phase_attrs;
- $dbh->func( 1, "init_default_attributes" );
- %$attr = %second_phase_attrs;
- }
+ for( my $i = 0; $i < scalar(@func_inits); $i += 2 )
+ {
+ my $func = $func_inits[$i];
+ my $arg = $func_inits[$i+1];
+ $dbh->$func($arg);
+ }
$dbh->func("init_done");