2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.5 2002/11/17 07:18:38 joko |
6 |
|
## + small modification in hash2sql |
7 |
|
## |
8 |
|
## Revision 1.4 2002/10/16 22:36:42 joko |
9 |
|
## + sub testDbServer |
10 |
|
## |
11 |
## Revision 1.3 2002/07/27 00:28:20 cvsjoko |
## Revision 1.3 2002/07/27 00:28:20 cvsjoko |
12 |
## bugfixes |
## bugfixes |
13 |
## |
## |
38 |
dbNow |
dbNow |
39 |
getDbNameByDsn sqlDbAction createSqlDb dropSqlDb |
getDbNameByDsn sqlDbAction createSqlDb dropSqlDb |
40 |
quotesql |
quotesql |
41 |
testDsnForTables |
testDsnForTables testDbServer |
42 |
); |
); |
43 |
|
|
44 |
use constant SQL_INSERT => 10; |
use constant SQL_INSERT => 10; |
57 |
} |
} |
58 |
} |
} |
59 |
|
|
60 |
|
sub testDbServer { |
61 |
|
my $dsn = shift; |
62 |
|
$dsn =~ s/database=(\w+)//; |
63 |
|
|
64 |
|
#print "testDbServer: $dsn", "\n"; |
65 |
|
|
66 |
|
my $result; |
67 |
|
if ( my $dbh = DBI->connect($dsn, '', '', { |
68 |
|
PrintError => 0, |
69 |
|
} ) ) { |
70 |
|
$dbh->disconnect(); |
71 |
|
return 1; |
72 |
|
} |
73 |
|
} |
74 |
|
|
75 |
sub hash2Sql { |
sub hash2Sql { |
76 |
|
|
77 |
my $table = shift; |
my $table = shift; |
80 |
my $crit = shift; |
my $crit = shift; |
81 |
|
|
82 |
my $sql; |
my $sql; |
83 |
if ($mode == SQL_INSERT) { |
if ($mode eq 'SQL_INSERT' || $mode == SQL_INSERT) { |
84 |
$sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; |
$sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; |
85 |
} |
} |
86 |
if ($mode == SQL_UPDATE) { |
if ($mode eq 'SQL_UPDATE' || $mode == SQL_UPDATE) { |
87 |
$sql = "UPDATE $table SET #fields-values# WHERE $crit;"; |
$sql = "UPDATE $table SET #fields-values# WHERE $crit;"; |
88 |
} |
} |
89 |
|
|
165 |
return 0; |
return 0; |
166 |
} |
} |
167 |
if (my $result = $dbmeta_ref->{dbh}->prepare($sql)) { |
if (my $result = $dbmeta_ref->{dbh}->prepare($sql)) { |
168 |
if ($result->execute()) { |
#if ($result->execute()) { |
169 |
|
$result->execute(); |
170 |
return $result; |
return $result; |
171 |
} |
#} |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
233 |
|
|
234 |
sub quotesql { |
sub quotesql { |
235 |
my $string = shift; |
my $string = shift; |
236 |
$string =~ s/'/\\'/g; |
if ($string) { |
237 |
|
$string =~ s/'/\\'/g; |
238 |
|
} |
239 |
return $string; |
return $string; |
240 |
} |
} |
241 |
|
|