[LON-CAPA-cvs] cvs: loncom /metadata_database/LONCAPA lonmetadata.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Thu, 08 Apr 2004 14:50:44 -0000
matthew Thu Apr 8 10:50:44 2004 EDT
Modified files:
/loncom/metadata_database/LONCAPA lonmetadata.pm
Log:
Modified &store_metadata to take a table name as a parameter.
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.3 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.4
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.3 Mon Jan 12 16:48:38 2004
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm Thu Apr 8 10:50:44 2004
@@ -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 @@
=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 @@
## $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 @@
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()) {