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 |
# Revision 1.14 2003/04/09 06:06:04 joko |
18 |
# sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries |
# sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries |
19 |
# |
# |
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 |
|
|
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}) { |
221 |
|
|
222 |
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
223 |
|
|
224 |
my $action = $query->{options}->{action}; |
my $crud = $query->{options}->{crud}; |
225 |
$action ||= 'load'; |
$crud ||= $query->{options}->{action}; |
226 |
|
$crud ||= 'RETRIEVE'; |
227 |
|
|
228 |
if (my $guid = $query->{options}->{GUID}) { |
if (my $guid = $query->{options}->{GUID}) { |
229 |
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
250 |
#$subnodes ||= $query->{payload}; |
#$subnodes ||= $query->{payload}; |
251 |
|
|
252 |
# dispatch action |
# dispatch action |
253 |
if ($action eq 'load') { |
if ($crud eq 'RETRIEVE') { |
254 |
my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit); |
my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit); |
255 |
return $self->sendCommand($sql); |
return $self->sendCommand($sql); |
256 |
} elsif ($action eq 'save') { |
|
257 |
|
} elsif ($crud eq 'UPDATE') { |
258 |
my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit); |
my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit); |
259 |
$self->sendCommand($sql); |
$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 |
} |
} |
318 |
|
|
319 |
} |
} |
320 |
|
|
321 |
sub getCOREHANDLE2 { |
sub getCOREHANDLE { |
322 |
my $self = shift; |
my $self = shift; |
323 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
324 |
} |
} |