--- nfo/perl/libs/libdb.pm 2002/07/27 00:28:20 1.3 +++ nfo/perl/libs/libdb.pm 2002/11/17 07:18:38 1.5 @@ -1,7 +1,13 @@ ## -------------------------------------------------------------------------------- -## $Id: libdb.pm,v 1.3 2002/07/27 00:28:20 cvsjoko Exp $ +## $Id: libdb.pm,v 1.5 2002/11/17 07:18:38 joko Exp $ ## -------------------------------------------------------------------------------- ## $Log: libdb.pm,v $ +## Revision 1.5 2002/11/17 07:18:38 joko +## + small modification in hash2sql +## +## Revision 1.4 2002/10/16 22:36:42 joko +## + sub testDbServer +## ## Revision 1.3 2002/07/27 00:28:20 cvsjoko ## bugfixes ## @@ -32,7 +38,7 @@ dbNow getDbNameByDsn sqlDbAction createSqlDb dropSqlDb quotesql - testDsnForTables + testDsnForTables testDbServer ); use constant SQL_INSERT => 10; @@ -51,6 +57,21 @@ } } +sub testDbServer { + my $dsn = shift; + $dsn =~ s/database=(\w+)//; + + #print "testDbServer: $dsn", "\n"; + + my $result; + if ( my $dbh = DBI->connect($dsn, '', '', { + PrintError => 0, + } ) ) { + $dbh->disconnect(); + return 1; + } +} + sub hash2Sql { my $table = shift; @@ -59,10 +80,10 @@ my $crit = shift; my $sql; - if ($mode == SQL_INSERT) { + if ($mode eq 'SQL_INSERT' || $mode == SQL_INSERT) { $sql = "INSERT INTO $table (#fields#) VALUES (#values#);"; } - if ($mode == SQL_UPDATE) { + if ($mode eq 'SQL_UPDATE' || $mode == SQL_UPDATE) { $sql = "UPDATE $table SET #fields-values# WHERE $crit;"; } @@ -144,9 +165,10 @@ return 0; } if (my $result = $dbmeta_ref->{dbh}->prepare($sql)) { - if ($result->execute()) { + #if ($result->execute()) { + $result->execute(); return $result; - } + #} } } @@ -211,7 +233,9 @@ sub quotesql { my $string = shift; - $string =~ s/'/\\'/g; + if ($string) { + $string =~ s/'/\\'/g; + } return $string; }