/[cvs]/nfo/perl/libs/libdb.pm
ViewVC logotype

Diff of /nfo/perl/libs/libdb.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by cvsjoko, Sat Jul 27 00:28:20 2002 UTC revision 1.4 by joko, Wed Oct 16 22:36:42 2002 UTC
# Line 2  Line 2 
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  ##  ##
# Line 32  our @EXPORT = qw( Line 35  our @EXPORT = qw(
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;
# Line 51  sub testDsn { Line 54  sub testDsn {
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;
# Line 59  sub hash2Sql { Line 77  sub hash2Sql {
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        
# Line 144  sub sendSql { Line 162  sub sendSql {
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    
# Line 211  sub dropSqlDb { Line 230  sub dropSqlDb {
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    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed