[evolvis-commits] r7264: Added the db_drop_table_if_exists function. ↵

mirabilos at evolvis.org mirabilos at evolvis.org
Thu Feb 24 15:37:24 CET 2011


Author: mirabilos
Date: 2011-02-24 15:37:24 +0100 (Thu, 24 Feb 2011)
New Revision: 7264

Modified:
   trunk/gforge_base/evolvisforge-5.1/gforge/utils/include.pl
Log:
Added the db_drop_table_if_exists function.


Modified: trunk/gforge_base/evolvisforge-5.1/gforge/utils/include.pl
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/utils/include.pl	2011-02-24 14:37:23 UTC (rev 7263)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/utils/include.pl	2011-02-24 14:37:24 UTC (rev 7264)
@@ -47,6 +47,21 @@
 	die "Cannot connect to database: $!" if ( ! $dbh );
 }
 
+sub db_drop_table_if_exists {
+    my ($sql, $res, $n, $tn) ;
+    $tn = shift ;
+    $sql = "SELECT COUNT(*) FROM pg_class WHERE relname='$tn'";
+    $res = $dbh->prepare($sql);
+    $res->execute();
+    ($n) = $res->fetchrow() ;
+    $res->finish () ;
+    if ($n != 0) {
+	$sql = "DROP TABLE $tn";
+	$res = $dbh->prepare($sql);
+	$res->finish () ;
+    }
+}
+
 ##############################
 # File open function, spews the entire file to an array.
 ##############################



More information about the evolvis-commits mailing list