2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.6 2002/11/29 04:53:39 joko |
6 |
|
## + hash2Sql now knows about SQL_SELECT |
7 |
|
## |
8 |
## Revision 1.5 2002/11/17 07:18:38 joko |
## Revision 1.5 2002/11/17 07:18:38 joko |
9 |
## + small modification in hash2sql |
## + small modification in hash2sql |
10 |
## |
## |
29 |
use strict; |
use strict; |
30 |
use warnings; |
use warnings; |
31 |
|
|
|
use libp; |
|
|
use DBI; |
|
|
|
|
32 |
require Exporter; |
require Exporter; |
33 |
our @ISA = qw( Exporter ); |
our @ISA = qw( Exporter ); |
34 |
our @EXPORT = qw( |
our @EXPORT_OK = qw( |
35 |
testDsn hash2Sql |
testDsn hash2Sql |
36 |
SQL_INSERT SQL_UPDATE |
SQL_INSERT SQL_UPDATE |
37 |
connectTarget disconnectTarget sendSql |
connectTarget disconnectTarget sendSql |
41 |
testDsnForTables testDbServer |
testDsnForTables testDbServer |
42 |
); |
); |
43 |
|
|
44 |
|
|
45 |
|
use libp qw( croak ); |
46 |
|
use DBI; |
47 |
|
|
48 |
use constant SQL_INSERT => 10; |
use constant SQL_INSERT => 10; |
49 |
use constant SQL_UPDATE => 11; |
use constant SQL_UPDATE => 11; |
50 |
|
use constant SQL_SELECT => 12; |
51 |
|
|
52 |
my $dbmeta_ref_cache; |
my $dbmeta_ref_cache; |
53 |
|
|
77 |
} |
} |
78 |
} |
} |
79 |
|
|
80 |
|
|
81 |
|
# TODO: handle usage of "$crit" in an abstract way somehow |
82 |
sub hash2Sql { |
sub hash2Sql { |
83 |
|
|
84 |
my $table = shift; |
my $table = shift; |
87 |
my $crit = shift; |
my $crit = shift; |
88 |
|
|
89 |
my $sql; |
my $sql; |
90 |
if ($mode eq 'SQL_INSERT' || $mode == SQL_INSERT) { |
$mode = SQL_SELECT if ($mode eq 'SQL_SELECT' || $mode eq 'SELECT'); |
91 |
$sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; |
$mode = SQL_INSERT if ($mode eq 'SQL_INSERT' || $mode eq 'INSERT'); |
92 |
} |
$mode = SQL_UPDATE if ($mode eq 'SQL_UPDATE' || $mode eq 'UPDATE'); |
93 |
if ($mode eq 'SQL_UPDATE' || $mode == SQL_UPDATE) { |
|
94 |
$sql = "UPDATE $table SET #fields-values# WHERE $crit;"; |
if ($mode == SQL_SELECT) { |
95 |
|
$sql = "SELECT #fields# FROM $table WHERE $crit"; |
96 |
|
} elsif ($mode == SQL_INSERT) { |
97 |
|
$sql = "INSERT INTO $table (#fields#) VALUES (#values#)"; |
98 |
|
} elsif ($mode == SQL_UPDATE) { |
99 |
|
$sql = "UPDATE $table SET #fields-values# WHERE $crit"; |
100 |
} |
} |
101 |
|
|
102 |
my (@fields, @values); |
my (@fields, @values); |