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

matthew lon-capa-cvs@mail.lon-capa.org
Sun, 28 Jul 2002 18:21:13 -0000


matthew		Sun Jul 28 14:21:13 2002 EDT

  Modified files:              
    /loncom/interface	lonmysql.pm 
  Log:
  Replaced unimplemented &query_table with (implemented) &number_of_rows.
  Changed &get_rows to use WHERE instead of HAVING in SQL query.
  
  
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.1 loncom/interface/lonmysql.pm:1.2
--- loncom/interface/lonmysql.pm:1.1	Fri Jul 26 12:22:24 2002
+++ loncom/interface/lonmysql.pm	Sun Jul 28 14:21:13 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # MySQL utility functions
 #
-# $Id: lonmysql.pm,v 1.1 2002/07/26 16:22:24 matthew Exp $
+# $Id: lonmysql.pm,v 1.2 2002/07/28 18:21:13 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -330,19 +330,26 @@
 
 =pod
 
-=item &query_table()
+=item &number_of_rows()
 
-Currently unimplemented.
+Input: table identifier
+
+Returns: the number of rows in the given table.
 
 =cut
 
 ###############################
-sub query_table { 
-    # someday this will work.
+sub number_of_rows { 
+    my ($table_id) = @_;
+    # Update the table information
+    my %Table_Info = %{&get_table_info($table_id)};
+    # return the number of rows.
+    if (defined(%Table_Info)) {
+        return $Table_Info{'Rows'};
+    }
+    return undef;
 }
 
-
-
 ###############################
 
 =pod
@@ -577,7 +584,7 @@
 
 Returns: undef on error, an array ref to (array of) results on success.
 
-Internally, this function does a 'SELECT * FROM table HAVING $condition'.
+Internally, this function does a 'SELECT * FROM table WHERE $condition'.
 $condition = 'id>0' will result in all rows where column 'id' has a value
 greater than 0 being returned.
 
@@ -587,7 +594,7 @@
 sub get_rows {
     my ($table_id,$condition) = @_;
     my $tablename = &translate_id($table_id);
-    my $request = 'SELECT * FROM '.$tablename.' HAVING '.$condition;
+    my $request = 'SELECT * FROM '.$tablename.' WHERE '.$condition;
     my $sth=$dbh->prepare($request);
     $sth->execute();
     if ($sth->err) {