Index: /main/trunk/greenstone2/perllib/dbutil.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil.pm	(revision 23399)
@@ -221,4 +221,32 @@
   my $infodb_key = shift(@_);
 
+  
+  if ($infodb_type eq "sqlite")
+  {
+    require dbutil::sqlite;
+    return &dbutil::sqlite::read_infodb_entry($infodb_file_path, $infodb_key, @_);
+  }
+#  elsif ($infodb_type eq "gdbm-txtgz")
+#  {
+#    require dbutil::gdbmtxtgz;
+#    return &dbutil::gdbmtxtgz::read_infodb_entry($infodb_file_path, $infodb_key, @_);
+#  }
+#  elsif ($infodb_type eq "jdbm")
+#  {
+#    require dbutil::jdbm;
+#    return &dbutil::jdbm::read_infodb_entry($infodb_file_path, $infodb_key, @_);
+#  }
+#  elsif ($infodb_type eq "mssql")
+#  {
+#    require dbutil::mssql;
+#    return &dbutil::mssql::read_infodb_entry($infodb_file_path, $infodb_key, @_);
+#  }
+  
+#  # Use GDBM if the infodb type is empty or not one of the values above
+#  require dbutil::gdbm;
+#  return &dbutil::gdbm::read_infodb_entry($infodb_file_path, $infodb_key, @_);
+  
+  
+  
   # !! TEMPORARY: Slow and naive implementation that just reads the entire file and picks out the one value
   # !! This will soon be replaced with database-specific versions that will use dbget etc.
@@ -294,4 +322,38 @@
   require dbutil::gdbm;
   return &dbutil::gdbm::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
+}
+
+
+sub set_infodb_entry
+{
+  my $infodb_type = shift(@_);
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_map = shift(@_);
+
+  if ($infodb_type eq "sqlite")
+  {
+    require dbutil::sqlite;
+    return &dbutil::sqlite::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_);
+  }
+  elsif ($infodb_type eq "gdbm-txtgz")
+  {
+    require dbutil::gdbmtxtgz;
+    return &dbutil::gdbmtxtgz::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_);
+  }
+  elsif ($infodb_type eq "jdbm")
+  {
+    require dbutil::jdbm;
+    return &dbutil::jdbm::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_);
+  }
+  elsif ($infodb_type eq "mssql")
+  {
+    require dbutil::mssql;
+    return &dbutil::mssql::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_);
+  }
+
+  # Use GDBM if the infodb type is empty or not one of the values above
+  require dbutil::gdbm;
+  return &dbutil::gdbm::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_);
 }
 
Index: /main/trunk/greenstone2/perllib/dbutil/gdbm.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil/gdbm.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil/gdbm.pm	(revision 23399)
@@ -158,4 +158,41 @@
 
 
+sub set_infodb_entry
+{
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+  
+	# Protect metadtaa values that go inside quotes for gdbmset
+    foreach my $k (keys %$infodb_map) {
+	  my @escaped_v = ();
+	  foreach my $v (@{$infodb_map->{$k}}) {
+	    if ($k eq "contains") {
+		  # protect quotes in ".2;".3 etc
+		  $v =~ s/\"/\\\"/g;
+		  push(@escaped_v, $v);
+	    }
+	    else {
+		  my $ev = &ghtml::unescape_html($v);
+		  $ev =~ s/\"/\\\"/g;
+		  push(@escaped_v, $ev);
+	    }
+	  }
+	  $infodb_map->{$k} = \@escaped_v;
+	}
+	
+    # Generate the record string
+    my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map);
+    ## print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n";
+
+    # Store it into GDBM
+    my $cmd = "gdbmset \"$infodb_file_path\" \"$infodb_key\" \"$serialized_infodb_map\"";
+    my $status = system($cmd);
+  
+	return $status;
+  
+}
+
+
 sub delete_infodb_entry
 {
Index: /main/trunk/greenstone2/perllib/dbutil/gdbmtxtgz.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil/gdbmtxtgz.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil/gdbmtxtgz.pm	(revision 23399)
@@ -184,4 +184,13 @@
 }
 
+ sub set_infodb_entry
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_map = shift(@_);
+  
+  print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n";
+}
+
 
 
Index: /main/trunk/greenstone2/perllib/dbutil/jdbm.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil/jdbm.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil/jdbm.pm	(revision 23399)
@@ -199,4 +199,14 @@
 
 
+sub set_infodb_entry
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_map = shift(@_);
+  
+  print STDERR "***** jdbm::set_infodb_entry() not implemented yet!\n";
+}
+
+
 sub delete_infodb_entry
 {
Index: /main/trunk/greenstone2/perllib/dbutil/mssql.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil/mssql.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil/mssql.pm	(revision 23399)
@@ -222,4 +222,14 @@
 }
 
+
+ sub set_infodb_entry
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_map = shift(@_);
+  
+  print STDERR "***** mssql::set_infodb_entry() not implemented yet!\n";
+}
+
 sub delete_infodb_entry
 {
Index: /main/trunk/greenstone2/perllib/dbutil/sqlite.pm
===================================================================
--- /main/trunk/greenstone2/perllib/dbutil/sqlite.pm	(revision 23398)
+++ /main/trunk/greenstone2/perllib/dbutil/sqlite.pm	(revision 23399)
@@ -37,5 +37,6 @@
 {
   my $infodb_file_path = shift(@_);
-
+  my $opt_append = shift(@_);
+ 
   my $sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}, "sqlite3" . &util::get_os_exe());
   my $infodb_handle = undef;
@@ -56,4 +57,9 @@
   binmode($infodb_handle,":utf8");
 
+  if (!(defined $opt_append) || ($opt_append ne "append")) {
+    print $infodb_handle "DROP TABLE IF EXISTS data;\n";
+	print $infodb_handle "DROP TABLE IF EXISTS document_metadata;\n";
+  }
+   
   print $infodb_handle "CREATE TABLE IF NOT EXISTS data (key TEXT PRIMARY KEY, value TEXT);\n";
   print $infodb_handle "CREATE TABLE IF NOT EXISTS document_metadata (id INTEGER PRIMARY KEY, docOID TEXT, element TEXT, value TEXT);\n";
@@ -161,4 +167,30 @@
       $infodb_map->{$key} = 1;
   }
+}
+
+sub read_infodb_rawentry
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+
+  
+  my $key_safe = &sqlite_safe($infodb_key);
+  my $select_val_cmd = "SELECT value FROM data WHERE key='$key_safe';";
+
+  my $val_str = read_infodb_cmd($infodb_file_path,$select_val_cmd);
+
+  return $val_str
+}
+
+sub read_infodb_entry
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_key = shift(@_);
+
+  my $val_str = read_infodb_rawentry($infodb_file_path,$infodb_key);
+  
+  my $rec_hash = &dbutil::convert_infodb_string_to_hash($val_str);
+
+  return $rec_hash;
 }
 
@@ -216,6 +248,4 @@
 }
 
-
-
 sub write_infodb_rawentry
 {
@@ -227,4 +257,35 @@
   print $infodb_handle "INSERT OR REPLACE INTO data (key, value) VALUES ('" . $safe_infodb_key . "', '" . &sqlite_safe($infodb_val) . "');\n";
 }
+
+
+sub set_infodb_entry
+{
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+	
+  my $sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}, "sqlite3" . &util::get_os_exe());
+  my $infodb_handle = undef;
+  my $cmd = "\"$sqlite3_exe\" \"$infodb_file_path\"";
+
+  if (!-e "$sqlite3_exe" || !open($infodb_handle, "|$cmd"))
+  {
+      print STDERR "Unable to execute: $cmd\n";
+      print STDERR "$!\n";
+	  return -1;
+  }
+  else {
+
+      binmode($infodb_handle, ":utf8");
+	  write_infodb_entry($infodb_handle,$infodb_key,$infodb_map);
+      close($infodb_handle);
+  }
+
+  # Not currently checking for errors on write to DB
+  return 0;
+  
+  
+	}
+	
 
 
