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

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

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