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

version 1.1, 2004/01/12 15:07:08 version 1.2, 2004/01/12 21:32:20
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 250  Returns: 1 on success, 0 on failure to s Line 250  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 320  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.2


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