Author: timbo
Date: Thu Feb  1 18:09:21 2007
New Revision: 8784

Modified:
   dbi/trunk/Changes
   dbi/trunk/DBI.pm
   dbi/trunk/MANIFEST
   dbi/trunk/lib/DBD/Gofer.pm
   dbi/trunk/lib/DBD/Gofer/Transport/stream.pm
   dbi/trunk/lib/DBI/Gofer/Transport/Base.pm

Log:
Add basic ssh config for stream transport.
Flag the dbh *_info methods thar return $sth as factory methods.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Thu Feb  1 18:09:21 2007
@@ -10,14 +10,14 @@
 
 =head2 Changes in DBI 1.54 (svn rev 8745),  29th January 2007
 
-  NOTE: This version has some subtle changes in DBI internals.
+  NOTE: This release includes the 'next big thing' for DBI: DBD::Gofer.
+  Take a look!
+
+  WARNING: This version has some subtle changes in DBI internals.
   It's possible, though doubtful, that some may affect your code.
   I recommend some extra texting before using this release.
   Or perhaps I'm just being over cautious...
 
-  NOTE: This release includes the 'next big thing' for DBI: DBD::Gofer.
-  Take a look!
-
   Fixed type_info when called for multiple dbh thanks to Cosimo Streppone.
   Fixed compile warnings in bleadperl on freebsd-6.1-release
     and solaris 10g thanks to Philip M. Gollucci.
@@ -32,6 +32,9 @@
     to only be given for dbh that have active sth or are not AutoCommit.
   Changed take_imp_data to call finish on all Active child sth.
   Changed DBI::PurePerl trace() method to be more consistent.
+  Changed handle factory methods, like connect, prepare, and table_info,
+    to copy any error/warn/info state of the handle being returned
+    up into the handle the method was called on.
   Updated DBI::DBD docs for driver authors thanks to Ammon Riley
     and Dean Arnold.
 

Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm    (original)
+++ dbi/trunk/DBI.pm    Thu Feb  1 18:09:21 2007
@@ -423,12 +423,12 @@
        rows            => $keeperr,
 
        tables          => { U =>[1,6,'$catalog, $schema, $table, $type [, 
\%attr ]' ], O=>0x2200 },
-       table_info      => { U =>[1,6,'$catalog, $schema, $table, $type [, 
\%attr ]' ], O=>0x2200|0x0800 },
-       column_info     => { U =>[5,6,'$catalog, $schema, $table, $column [, 
\%attr ]'],O=>0x2200|0x0800 },
-       primary_key_info=> { U =>[4,5,'$catalog, $schema, $table [, \%attr ]' 
],        O=>0x2200|0x0800 },
+       table_info      => { U =>[1,6,'$catalog, $schema, $table, $type [, 
\%attr ]' ], O=>0x2200|0x8800 },
+       column_info     => { U =>[5,6,'$catalog, $schema, $table, $column [, 
\%attr ]'],O=>0x2200|0x8800 },
+       primary_key_info=> { U =>[4,5,'$catalog, $schema, $table [, \%attr ]' 
],        O=>0x2200|0x8800 },
        primary_key     => { U =>[4,5,'$catalog, $schema, $table [, \%attr ]' 
],        O=>0x2200 },
-       foreign_key_info=> { U =>[7,8,'$pk_catalog, $pk_schema, $pk_table, 
$fk_catalog, $fk_schema, $fk_table [, \%attr ]' ], O=>0x2200|0x0800 },
-       statistics_info => { U =>[6,7,'$catalog, $schema, $table, $unique_only, 
$quick, [, \%attr ]' ], O=>0x2200|0x0800 },
+       foreign_key_info=> { U =>[7,8,'$pk_catalog, $pk_schema, $pk_table, 
$fk_catalog, $fk_schema, $fk_table [, \%attr ]' ], O=>0x2200|0x8800 },
+       statistics_info => { U =>[6,7,'$catalog, $schema, $table, $unique_only, 
$quick, [, \%attr ]' ], O=>0x2200|0x8800 },
        type_info_all   => { U =>[1,1], O=>0x2200|0x0800 },
        type_info       => { U =>[1,2,'$data_type'], O=>0x2200 },
        get_info        => { U =>[2,2,'$info_type'], O=>0x2200|0x0800 },

Modified: dbi/trunk/MANIFEST
==============================================================================
--- dbi/trunk/MANIFEST  (original)
+++ dbi/trunk/MANIFEST  Thu Feb  1 18:09:21 2007
@@ -26,7 +26,9 @@
 lib/DBD/File.pm                        A driver base class for simple drivers
 lib/DBD/Gofer.pm                DBD::Gofer 'stateless proxy' driver
 lib/DBD/Gofer/Transport/Base.pm Base class for DBD::Gofer driver transport 
classes
-lib/DBD/Gofer/Transport/null.pm DBD::Gofer transport that executes locally 
(for testing)
+lib/DBD/Gofer/Transport/null.pm DBD::Gofer transport that executes in same 
process (for testing)
+lib/DBD/Gofer/Transport/pipeone.pm DBD::Gofer transport to new subprocess for 
each request
+lib/DBD/Gofer/Transport/stream.pm DBD::Gofer transport for ssh etc
 lib/DBD/NullP.pm               An empty example Driver module
 lib/DBD/Proxy.pm               Proxy driver
 lib/DBD/Sponge.pm              A driver for fake cursors (precached data)
@@ -41,6 +43,8 @@
 lib/DBI/Gofer/Request.pm        Request object from DBD::Gofer
 lib/DBI/Gofer/Response.pm       Response object for DBD::Gofer
 lib/DBI/Gofer/Transport/Base.pm Base class for DBD::Gofer server transport 
classes
+lib/DBI/Gofer/Transport/pipeone.pm  DBD::Gofer transport for single requests
+lib/DBI/Gofer/Transport/stream.pm   DBI::Gofer transport for ssh etc
 lib/DBI/Profile.pm             Manage DBI usage profile data
 lib/DBI/ProfileData.pm
 lib/DBI/ProfileDumper.pm

Modified: dbi/trunk/lib/DBD/Gofer.pm
==============================================================================
--- dbi/trunk/lib/DBD/Gofer.pm  (original)
+++ dbi/trunk/lib/DBD/Gofer.pm  Thu Feb  1 18:09:21 2007
@@ -91,6 +91,7 @@
     my %dsn_attr_defaults = (
         go_dsn => undef,
         go_url => undef,
+        go_ssh => undef,
         go_transport => undef,
     );
 
@@ -102,20 +103,20 @@
         my $orig_dsn = $dsn;
 
         # first remove dsn= and everything after it
-        my $go_dsn = ($dsn =~ s/\bdsn=(.*)$// && $1)
+        my $remote_dsn = ($dsn =~ s/\bdsn=(.*)$// && $1)
             or return $drh->set_err(1, "No dsn= argument in '$orig_dsn'");
 
         if ($attr->{go_bypass}) { # don't use DBD::Gofer for this connection
             # useful for testing with DBI_AUTOPROXY, e.g., t/03handle.t
-            return DBI->connect($go_dsn, $user, $auth, $attr);
+            return DBI->connect($remote_dsn, $user, $auth, $attr);
         }
 
-        my %dsn_attr = (%dsn_attr_defaults, go_dsn => $go_dsn);
+        my %dsn_attr = (%dsn_attr_defaults, go_dsn => $remote_dsn);
         # extract any go_ attributes from the connect() attr arg
         for my $k (grep { /^go_/ } keys %$attr) {
             $dsn_attr{$k} = delete $attr->{$k};
         }
-        # then override those with any attributes embedded in our dsn (not 
go_dsn)
+        # then override those with any attributes embedded in our dsn (not 
remote_dsn)
         for my $kv (grep /=/, split /;/, $dsn, -1) {
             my ($k, $v) = split /=/, $kv, 2;
             $dsn_attr{ "go_$k" } = $v;
@@ -125,9 +126,9 @@
             return $drh->set_err(1, "Unknown attributes: @{[ keys %dsn_attr 
]}");
         }
 
-        my $transport_class = $dsn_attr{go_transport}
+        my $transport_class = delete $dsn_attr{go_transport}
             or return $drh->set_err(1, "No transport= argument in 
'$orig_dsn'");
-        $transport_class = "DBD::Gofer::Transport::$dsn_attr{go_transport}"
+        $transport_class = "DBD::Gofer::Transport::$transport_class"
             unless $transport_class =~ /::/;
         _load_class($transport_class)
             or return $drh->set_err(1, "Error loading $transport_class: $@");
@@ -141,7 +142,7 @@
             my $go_attr = { %$attr };
             delete @{$go_attr}{qw(Profile HandleError HandleSetErr Callbacks)};
             $request_class->new({
-                connect_args => [ $go_dsn, $user, $auth, $go_attr ]
+                connect_args => [ $remote_dsn, $user, $auth, $go_attr ]
             })
         } or return $drh->set_err(1, "Error instanciating $request_class $@");
 

Modified: dbi/trunk/lib/DBD/Gofer/Transport/stream.pm
==============================================================================
--- dbi/trunk/lib/DBD/Gofer/Transport/stream.pm (original)
+++ dbi/trunk/lib/DBD/Gofer/Transport/stream.pm Thu Feb  1 18:09:21 2007
@@ -18,7 +18,7 @@
 our $VERSION = sprintf("0.%06d", q$Revision: 8748 $ =~ /(\d+)/o);
 
 __PACKAGE__->mk_accessors(qw(
-    ssh
+    go_ssh
 )); 
 
 
@@ -33,9 +33,13 @@
         if (not $connection || ($connection->{pid} && not kill 0, 
$connection->{pid})) {
             my $cmd = [qw(perl -MDBI::Gofer::Transport::stream -e 
run_stdio_hex)];
             #push @$cmd, "DBI_TRACE=2=/tmp/goferstream.log", "sh", "-c";
-            if (0) {
-                my $ssh = '[EMAIL PROTECTED]';
-                unshift @$cmd, 'ssh', '-q', split(' ', $ssh);
+            if (my $ssh = $self->go_ssh) {
+                #my $ssh = '[EMAIL PROTECTED]';
+                my $setup_env = join "||", map { "source $_ 2>/dev/null" }
+                                    qw(.bash_profile .bash_login .profile);
+                my $setup = $setup_env.q{; eval "$@"};
+                unshift @$cmd, qw(ssh -q), split(' ', $ssh), qw(bash -c), 
$setup;
+                #warn "[EMAIL PROTECTED]";
             }
             # XXX add a handshake - some message from 
DBI::Gofer::Transport::stream that's
             # sent as soon as it starts that we can wait for to report success 
- and soak up

Modified: dbi/trunk/lib/DBI/Gofer/Transport/Base.pm
==============================================================================
--- dbi/trunk/lib/DBI/Gofer/Transport/Base.pm   (original)
+++ dbi/trunk/lib/DBI/Gofer/Transport/Base.pm   Thu Feb  1 18:09:21 2007
@@ -22,14 +22,24 @@
 __PACKAGE__->mk_accessors(qw(
     trace
     go_dsn
+    go_url
+    go_ssh
 ));
 
 
-sub new {
+sub _new {
     my ($class, $args) = @_;
     $args->{trace} ||= $class->_init_trace;
     return $class->SUPER::new($args);
 }
+sub new {
+    my ($class, $args) = @_;
+    $args->{trace} ||= $class->_init_trace;
+    my $self = bless {}, $class;
+    $self->$_( $args->{$_} ) for keys %$args;
+    return $self;
+}
+
 
 
 sub freeze_data {
@@ -37,12 +47,21 @@
     $self->_dump("freezing ".ref($data), $data)
         if !$skip_trace and $self->trace;
     local $Storable::forgive_me = 1; # for CODE refs etc
-    return freeze($data);
+    my $frozen = eval { freeze($data) };
+    if ($@) {
+        die "Error freezing ".ref($data)." object: $@";
+    }
+    return $frozen;
 }   
 
 sub thaw_data {
     my ($self, $frozen_data, $skip_trace) = @_;
-    my $data = thaw($frozen_data);
+    my $data = eval { thaw($frozen_data) };
+    if ($@) {
+        my $err = $@;
+        $self->_dump("bad data",$frozen_data);
+        die "Error thawing object: $err";
+    }
     $self->_dump("thawing ".ref($data), $data)
         if !$skip_trace and $self->trace;
     return $data;

Reply via email to