2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.4 2002/10/16 22:36:42 joko |
6 |
|
## + sub testDbServer |
7 |
|
## |
8 |
## Revision 1.3 2002/07/27 00:28:20 cvsjoko |
## Revision 1.3 2002/07/27 00:28:20 cvsjoko |
9 |
## bugfixes |
## bugfixes |
10 |
## |
## |
35 |
dbNow |
dbNow |
36 |
getDbNameByDsn sqlDbAction createSqlDb dropSqlDb |
getDbNameByDsn sqlDbAction createSqlDb dropSqlDb |
37 |
quotesql |
quotesql |
38 |
testDsnForTables |
testDsnForTables testDbServer |
39 |
); |
); |
40 |
|
|
41 |
use constant SQL_INSERT => 10; |
use constant SQL_INSERT => 10; |
54 |
} |
} |
55 |
} |
} |
56 |
|
|
57 |
|
sub testDbServer { |
58 |
|
my $dsn = shift; |
59 |
|
$dsn =~ s/database=(\w+)//; |
60 |
|
|
61 |
|
#print "testDbServer: $dsn", "\n"; |
62 |
|
|
63 |
|
my $result; |
64 |
|
if ( my $dbh = DBI->connect($dsn, '', '', { |
65 |
|
PrintError => 0, |
66 |
|
} ) ) { |
67 |
|
$dbh->disconnect(); |
68 |
|
return 1; |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
sub hash2Sql { |
sub hash2Sql { |
73 |
|
|
74 |
my $table = shift; |
my $table = shift; |
77 |
my $crit = shift; |
my $crit = shift; |
78 |
|
|
79 |
my $sql; |
my $sql; |
80 |
if ($mode == SQL_INSERT) { |
if ($mode == SQL_INSERT || $mode eq 'SQL_INSERT') { |
81 |
$sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; |
$sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; |
82 |
} |
} |
83 |
if ($mode == SQL_UPDATE) { |
if ($mode == SQL_UPDATE || $mode eq 'SQL_UPDATE') { |
84 |
$sql = "UPDATE $table SET #fields-values# WHERE $crit;"; |
$sql = "UPDATE $table SET #fields-values# WHERE $crit;"; |
85 |
} |
} |
86 |
|
|
162 |
return 0; |
return 0; |
163 |
} |
} |
164 |
if (my $result = $dbmeta_ref->{dbh}->prepare($sql)) { |
if (my $result = $dbmeta_ref->{dbh}->prepare($sql)) { |
165 |
if ($result->execute()) { |
#if ($result->execute()) { |
166 |
|
$result->execute(); |
167 |
return $result; |
return $result; |
168 |
} |
#} |
169 |
} |
} |
170 |
} |
} |
171 |
|
|
230 |
|
|
231 |
sub quotesql { |
sub quotesql { |
232 |
my $string = shift; |
my $string = shift; |
233 |
$string =~ s/'/\\'/g; |
if ($string) { |
234 |
|
$string =~ s/'/\\'/g; |
235 |
|
} |
236 |
return $string; |
return $string; |
237 |
} |
} |
238 |
|
|