3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.16 2003/04/11 01:17:18 joko |
7 |
|
# sendQuery: |
8 |
|
# + introduced crud action 'DELETE' |
9 |
|
# + some pre-flight checks |
10 |
|
# |
11 |
|
# Revision 1.15 2003/04/09 07:53:33 joko |
12 |
|
# minor namespace update |
13 |
|
# |
14 |
# Revision 1.14 2003/04/09 06:06:04 joko |
# Revision 1.14 2003/04/09 06:06:04 joko |
15 |
# sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries |
# sendQuery now is capable of doing 'SELECT'- or 'INSERT'-queries |
16 |
# |
# |
71 |
|
|
72 |
use DBI; |
use DBI; |
73 |
use Data::Dumper; |
use Data::Dumper; |
74 |
use shortcuts::db qw( hash2sql dsn2dbname ); |
use shortcuts::database qw( hash2sql dsn2dbname ); |
75 |
use Data::Storage::Result::DBI; |
use Data::Storage::Result::DBI; |
76 |
|
|
77 |
|
|
149 |
my $self = shift; |
my $self = shift; |
150 |
my $sql = shift; |
my $sql = shift; |
151 |
|
|
152 |
|
# pre-flight check: is $sql defined? |
153 |
|
if (!$sql) { |
154 |
|
$logger->warning( __PACKAGE__ . "->_sendSql: \$sql was empty." ); |
155 |
|
return; |
156 |
|
} |
157 |
|
|
158 |
# two-level handling for implicit connect: |
# two-level handling for implicit connect: |
159 |
# if there's no corehandle ... |
# if there's no corehandle ... |
160 |
if (!$self->{_COREHANDLE}) { |
if (!$self->{_COREHANDLE}) { |
218 |
|
|
219 |
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
$logger->debug( __PACKAGE__ . "->sendQuery" ); |
220 |
|
|
221 |
my $action = $query->{options}->{action}; |
my $crud = $query->{options}->{crud}; |
222 |
$action ||= 'load'; |
$crud ||= $query->{options}->{action}; |
223 |
|
$crud ||= 'RETRIEVE'; |
224 |
|
|
225 |
if (my $guid = $query->{options}->{GUID}) { |
if (my $guid = $query->{options}->{GUID}) { |
226 |
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
247 |
#$subnodes ||= $query->{payload}; |
#$subnodes ||= $query->{payload}; |
248 |
|
|
249 |
# dispatch action |
# dispatch action |
250 |
if ($action eq 'load') { |
if ($crud eq 'RETRIEVE') { |
251 |
my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit); |
my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit); |
252 |
return $self->sendCommand($sql); |
return $self->sendCommand($sql); |
253 |
} elsif ($action eq 'save') { |
|
254 |
|
} elsif ($crud eq 'UPDATE') { |
255 |
my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit); |
my $sql = hash2sql($query->{node}, $query->{payload}, 'UPDATE', $crit); |
256 |
$self->sendCommand($sql); |
$self->sendCommand($sql); |
257 |
|
|
258 |
|
} elsif ($crud eq 'DELETE') { |
259 |
|
my $sql = hash2sql($query->{node}, $query->{payload}, 'DELETE', $crit); |
260 |
|
$self->sendCommand($sql); |
261 |
|
|
262 |
} |
} |
263 |
|
|
264 |
} |
} |