--- loncom/metadata_database/LONCAPA/lonmetadata.pm 2004/01/12 21:48:38 1.3 +++ loncom/metadata_database/LONCAPA/lonmetadata.pm 2004/04/08 14:50:44 1.4 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonmetadata.pm,v 1.3 2004/01/12 21:48:38 matthew Exp $ +# $Id: lonmetadata.pm,v 1.4 2004/04/08 14:50:44 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -242,8 +242,8 @@ sub create_metadata_storage { =item store_metadata() -Inputs: database handle ($dbh) and a hash or hash reference containing the -metadata for a single resource. +Inputs: database handle ($dbh), a table name, and a hash or hash reference +containing the metadata for a single resource. Returns: 1 on success, 0 on failure to store. @@ -263,10 +263,14 @@ Returns: 1 on success, 0 on failure to s ## $dbh, so we can't check our validity. ## my $sth = undef; + my $sth_table = undef; sub create_statement_handler { my $dbh = shift(); - my $request = 'INSERT INTO metadata VALUES('; + my $tablename = shift(); + $tablename = 'metadata' if (! defined($tablename)); + $sth_table = $tablename; + my $request = 'INSERT INTO '.$tablename.' VALUES('; foreach (@Metadata_Table_Description) { $request .= '?,'; } @@ -276,13 +280,16 @@ sub create_statement_handler { return; } -sub clear_sth { $sth=undef; } +sub clear_sth { $sth=undef; $sth_table=undef;} sub store_metadata { my $dbh = shift(); + my $tablename = shift(); my $errors = ''; - if (! defined($sth)) { - &create_statement_handler($dbh); + if (! defined($sth) || + ( defined($tablename) && ($sth_table ne $tablename)) || + (! defined($tablename) && $sth_table ne 'metadata')) { + &create_statement_handler($dbh,$tablename); } my $successcount = 0; while (my $mdata = shift()) {