/[cvs]/nfo/perl/libs/Data/Storage/Handler/DBI.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/DBI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by jonen, Sun Nov 17 08:46:42 2002 UTC revision 1.5 by joko, Fri Nov 29 05:00:26 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.5  2002/11/29 05:00:26  joko
7    #  + sub getListUnfiltered
8    #  + sub sendQuery
9    #
10  #  Revision 1.4  2002/11/17 08:46:42  jonen  #  Revision 1.4  2002/11/17 08:46:42  jonen
11  #  + wrapped eval around DBI->connect to prevent deaths  #  + wrapped eval around DBI->connect to prevent deaths
12  #  #
# Line 29  use base ("Data::Storage::Handler::Abstr Line 33  use base ("Data::Storage::Handler::Abstr
33    
34  use DBI;  use DBI;
35  use Data::Dumper;  use Data::Dumper;
36  use libdb;  use libdb qw( getDbNameByDsn hash2Sql );
37    use Data::Storage::Result::DBI;
38    
39  # get logger instance  # get logger instance
40  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
41    
42    
43  our $metainfo = {  sub getMetaInfo {
44    'disconnectMethod' => 'disconnect',    my $self = shift;
45  };    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );
46      return {
47        'disconnectMethod' => 'disconnect',
48      };
49    }
50    
51  sub connect {  sub connect {
52    
# Line 79  sub configureCOREHANDLE { Line 88  sub configureCOREHANDLE {
88    
89    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
90    
91    # apply configured modifications    # apply configured modifications to DBI-handle
92      if (exists $self->{locator}->{dbi}->{trace_level} && exists $self->{locator}->{dbi}->{trace_file}) {      if (exists $self->{locator}->{dbi}->{trace_level} && exists $self->{locator}->{dbi}->{trace_file}) {
93        $self->{COREHANDLE}->trace($self->{locator}->{dbi}->{trace_level}, $self->{locator}->{dbi}->{trace_file});        $self->{COREHANDLE}->trace($self->{locator}->{dbi}->{trace_level}, $self->{locator}->{dbi}->{trace_file});
94      }      }
# Line 120  sub _sendSql { Line 129  sub _sendSql {
129  sub sendCommand {  sub sendCommand {
130    my $self = shift;    my $self = shift;
131    my $command = shift;    my $command = shift;
132      # TODO: when tracing: yes, do actually log this
133    #$logger->debug( __PACKAGE__ . "->sendCommand( command $command )" );    #$logger->debug( __PACKAGE__ . "->sendCommand( command $command )" );
134    my $cmdHandle = $self->_sendSql($command);    my $cmdHandle = $self->_sendSql($command);
135    my $result = Data::Storage::Result::DBI->new( RESULTHANDLE => $cmdHandle );    my $result = Data::Storage::Result::DBI->new( RESULTHANDLE => $cmdHandle );
136    return $result;    return $result;
137  }  }
138    
 sub quoteSql {  
   my $self = shift;  
   my $string = shift;  
   if ($string) {  
     $string =~ s/'/\\'/g;  
   }  
   return $string;  
 }  
   
   
139  sub getChildNodes {  sub getChildNodes {
   
140    my $self = shift;    my $self = shift;
141    my @nodes;    my @nodes;
   
142    $logger->debug( __PACKAGE__ . "->getChildNodes()" );    $logger->debug( __PACKAGE__ . "->getChildNodes()" );
   
143    if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
144      my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn});      my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn});
145      my $key = "Tables_in_$dbname";      my $key = "Tables_in_$dbname";
146      while ( my $row = $result->_getNextEntry() ) {      while ( my $row = $result->getNextEntry() ) {
147        push @nodes, $row->{$key};        push @nodes, $row->{$key};
148      }      }
149    }    }
     
150    return \@nodes;    return \@nodes;
   
151  }  }
152    
153    sub getListUnfiltered {
   
   
 package Data::Storage::Result::DBI;  
   
 use strict;  
 use warnings;  
   
 use base ("Data::Storage::Result");  
   
 sub DESTROY {  
154    my $self = shift;    my $self = shift;
155    #$logger->debug( __PACKAGE__ . "->" . "DESTROY" );    my $nodename = shift;
156    $self->{RESULTHANDLE} && $self->{RESULTHANDLE}->finish();    my @list;
157      $logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" );
158      # get list of rows from rdbms by table name
159      my $result = $self->sendCommand("SELECT * FROM $nodename");
160      while ( my $row = $result->getNextEntry() ) {
161        push @list, $row;
162      }
163      return \@list;
164  }  }
165    
166  sub _getNextEntry {  sub sendQuery {
167    my $self = shift;    my $self = shift;
168    $self->{RESULTHANDLE} && return $self->{RESULTHANDLE}->fetchrow_hashref;    my $query = shift;
169      #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";
170      #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);
171      my @crits;
172      foreach (@{$query->{criterias}}) {
173        my $op = '';
174        $op = '=' if lc $_->{op} eq 'eq';
175        push @crits, "$_->{key}$op'$_->{val}'";
176      }
177      my $subnodes = {};
178      map { $subnodes->{$_}++ } @{$query->{subnodes}};
179      # HACK: this is hardcoded ;(    expand possibilities!
180      my $crit = join(' AND ', @crits);
181      my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
182      return $self->sendCommand($sql);
183  }  }
184    
   
185  1;  1;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed