/[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.5 by joko, Sun Nov 17 07:18:38 2002 UTC
# Line 2  Line 2 
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  ##  ##
# Line 32  our @EXPORT = qw( Line 38  our @EXPORT = qw(
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;
# Line 51  sub testDsn { Line 57  sub testDsn {
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;
# Line 59  sub hash2Sql { Line 80  sub hash2Sql {
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        
# Line 144  sub sendSql { Line 165  sub sendSql {
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    
# Line 211  sub dropSqlDb { Line 233  sub dropSqlDb {
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    

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

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