[PATCH] DBD::Proxy to handle tables_info

Jochen,
	I've included a patch to fix the a problem using table_info
	and DBD::Proxy.  Currently the DBD::Proxy attempts to execute a
	statement called "SHOW TABLES".  I've included a patch that
	modifies the execute and fetch methods to use cached data only.
	I've used (mis-used) the proxy_cache_only to mark the data as "to
	read cache only".  I mark the statement as INACTIVE when all the
	cached data is read (and proxy_cache_only is true).
Tom

*** Proxy.pm.orig	Wed Feb 09 00:29:14 2000
--- Proxy.pm	Thu Mar 01 23:35:56 2001
***************
*** 268,274 ****
      my $sth = DBI::_new_sth($dbh, {
  	    'Statement' => $stmt,
  	    'proxy_attr' => $attr,
! 	    'proxy_params' => []
      });
      $sth;
  }
--- 268,275 ----
      my $sth = DBI::_new_sth($dbh, {
  	    'Statement' => $stmt,
  	    'proxy_attr' => $attr,
! 	    'proxy_params' => [],
!     	'proxy_cache_only' => 0,
      });
      $sth;
  }
***************
*** 307,313 ****
          'Statement' => "SHOW TABLES",
  	'proxy_params' => [],
  	'proxy_data' => \@rows,
! 	'proxy_attr_cache' => { 'NAME' => $names, 'TYPE' => $types }
      });
      $sth->SUPER::STORE('NUM_OF_FIELDS' => $numFields);
      return $sth;
--- 308,320 ----
          'Statement' => "SHOW TABLES",
  	'proxy_params' => [],
  	'proxy_data' => \@rows,
! 	'proxy_attr_cache' => { 
! 		'NUM_OF_PARAMS' => 0, 
! 		'NUM_OF_FIELDS' => $numFields, 
! 		'NAME' => $names, 
! 		'TYPE' => $types
! 		},
!     	'proxy_cache_only' => 1,
      });
      $sth->SUPER::STORE('NUM_OF_FIELDS' => $numFields);
      return $sth;
***************
*** 351,357 ****
      my $sth = shift;
      my $params = @_ ? \@_ : $sth->{'proxy_params'};
  
!     undef $sth->{'proxy_data'};
  
      my $dbh = $sth->{'Database'};
      my $client = $dbh->{'proxy_client'};
--- 358,365 ----
      my $sth = shift;
      my $params = @_ ? \@_ : $sth->{'proxy_params'};
  
!     #
!     # undef $sth->{'proxy_data'};
  
      my $dbh = $sth->{'Database'};
      my $client = $dbh->{'proxy_client'};
***************
*** 359,364 ****
--- 367,381 ----
  
      my ($numFields, $numParams, $numRows, $names, $types, @outParams);
  
+     if ($sth->{'proxy_data'}) {
+ 	my $attrCache = $sth->{'proxy_attr_cache'};
+ 	$numFields = $attrCache->{'NUM_OF_FIELDS'};
+ 	$numParams = $attrCache->{'NUM_OF_PARAMS'};
+ 	$names = $attrCache->{'NAME'};
+ 	$types = $attrCache->{'TYPE'};
+ 	$numRows = scalar @{$sth->{'proxy_data'}};
+     } else {
+ 
      if (!$rsth) {
  	my $rdbh = $dbh->{'proxy_dbh'};
  
***************
*** 384,395 ****
--- 401,414 ----
  	($numRows, @outParams) = eval { $rsth->execute($params) };
  	return DBI::set_err($sth, 1, $@) if $@;
      }
+     }
      $sth->{'proxy_rows'} = $numRows;
      $sth->{'proxy_attr_cache'} = {
  	    'NUM_OF_FIELDS' => $numFields,
  	    'NUM_OF_PARAMS' => $numParams,
  	    'NAME'          => $names
      };
+ 
      $sth->SUPER::STORE('Active' => 1) if $numFields; # is SELECT
  
      if (@outParams) {
***************
*** 428,433 ****
--- 447,454 ----
  	$sth->{'proxy_data'} = $data = [@rows];
      }
      my $row = shift @$data;
+ 
+ 	$sth->SUPER::STORE(Active => 0) if ( $sth->{proxy_cache_only} and !@$data );
      return $sth->_set_fbav($row);
  }
  *fetchrow_arrayref = \&fetch;

-- 
Thomas A. Lowery	stlowery@yahoo.com
http://tlowery.hypermart.net

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

0
stlowery
3/2/2001 3:41:51 PM
perl.dbi.dev 1960 articles. 0 followers. Follow

0 Replies
384 Views

Similar Articles

[PageSpeed] 45

Reply: