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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 09 Aug 2002 17:08:19 -0000


matthew		Fri Aug  9 13:08:19 2002 EDT

  Modified files:              
    /loncom/interface	lonmysql.pm 
  Log:
  General cleanups.
  Added new function &remove_from_table to remove a row from a table.
  
  
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.4 loncom/interface/lonmysql.pm:1.5
--- loncom/interface/lonmysql.pm:1.4	Mon Aug  5 08:43:18 2002
+++ loncom/interface/lonmysql.pm	Fri Aug  9 13:08:19 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # MySQL utility functions
 #
-# $Id: lonmysql.pm,v 1.4 2002/08/05 12:43:18 matthew Exp $
+# $Id: lonmysql.pm,v 1.5 2002/08/09 17:08:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -481,7 +481,7 @@
     # Determine the column order
     #
     $db_command = "DESCRIBE $tablename";
-    my $sth = $dbh->prepare($db_command);
+    $sth = $dbh->prepare($db_command);
     $sth->execute();
     if ($sth->err) {
         $errorstring = "$dbh ATTEMPTED:\n".$db_command."\nRESULTING ERROR:\n".
@@ -609,7 +609,6 @@
 ###############################
 sub get_new_table_id {
     my $newid = 0;
-    my $name_regex = '^'.$ENV{'user.name'}.'_'.$ENV{'user.domain'}."_(\d+)\$";
     my @tables = &tables_in_db();
     foreach (@tables) {
         if (/^$ENV{'user.name'}_$ENV{'user.domain'}_(\d+)$/) {
@@ -738,7 +737,7 @@
 ###########################################
 sub tables_in_db {
     return undef if (!defined(&connect_to_db()));
-    my $sth=$dbh->prepare('SHOW TABLES;');
+    my $sth=$dbh->prepare('SHOW TABLES');
     $sth->execute();
     if ($sth->err) {
         $errorstring = "$dbh ATTEMPTED:\n".'SHOW TABLES'.
@@ -808,6 +807,41 @@
     return $result;
 }
 
+###########################################
+
+=pod
+
+=item &remove_from_table($table_id,$column,$value)
+
+Executes a "delete from $tableid where $column like binary '$value'".
+
+=cut
+
+###########################################
+sub remove_from_table {
+    my ($table_id,$column,$value) = @_;
+    return undef if (!defined(&connect_to_db()));
+    #
+    $table_id = &translate_id($table_id);
+    my $command = 'DELETE FROM '.$table_id.' WHERE '.$dbh->quote($column).
+        " LIKE BINARY ".$dbh->quote($value);
+    my $sth = $dbh->prepare($command); 
+    $sth->execute();
+    if ($sth->err) {
+        $errorstring = "ERROR on execution of ".$command."\n".$sth->errstr;
+        return undef;
+    }
+    my $rows = $sth->rows;
+    return $rows;
+}
+
+
 1;
 
 __END__;
+
+=pod
+
+=back
+
+=cut