[LON-CAPA-cvs] cvs: loncom /interface lonmysql.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 02 Jun 2003 16:44:01 -0000


matthew		Mon Jun  2 12:44:01 2003 EDT

  Modified files:              
    /loncom/interface	lonmysql.pm 
  Log:
  Added &drop_table($tableid) to drop tables when we need to clean up.
  
  
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.13 loncom/interface/lonmysql.pm:1.14
--- loncom/interface/lonmysql.pm:1.13	Fri Apr 18 11:50:55 2003
+++ loncom/interface/lonmysql.pm	Mon Jun  2 12:44:01 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # MySQL utility functions
 #
-# $Id: lonmysql.pm,v 1.13 2003/04/18 15:50:55 matthew Exp $
+# $Id: lonmysql.pm,v 1.14 2003/06/02 16:44:01 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1013,6 +1013,33 @@
     return $rows;
 }
 
+###########################################
+
+=pod
+
+=item drop_table($table_id)
+
+Issues a 'drop table if exists' command
+
+=cut
+
+###########################################
+
+sub drop_table {
+    my ($table_id) = @_;
+    return undef if (!defined(&connect_to_db()));
+    #
+    $table_id = &translate_id($table_id);
+    my $command = 'DROP TABLE IF EXISTS '.$table_id;
+    my $sth = $dbh->prepare($command); 
+    $sth->execute();
+    if ($sth->err) {
+        $errorstring = "ERROR on execution of ".$command."\n".$sth->errstr;
+        return undef;
+    }
+    $debugstring = $command;
+    return 1; # if we got here there was no error, so return a 'true' value
+}
 
 1;