[pm-h] Perl tie variable to database then using local on it

Michael R. Davis mrdvt92 at yahoo.com
Wed Jul 31 12:07:22 PDT 2013


Perl Folks,
Has anyone attempted to tie a variable to Oracle's v$session values? Or any database value for that matter?
 
I am new to tie but not to DBI or Perl.
 
Perl tie and the action seems like a perfect match but I cannot get them to work together cleanly.
 SQL is "BEGIN DBMS_APPLICATION_INFO.set_action(action_name => ?); END;"
 
my $action;
tie $action, MY:OBJ (db=>$db);
local $action="Outside";
{ 
  local $action="Inside";
  #do some stuff as action is Inside
}
 #action is now "Outside" again due to the tie.
 
It works but I get this error when the database object goes out of scope.  
 
DBD::Oracle::db DESTROY failed: ORA-03135: connection
lost contact Process ID: 0 Session ID: 77 Serial number: 30453 (DBD ERROR:
OCISessionEnd) during global destruction.
Is this hopeless or has anyone gotten it to work successfully?
 
I've tried every test I can come up with to ensure we are not trying to write to the handle when we are trying to disconnect but no luck yet.   
 sub STORE {
  my $self=shift;
  my $value=shift;
  return unless defined $value; #Note local calls STORE first time with undef then with real value. no need to hit database twice
  return unless defined $self->parent;           #DESTROYED
  return unless defined $self->parent->dbh;      #DESTROYED
  return unless $self->parent->dbh->{"Active"};  #Disconnected
  $self->parent->action($value);                 #void context for performance
  return;
}
 
I assume that somewhere along the way I need to untie the variable before the database handle goes out of scope but not sure where that needs to be done.
 
Thanks for any help that can provide!
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20130731/44f15deb/attachment.html>


More information about the Houston mailing list