Diff for /loncom/metadata_database/LONCAPA/lonmetadata.pm between versions 1.1 and 1.3

version 1.1, 2004/01/12 15:07:08 version 1.3, 2004/01/12 21:48:38
Line 165  my @Fulltext_indicies = qw/ Line 165  my @Fulltext_indicies = qw/
   
 Input: None  Input: None
   
 Returns: An array of hash references describing the columns and rows  Returns: An array of hash references describing the columns and indicies
 of the metadata table.  of the metadata table(s).
   
 =cut  =cut
   
Line 183  sub describe_metadata_storage { Line 183  sub describe_metadata_storage {
   
 =item create_metadata_storage()  =item create_metadata_storage()
   
 Inputs: None  Inputs: table name (optional): the name of the table.  Default is 'metadata'.
   
 Returns: A perl string which, when executed by MySQL, will cause the  Returns: A perl string which, when executed by MySQL, will cause the
 metadata storage to be initialized.  metadata storage to be initialized.
Line 193  metadata storage to be initialized. Line 193  metadata storage to be initialized.
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
 sub create_metadata_storage {   sub create_metadata_storage { 
     my $tablename = 'metadata';      my ($tablename) = @_;
       $tablename = 'metadata' if (! defined($tablename));
     my $request = "CREATE TABLE IF NOT EXISTS ".$tablename." ";      my $request = "CREATE TABLE IF NOT EXISTS ".$tablename." ";
     #      #
     # Process the columns  (this code is stolen from lonmysql.pm)      # Process the columns  (this code is stolen from lonmysql.pm)
Line 230  sub create_metadata_storage { Line 231  sub create_metadata_storage {
         my $text = 'FULLTEXT idx_'.$colname.' ('.$colname.')';          my $text = 'FULLTEXT idx_'.$colname.' ('.$colname.')';
         push (@Columns,$text);          push (@Columns,$text);
     }      }
     $request .= "(".join(", ",@Columns).") ";      $request .= "(".join(", ",@Columns).") TYPE=MyISAM";
     return $request;      return $request;
 }  }
   
Line 250  Returns: 1 on success, 0 on failure to s Line 251  Returns: 1 on success, 0 on failure to s
   
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
   {
       ##
       ##  WARNING: The following cleverness may cause trouble in cases where
       ##  the dbi connection is dropped and recreated - a stale statement
       ##  handler may linger around and cause trouble.
       ##
       ##  In most scripts, this will work fine.  If the dbi is going to be
       ##  dropped and (possibly) later recreated, call &clear_sth.  Yes it
       ##  is annoying but $sth appearantly does not have a link back to the 
       ##  $dbh, so we can't check our validity.
       ##
       my $sth = undef;
   
   sub create_statement_handler {
       my $dbh = shift();
       my $request = 'INSERT INTO metadata VALUES(';
       foreach (@Metadata_Table_Description) {
           $request .= '?,';
       }
       chop $request;
       $request.= ')';
       $sth = $dbh->prepare($request);
       return;
   }
   
   sub clear_sth { $sth=undef; }
   
 sub store_metadata {  sub store_metadata {
       my $dbh = shift();
       my $errors = '';
       if (! defined($sth)) {
           &create_statement_handler($dbh);
       }
       my $successcount = 0;
       while (my $mdata = shift()) {
           next if (ref($mdata) ne "HASH");
           my @MData;
           foreach my $field (@Metadata_Table_Description) {
               if (exists($mdata->{$field->{'name'}})) {
                   push(@MData,$mdata->{$field->{'name'}});
               } else {
                   push(@MData,undef);
               }
           }
           $sth->execute(@MData);
           if (! $sth->err) {
               $successcount++;
           } else {
               $errors = join(',',$errors,$sth->errstr);
           }
       }
       if (wantarray()) {
           return ($successcount,$errors);
       } else {
           return $successcount;
       }
   }
   
 }  }
   
Line 264  sub store_metadata { Line 321  sub store_metadata {
 Inputs: database handle ($dbh) and a hash or hash reference containing   Inputs: database handle ($dbh) and a hash or hash reference containing 
 metadata which will be used for a search.  metadata which will be used for a search.
   
 Returns:   Returns: scalar with error string on failure, array reference on success.
   The array reference is the same one returned by $sth->fetchall_arrayref().
   
 =cut  =cut
   
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
 sub lookup_metadata {}  sub lookup_metadata {
       my ($dbh,$condition,$fetchparameter) = @_;
       my $error;
       my $returnvalue=[];
       my $request = 'SELECT * FROM metadata';
       if (defined($condition)) {
           $request .= ' WHERE '.$condition;
       }
       my $sth = $dbh->prepare($request);
       if ($sth->err) {
           $error = $sth->errstr;
       }
       if (! $error) {
           $sth->execute();
           if ($sth->err) {
               $error = $sth->errstr;
           } else {
               $returnvalue = $sth->fetchall_arrayref($fetchparameter);
               if ($sth->err) {
                   $error = $sth->errstr;
               }
           }
       }
       return ($error,$returnvalue);
   }
   
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################

Removed from v.1.1  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>