/[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.13 by joko, Tue Apr 8 23:06:45 2003 UTC revision 1.17 by joko, Sat Jun 19 01:49:47 2004 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.17  2004/06/19 01:49:47  joko
7    #  (re-)activated "getCOREHANDLE"
8    #
9    #  Revision 1.16  2003/04/11 01:17:18  joko
10    #  sendQuery:
11    #  + introduced crud action 'DELETE'
12    #  + some pre-flight checks
13    #
14    #  Revision 1.15  2003/04/09 07:53:33  joko
15    #  minor namespace update
16    #
17    #  Revision 1.14  2003/04/09 06:06:04  joko
18    #  sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries
19    #
20  #  Revision 1.13  2003/04/08 23:06:45  joko  #  Revision 1.13  2003/04/08 23:06:45  joko
21  #  renamed core database helper functions  #  renamed core database helper functions
22  #  #
# Line 60  use base ("Data::Storage::Handler::Abstr Line 74  use base ("Data::Storage::Handler::Abstr
74    
75  use DBI;  use DBI;
76  use Data::Dumper;  use Data::Dumper;
77  use shortcuts::db qw( hash2sql dsn2dbname );  use shortcuts::database qw( hash2sql dsn2dbname );
78  use Data::Storage::Result::DBI;  use Data::Storage::Result::DBI;
79    
80    
# Line 138  sub _sendSql { Line 152  sub _sendSql {
152    my $self = shift;    my $self = shift;
153    my $sql = shift;    my $sql = shift;
154        
155      # pre-flight check: is $sql defined?
156      if (!$sql) {
157        $logger->warning( __PACKAGE__ . "->_sendSql: \$sql was empty." );
158        return;
159      }
160      
161    # two-level handling for implicit connect:    # two-level handling for implicit connect:
162    # if there's no corehandle ...    # if there's no corehandle ...
163    if (!$self->{_COREHANDLE}) {    if (!$self->{_COREHANDLE}) {
# Line 201  sub sendQuery { Line 221  sub sendQuery {
221    
222    $logger->debug( __PACKAGE__ . "->sendQuery" );    $logger->debug( __PACKAGE__ . "->sendQuery" );
223    
224      my $crud = $query->{options}->{crud};
225      $crud ||= $query->{options}->{action};
226      $crud ||= 'RETRIEVE';
227    
228      if (my $guid = $query->{options}->{GUID}) {
229        $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ];
230      }
231    
232      # check criterias (load & save)
233    #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}';";
234    #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);    #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);
235    my @crits;    my @crits;
# Line 209  sub sendQuery { Line 238  sub sendQuery {
238      $op = '=' if lc $_->{op} eq 'eq';      $op = '=' if lc $_->{op} eq 'eq';
239      push @crits, "$_->{key}$op'$_->{val}'";      push @crits, "$_->{key}$op'$_->{val}'";
240    }    }
   my $subnodes = {};  
   map { $subnodes->{$_}++ } @{$query->{subnodes}};  
241    # HACK: this is hardcoded ;(    expand possibilities!    # HACK: this is hardcoded ;(    expand possibilities!
242    my $crit = join(' AND ', @crits);    my $crit = join(' AND ', @crits);
243    my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit);    
244    return $self->sendCommand($sql);    # check subnodes (load)
245      my $subnodes = {};
246      map { $subnodes->{$_}++ } @{$query->{subnodes}};
247      
248      # check payload (save)
249      #print Dumper($query->{payload});
250      #$subnodes ||= $query->{payload};
251      
252      # dispatch action
253      if ($crud eq 'RETRIEVE') {
254        my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit);
255        return $self->sendCommand($sql);
256    
257      } elsif ($crud eq 'UPDATE') {
258        my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit);
259        $self->sendCommand($sql);
260    
261      } elsif ($crud eq 'DELETE') {
262        my $sql = hash2sql($query->{node}, $query->{payload}, 'DELETE', $crit);
263        $self->sendCommand($sql);
264    
265      }
266    
267  }  }
268    
269  sub eraseAll {  sub eraseAll {
# Line 269  sub createDb { Line 318  sub createDb {
318        
319  }  }
320    
321  sub getCOREHANDLE2 {  sub getCOREHANDLE {
322    my $self = shift;    my $self = shift;
323    return $self->{_COREHANDLE};    return $self->{_COREHANDLE};
324  }  }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.17

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