/[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.12 by joko, Thu Jan 30 22:28:21 2003 UTC revision 1.15 by joko, Wed Apr 9 07:53:33 2003 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.15  2003/04/09 07:53:33  joko
7    #  minor namespace update
8    #
9    #  Revision 1.14  2003/04/09 06:06:04  joko
10    #  sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries
11    #
12    #  Revision 1.13  2003/04/08 23:06:45  joko
13    #  renamed core database helper functions
14    #
15  #  Revision 1.12  2003/01/30 22:28:21  joko  #  Revision 1.12  2003/01/30 22:28:21  joko
16  #  + implemented new concrete methods  #  + implemented new concrete methods
17  #  #
# Line 54  use warnings; Line 63  use warnings;
63    
64  use base ("Data::Storage::Handler::Abstract");  use base ("Data::Storage::Handler::Abstract");
65    
66    
67  use DBI;  use DBI;
68  use Data::Dumper;  use Data::Dumper;
69  use libdb qw( getDbNameByDsn hash2Sql );  use shortcuts::database qw( hash2sql dsn2dbname );
70  use Data::Storage::Result::DBI;  use Data::Storage::Result::DBI;
71    
72    
73  # get logger instance  # get logger instance
74  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
75    
# Line 168  sub getChildNodes { Line 179  sub getChildNodes {
179    my $locator = $self->{locator};    my $locator = $self->{locator};
180    #print Dumper($locator); exit;    #print Dumper($locator); exit;
181    if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
182      my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn});      my $dbname = dsn2dbname($self->{locator}->{dbi}->{dsn});
183      my $key = "Tables_in_$dbname";      my $key = "Tables_in_$dbname";
184      while ( my $row = $result->getNextEntry() ) {      while ( my $row = $result->getNextEntry() ) {
185        push @nodes, $row->{$key};        push @nodes, $row->{$key};
# Line 196  sub sendQuery { Line 207  sub sendQuery {
207    
208    $logger->debug( __PACKAGE__ . "->sendQuery" );    $logger->debug( __PACKAGE__ . "->sendQuery" );
209    
210      my $action = $query->{options}->{action};
211      $action ||= 'load';
212    
213      if (my $guid = $query->{options}->{GUID}) {
214        $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ];
215      }
216    
217      # check criterias (load & save)
218    #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";    #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";
219    #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);    #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);
220    my @crits;    my @crits;
# Line 204  sub sendQuery { Line 223  sub sendQuery {
223      $op = '=' if lc $_->{op} eq 'eq';      $op = '=' if lc $_->{op} eq 'eq';
224      push @crits, "$_->{key}$op'$_->{val}'";      push @crits, "$_->{key}$op'$_->{val}'";
225    }    }
   my $subnodes = {};  
   map { $subnodes->{$_}++ } @{$query->{subnodes}};  
226    # HACK: this is hardcoded ;(    expand possibilities!    # HACK: this is hardcoded ;(    expand possibilities!
227    my $crit = join(' AND ', @crits);    my $crit = join(' AND ', @crits);
228    my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);    
229    return $self->sendCommand($sql);    # check subnodes (load)
230      my $subnodes = {};
231      map { $subnodes->{$_}++ } @{$query->{subnodes}};
232      
233      # check payload (save)
234      #print Dumper($query->{payload});
235      #$subnodes ||= $query->{payload};
236      
237      # dispatch action
238      if ($action eq 'load') {
239        my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit);
240        return $self->sendCommand($sql);
241      } elsif ($action eq 'save') {
242        my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit);
243        $self->sendCommand($sql);
244      }
245    
246  }  }
247    
248  sub eraseAll {  sub eraseAll {

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.15

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