Index: /main/trunk/greenstone2/perllib/DBDrivers/70HyphenFormat.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/70HyphenFormat.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/70HyphenFormat.pm	(revision 30355)
@@ -0,0 +1,380 @@
+###############################################################################
+#
+# 70HyphenFormat.pm -- The parent class of drivers that use the basic GS format
+#                      of a text obeying these rules:
+#
+#                      <line>      := <uniqueid> <metadata>+ <separator>
+#                      <uniqueid>  := \[[a-z][a-z0-9]*\]\n
+#                      <metadata>  := <[a-z][a-z0-9]*>(^-{70})+\n
+#                      <separator> := -{70}\n
+#
+#                      Contains some utility functions useful to any driver
+#                      that makes use of this format.
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+# Note: This driver may be a candidate for further splitting, maybe into a
+# PipedExecutableDriver and a 70HyphenFormatDriver... but for now all piped
+# drivers are 70 hyphen format ones, so, yeah.
+
+package DBDrivers::70HyphenFormat;
+
+# Pragma
+use strict;
+
+# Libraries
+use ghtml;
+use util;
+use FileUtils;
+use parent 'DBDrivers::BaseDBDriver';
+
+use constant {
+    RWMODE_READ  => '-|',
+    RWMODE_WRITE => '|-',
+};
+
+## @function constructor
+#
+sub new
+{
+    my $class = shift(@_);
+    my $self = DBDrivers::BaseDBDriver->new(@_);
+    $self->{'executable_path'} = 'error';
+    $self->{'keyread_executable'} = 'error';
+    $self->{'read_executable'} = 'error';
+    $self->{'write_executable'} = 'error';
+    #
+    $self->{'forced_affinity'} = -1; # Set to processor number for forced affinity
+    bless($self, $class);
+    return $self;
+}
+## new(void) => 70HyphenFormat ##
+
+
+################################## Protected ##################################
+
+
+## @function close_infodb_write_handle(filehandle)
+#
+sub close_infodb_write_handle
+{
+    my $self = shift(@_);
+    $self->debugPrintFunctionHeader(@_);
+    my $handle = shift(@_);
+    my $force_close = shift(@_); # Undefined most of the time
+    my $continue_close = $self->removeConnectionIfPersistent($handle, $force_close);
+    if ($continue_close) {
+	close($handle);
+    }
+    return;
+}
+## close_infodb_write_handle(filehandle) => void ##
+
+
+## @function delete_infodb_entry(filehandle, string)
+#
+sub delete_infodb_entry
+{
+    my $self = shift(@_);
+    $self->debugPrintFunctionHeader(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    # A minus at the end of a key (after the ]) signifies 'delete'
+    print $infodb_handle '[' . $infodb_key . ']-' . "\n";
+    # The 70 minus signs are also needed, to help make the parsing by db2txt simple
+    print $infodb_handle '-' x 70, "\n";
+}
+## delete_infodb_entry(filehandle, string) => void ##
+
+
+## @function open_infodb_write_handle(string, string)
+#
+sub open_infodb_write_handle
+{
+    my $self = shift(@_);
+    $self->debugPrintFunctionHeader(@_);
+    my $path = shift(@_);
+    my $append = shift(@_);
+    my $infodb_file_handle = $self->retrieveConnectionIfPersistent($path, $append);;
+    # No available existing connection
+    if (!defined $infodb_file_handle || !$infodb_file_handle) {
+        $infodb_file_handle = $self->openWriteHandle($path, $append, @_);
+	$self->registerConnectionIfPersistent($infodb_file_handle, $path, $append);
+    }
+    return $infodb_file_handle;
+}
+## open_infodb_write_handle(string, string) => filehandle ##
+
+
+## @function openPipedHandle(integer, string, string, string*) => filehandle
+#
+sub openPipedHandle
+{
+    my $self = shift(@_);
+    my $mode = shift(@_);
+    my $executable_and_default_args = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my ($executable, $default_args) = $executable_and_default_args =~ /^([a-z0-9]+)\s*(.*)$/;
+    my $exe = &FileUtils::filenameConcatenate($self->{'executable_path'}, $executable . &util::get_os_exe());
+    if (!-e $exe) {
+	# Hope it's on path
+	$exe = $executable . &util::get_os_exe();
+    }
+    my $infodb_file_handle = undef;
+    my $cmd = '';
+    if ($self->{'forced_affinity'} >= 0)
+    {
+        $cmd = 'taskset -c ' . $self->{'forced_affinity'} . ' ';
+    }
+    $cmd .= '"' . $exe . '" ' . $default_args;
+    foreach my $open_arg (@_) {
+	# Special - append is typically missing a hyphen
+	if ($open_arg eq 'append') {
+	    $open_arg = '-append';
+	}
+	$cmd .= ' ' . $open_arg;
+    }
+    $cmd .= ' "' . $infodb_file_path . '"';
+    $self->debugPrint("CMD: '" . $cmd . "'\n");
+    if(!open($infodb_file_handle, $mode . ':utf8', $cmd)) {
+        print STDERR "Error: Failed to open pipe to '$cmd'\n";
+        print STDERR "       $!\n";
+        return undef;
+    }
+    #binmode($infodb_file_handle,":utf8");
+    return $infodb_file_handle;
+}
+## openPipedHandle(integer, string, string, string*) => filehandle ##
+
+
+## @function openReadHandle(string, string) => filehandle
+#
+sub openReadHandle
+{
+    my $self = shift(@_);
+    return $self->openPipedHandle(RWMODE_READ, $self->{'read_executable'}, @_);
+}
+## openReadHandle(string, string) => filehandle
+
+
+## @function openWriteHandle(*) => filehandle
+#
+sub openWriteHandle
+{
+    my $self = shift(@_);
+    return $self->openPipedHandle(RWMODE_WRITE, $self->{'write_executable'}, @_);
+}
+## openWriteHandle(*) => filehandle ##
+
+
+## @function read_infodb_entry(string, string) => hashmap
+#
+sub read_infodb_entry
+{
+    my $self = shift(@_);
+    my $raw_string = $self->read_infodb_rawentry(@_);
+    my $infodb_rec = $self->convert_infodb_string_to_hash($raw_string);
+    return $infodb_rec;
+}
+## read_infodb_entry(string, string) => hashmap ##
+
+
+## @function read_infodb_file(string, hashmap) => void
+#
+sub read_infodb_file
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_map = shift(@_);
+    $self->debugPrintFunctionHeader($infodb_file_path, $infodb_map);
+    my $infodb_file_handle = $self->openReadHandle($infodb_file_path);
+    my $infodb_line = "";
+    my $infodb_key = "";
+    my $infodb_value = "";
+    while (defined ($infodb_line = <$infodb_file_handle>)) {
+        $infodb_line =~ s/(\r\n)+$//; # more general than chomp
+        if ($infodb_line =~ /^\[([^\]]+)\]$/) {
+            $infodb_key = $1;
+        }
+        elsif ($infodb_line =~ /^-{70}$/) {
+            $infodb_map->{$infodb_key} = $infodb_value;
+            $infodb_key = "";
+            $infodb_value = "";
+        }
+        else {
+            $infodb_value .= $infodb_line;
+        }
+    }
+  $self->close_infodb_write_handle($infodb_file_handle);
+}
+## read_infodb_file(string, hashmap) => void ##
+
+
+## @function read_infodb_keys(string, hashmap) => void
+#
+sub read_infodb_keys
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_map = shift(@_);
+    my $infodb_file_handle = $self->openPipedHandle(RWMODE_READ, $self->{'keyread_executable'}, $infodb_file_path);
+    if (!$infodb_file_handle) {
+	die("Couldn't open pipe from gdbmkeys: " . $infodb_file_path . "\n");
+    }
+    my $infodb_line = "";
+    my $infodb_key = "";
+    my $infodb_value = "";
+    # Simple case - dedicated keyread exe, so keys are strings
+    if ($self->{'keyread_executable'} ne $self->{'read_executable'}) {
+	while (defined ($infodb_line = <$infodb_file_handle>)) {
+	    $infodb_line =~ s/[\r\n]+$//;
+	    $infodb_map->{$infodb_line} = 1;
+	}
+    }
+    # Slightly more difficult - have to parse keys out of 70hyphen format
+    else {
+	while (defined ($infodb_line = <$infodb_file_handle>)) {
+	    if ($infodb_line =~ /^\[([^\]]+)\](-)?[\r\n]*$/) {
+		my $key = $1;
+		my $delete_flag = $2;
+		if (defined $delete_flag) {
+		    delete $infodb_map->{$key}
+		}
+		else {
+		    $infodb_map->{$key} = 1;
+		}
+	    }
+	}
+    }
+    $self->close_infodb_write_handle($infodb_file_handle);
+}
+## read_infodb_keys(string, hashmap) => void ##
+
+
+## @function read_infodb_rawentry(string, string) => string
+#
+# !! TEMPORARY: Slow and naive implementation that just reads the entire file
+# and picks out the one value. This should one day be replaced with database-
+# specific versions that will use dbget etc.
+#
+sub read_infodb_rawentry
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    # temporary hashmap... we're only interested in one entry
+    my $infodb_map = {};
+    $self->read_infodb_file($infodb_file_path, $infodb_map);
+    return $infodb_map->{$infodb_key};
+}
+## read_infodb_rawentry(string, string) => string ##
+
+
+## @function set_infodb_entry(string, string, hashmap)
+#
+sub set_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+
+    # HTML escape anything that is not part of the "contains" metadata value
+    foreach my $k (keys %$infodb_map) {
+	my @escaped_v = ();
+	foreach my $v (@{$infodb_map->{$k}}) {
+	    if ($k eq "contains") {
+		push(@escaped_v, $v);
+	    }
+	    else {
+		my $ev = &ghtml::unescape_html($v);
+		push(@escaped_v, $ev);
+	    }
+	}
+	$infodb_map->{$k} = \@escaped_v;
+    }
+
+    # Generate the record string
+    my $serialized_infodb_map = $self->convert_infodb_hash_to_string($infodb_map);
+
+    # Store it into DB using '... -append' which despite its name actually
+    # replaces the record if it already exists
+    my $status = undef;
+    my $infodb_file_handle = $self->openWriteHandle($infodb_file_path, '-append');
+    if (!$infodb_file_handle) {
+	print STDERR "Error: set_infodb_entry() failed to open pipe to: " . $infodb_file_handle ."\n";
+	print STDERR "       $!\n";
+	$status = -1;
+    }
+    else {
+	print $infodb_file_handle "[$infodb_key]\n";
+	print $infodb_file_handle "$serialized_infodb_map\n";
+	$self->close_infodb_write_handle($infodb_file_handle);
+	$status = 0; # as in exit status of cmd OK
+    }
+    return $status;
+}
+## set_infodb_entry(string, string, hashmap) => integer ##
+
+
+## @function write_infodb_entry(filehandle, string, hashmap)
+#
+sub write_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+
+    print $infodb_handle "[$infodb_key]\n";
+    foreach my $infodb_value_key (sort keys(%$infodb_map)) {
+        foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
+            if ($infodb_value =~ /-{70,}/) {
+                # if value contains 70 or more hyphens in a row we need to escape them
+                # to prevent txt2db from treating them as a separator
+                $infodb_value =~ s/-/&\#045;/gi;
+            }
+            print $infodb_handle "<$infodb_value_key>" . $infodb_value . "\n";
+        }
+    }
+    print $infodb_handle '-' x 70, "\n";
+}
+## write_infodb_entry(filehandle, string, hashmap) => void ##
+
+
+## @function write_infodb_rawentry(filehandle, string, string)
+#
+sub write_infodb_rawentry
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_val = shift(@_);
+
+    print $infodb_handle "[$infodb_key]\n";
+    print $infodb_handle "$infodb_val\n";
+    print $infodb_handle '-' x 70, "\n";
+}
+## write_infodb_rawentry(filehandle, string, string) ##
+
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/BaseDBDriver.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/BaseDBDriver.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/BaseDBDriver.pm	(revision 30355)
@@ -0,0 +1,540 @@
+###############################################################################
+#
+# BaseDBDriver.pm -- base class for all the database drivers
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (c) 2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::BaseDBDriver;
+
+# Pragma
+use strict;
+no strict 'subs';
+no strict 'refs'; # allow filehandles to be variables and viceversa
+
+# Libaries
+use Time::HiRes qw( gettimeofday );
+use gsprintf 'gsprintf';
+
+
+## @function constructor
+#
+sub new
+{
+    my $class = shift(@_);
+    my $debug = shift(@_);
+    my $self = {};
+    # Debug messages for this driver
+    $self->{'debug'} = $debug; # 1 to enable
+    # We'll use this in places other than 70HyphenFormat
+    $self->{'70hyphen'} = '-' x 70;
+    # Keep track of all opened file handles, but only for drivers that support
+    # persistent connections
+    $self->{'handle_pool'} = {};
+    # Default file extension - in this case it is an error to create a DB from
+    # BaseDBDriver
+    $self->{'default_file_extension'} = 'err';
+    # Support
+    $self->{'supports_datestamp'} = 0;
+    $self->{'supports_merge'} = 0;
+    $self->{'supports_persistentconnection'} = 0;
+    $self->{'supports_rss'} = 0;
+    $self->{'supports_set'} = 0;
+    $self->{'write_only'} = 0; # Some drivers are one way - i.e. STDOUTXML
+    bless($self, $class);
+    return $self;
+}
+## new(void) => BaseDBDriver ##
+
+
+## @function DESTROY
+#
+# Built-in destructor block that, unlike END, gets passed a reference to self.
+# Responsible for properly closing any open database handles.
+#
+sub DESTROY
+{
+    my $self = shift(@_);
+    # Close all remaining filehandles
+    foreach my $infodb_file_path (keys(%{$self->{'handle_pool'}})) {
+	my $infodb_handle = $self->{'handle_pool'}->{$infodb_file_path};
+	# By passing the filepath as the second argument we instruct the driver
+	# that we actually want to close the connection by passing a non-zero
+	# value, but we sneakily optimize things a little as the close method
+	# can now check to see if it's been provided a file_path rather than
+	# having to search the handle pool for it. The file_path is needed to
+	# remove the closed handle from the pool anyway.
+	$self->close_infodb_write_handle($infodb_handle, $infodb_file_path);
+    }
+}
+## DESTROY(void) => void ##
+
+
+###############################################################################
+## Protected Functions
+###############################################################################
+
+
+## @function debugPrint(string) => void
+#
+sub debugPrint
+{
+    my $self = shift(@_);
+    my $message = shift(@_);
+    if ($self->{'debug'}) {
+	my ($seconds, $microseconds) = gettimeofday();
+	print STDERR '[DEBUG:' . $seconds . '.' . $microseconds . '] ' . (caller 1)[3] . '() ' . $message . "\n";
+    }
+}
+## debugPrint(string) => void ##
+
+
+## @function debugPrintFunctionHeader(*) => void
+#
+sub debugPrintFunctionHeader
+{
+    my $self = shift(@_);
+    if ($self->{'debug'}) {
+	my @arguments;
+	foreach my $argument (@_) {
+	    if ($argument !~ /^-?\d+(\.?\d+)?$/) {
+		push(@arguments, '"' . $argument . '"');
+	    }
+	    else {
+		push(@arguments, $argument);
+	    }
+	}
+	my $message = '(' . join(', ', @arguments) . ')';
+	# Would love to just call debugPrint() here, but then caller would be wrong
+	my ($seconds, $microseconds) = gettimeofday();
+	print STDERR '[DEBUG:' . $seconds . '.' . $microseconds . '] ' . (caller 1)[3] . $message . "\n";
+    }
+}
+## debugPrintFunctionHeader(*) => void
+
+
+## @function errorPrint(string, integer) => void
+#
+sub errorPrint
+{
+    my $self = shift(@_);
+    my $message = shift(@_);
+    my $is_fatal = shift(@_);
+    print STDERR 'Error in ' . (caller 1)[3] . '! ' . $message . "\n";
+    if ($is_fatal) {
+	exit();
+    }
+}
+## errorPrint(string, integer) => void ##
+
+
+## @function registerConnectionIfPersistent(filehandle, string, string) => void
+#
+sub registerConnectionIfPersistent
+{
+    my $self = shift(@_);
+    my $conn = shift(@_);
+    my $path = shift(@_);
+    my $append = shift(@_);
+    if ($self->{'supports_persistentconnection'}) {
+	$self->debugPrintFunctionHeader($conn, $path, $append);
+	my $fhid = $path;
+	if (defined $append && $append eq '-append') {
+	    $fhid .= ' [APPEND]';
+	}
+	$self->debugPrint('Registering connection: "' . $fhid . '"');
+	$self->{'handle_pool'}->{$fhid} = $conn;
+    }
+    return;
+}
+## registerConnectionIfPersistent(filehandle, string, string) => void ##
+
+
+## @function removeConnectionIfPersistent(filehandle, string) => integer
+#
+sub removeConnectionIfPersistent
+{
+    my $self = shift(@_);
+    my $handle = shift(@_);
+    my $force_close = shift(@_);
+    my $continue_close = 1;
+    if ($self->{'supports_persistentconnection'}) {
+	$self->debugPrintFunctionHeader($handle, $force_close);
+	if (defined($force_close)) {
+	    # We'll need the file path so we can locate and remove the entry
+	    # in the handle pool (plus possibly the [APPEND] suffix for those
+	    # connections in opened in append mode)
+	    my $fhid = undef;
+	    # Sometimes we can cheat, as the force_close variable will have the
+	    # file_path in it thanks to the DESTROY block above. Doing a regex
+	    # on force_close will treat it like a string no matter what it was,
+	    # and we can search for the appropriate file extension that should
+	    # be there for valid paths.
+	    my $pattern = '\.' . $self->{'default_file_extension'} . '(\s\[APPEND\])?$';
+	    if ($force_close =~ /$pattern/) {
+		$fhid = $force_close;
+	    }
+	    # If we can't cheat then we are stuck finding which connection in
+	    # the handle_pool we are about to close. Need to compare objects
+	    # using refaddr()
+	    else {
+		foreach my $possible_fhid (keys %{$self->{'handle_pool'}}) {
+		    my $possible_handle = $self->{'handle_pool'}->{$possible_fhid};
+		    if (ref($handle) && ref($possible_handle) && refaddr($handle) == refaddr($possible_handle)) {
+			$fhid = $possible_fhid;
+			last;
+		    }
+		}
+	    }
+	    # If we found the fhid we can proceed to close the connection
+	    if (defined($fhid)) {
+		$self->debugPrint('Closing persistent connection: ' . $fhid);
+		delete($self->{'handle_pool'}->{$fhid});
+		$continue_close = 1;
+	    }
+	    else {
+		print STDERR "Warning! About to close persistent database handle, but couldn't locate in open handle pool.\n";
+	    }
+	}
+	# Persistent connection don't close *unless* force close is set
+	else {
+	    $continue_close = 0;
+	}
+    }
+    return $continue_close;
+}
+## removeConnectionIfPersistent(filehandle, string) => integer ##
+
+
+##
+#
+sub retrieveConnectionIfPersistent
+{
+    my $self = shift(@_);
+    my $path = shift(@_);
+    my $append = shift(@_); # -append support
+    my $conn; # This should be populated
+    if ($self->{'supports_persistentconnection'}) {
+	$self->debugPrintFunctionHeader($path, $append);
+	my $fhid = $path;
+	# special case: if the append mode has changed for a persistent
+	# connection, we need to close the old connection first or things
+	# will get wiggy.
+	if (defined $append && $append eq '-append') {
+	    # see if there is a non-append mode connection already open
+	    if (defined $self->{'handle_pool'}->{$path}) {
+		$self->debugPrint("Append mode added - closing existing non-append mode connection");
+		my $old_conn = $self->{'handle_pool'}->{$path};
+		$self->close_infodb_write_handle($old_conn, $path);
+	    }
+	    # Append -append so we know what happened.
+	    $fhid .= ' [APPEND]';
+	}
+	else {
+	    my $fhid_append = $path . ' [APPEND]';
+	    if (defined $self->{'handle_pool'}->{$fhid_append}) {
+		$self->debugPrint("Append mode removed - closing existing append mode connection");
+		my $old_conn = $self->{'handle_pool'}->{$fhid_append};
+		$self->close_infodb_write_handle($old_conn, $fhid_append);
+	    }
+	}
+	if (defined $self->{'handle_pool'}->{$fhid}) {
+	    $self->debugPrint('Retrieving existing connection: ' . $fhid);
+	    $conn = $self->{'handle_pool'}->{$fhid};
+	}
+    }
+    return $conn;
+}
+## ##
+
+
+
+
+
+
+
+###############################################################################
+## Public Functions
+###############################################################################
+
+
+## @function convert_infodb_hash_to_string(hashmap) => string
+#
+sub convert_infodb_hash_to_string
+{
+    my $self = shift(@_);
+    my $infodb_map = shift(@_);
+    my $infodb_entry_value = "";
+    foreach my $infodb_value_key (keys(%$infodb_map)) {
+        foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
+            $infodb_entry_value .= "<$infodb_value_key>" . $infodb_value . "\n";
+        }
+    }
+    return $infodb_entry_value;
+}
+## convert_infodb_hash_to_string(hashmap) => string ##
+
+
+## @function convert_infodb_string_to_hash(string) => hashmap
+#
+sub convert_infodb_string_to_hash
+{
+    my $self = shift(@_);
+    my $infodb_entry_value = shift(@_);
+    my $infodb_map = ();
+
+    if (!defined $infodb_entry_value) {
+	print STDERR "Warning: No value to convert into a infodb hashtable\n";
+    }
+    else {
+        while ($infodb_entry_value =~ /^<(.*?)>(.*)$/mg) {
+            my $infodb_value_key = $1;
+            my $infodb_value = $2;
+
+            if (!defined($infodb_map->{$infodb_value_key})) {
+                $infodb_map->{$infodb_value_key} = [ $infodb_value ];
+            }
+            else {
+                push(@{$infodb_map->{$infodb_value_key}}, $infodb_value);
+            }
+	}
+    }
+
+    return $infodb_map;
+}
+## convert_infodb_string_to_hash(string) => hashmap ##
+
+
+## @function get_infodb_file_path(string, string) => string
+#
+sub get_infodb_file_path
+{
+    my $self = shift(@_);
+    my $collection_name = shift(@_);
+    my $infodb_directory_path = shift(@_);
+    my $infodb_file_name = &util::get_dirsep_tail($collection_name) . '.' . $self->{'default_file_extension'};
+    my $infodb_file_path = &FileUtils::filenameConcatenate($infodb_directory_path, $infodb_file_name);
+    # Correct the path separators to work in Cygwin
+    if ($^O eq "cygwin") {
+	$infodb_file_path = `cygpath -w "$infodb_file_path"`;
+	chomp($infodb_file_path);
+	$infodb_file_path =~ s%\\%\\\\%g;
+    }
+    return $infodb_file_path;
+}
+## get_infodb_file_path(string, string) => string ##
+
+
+## @function supportsDatestamp(void) => integer
+#
+sub supportsDatestamp
+{
+    my $self = shift(@_);
+    return $self->{'supports_datestamp'};
+}
+## supportsDatestamp(void) => integer ##
+
+
+## @function supportsMerge(void) => boolean
+#
+sub supportsMerge
+{
+    my $self = shift(@_);
+    return $self->{'supports_merge'};
+}
+## supportsMerge(void) => integer ##
+
+
+## @function supportsPersistentConnection(void) => integer
+#
+sub supportsPersistentConnection
+{
+    my $self = shift(@_);
+    return $self->{'supports_persistentconnection'};
+}
+## supportsPersistentConnection(void) => integer ##
+
+
+## @function supportsRSS(void) => integer
+#
+sub supportsRSS
+{
+    my $self = shift(@_);
+    return $self->{'supports_rss'};
+}
+## supportsRSS(void) => integer ##
+
+
+## @function supportsSet(void) => integer
+#
+#  Not all drivers support the notion of set
+#
+sub supportsSet
+{
+    my $self = shift(@_);
+    return $self->{'supports_set'};
+}
+## supportsSet(void) => integer ##
+
+
+sub writeOnly
+{
+    my $self = shift(@_);
+    return $self->{'write_only'};
+}
+## writeOnly() ##
+
+###############################################################################
+## Virtual Functions
+###############################################################################
+
+
+## @function close_infodb_write_handle(*) => void
+#
+sub close_infodb_write_handle
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## close_infodb_write_handle(*) => void ##
+
+
+## @function delete_infodb_entry(*) => void
+#
+sub delete_infodb_entry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## delete_infodb_entry(*) => void ##
+
+
+## @function mergeDatabases(*) => void
+#
+sub mergeDatabases
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## mergeDatabases(*) => void ##
+
+
+## @function open_infodb_write_handle(*) => void
+#
+sub open_infodb_write_handle
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## open_infodb_write_handle(*) => void ##
+
+
+## @function set_infodb_entry(*) => void
+#
+sub set_infodb_entry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## set_infodb_entry(*) => void ##
+
+
+## @function read_infodb_entry(*) => void
+#
+sub read_infodb_entry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_entry(*) => void ##
+
+
+## @function read_infodb_rawentry(*) => string
+#
+sub read_infodb_rawentry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_rawentry(*) => string ##
+
+
+## @function read_infodb_file(*) => void
+#
+sub read_infodb_file
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_file(*) => void ##
+
+
+## @function read_infodb_keys(*) => void
+#
+sub read_infodb_keys
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_keys(*) => void ##
+
+
+## @function write_infodb_entry(*) => void
+#
+sub write_infodb_entry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## write_infodb_entry(*) => void ##
+
+
+## @function write_infodb_rawentry(*) => void
+#
+sub write_infodb_rawentry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## write_infodb_rawentry(*) => void ##
+
+
+## @function
+#
+sub mergeDatabases
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## mergeDatabase(string, string) => integer ##
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/GDBM.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/GDBM.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/GDBM.pm	(revision 30355)
@@ -0,0 +1,83 @@
+###############################################################################
+#
+# GDBM.pm -- utility functions for writing to gdbm databases
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::GDBM;
+
+# Pragma
+use strict;
+
+BEGIN
+{
+    if (!defined $ENV{'GSDLHOME'} || !defined $ENV{'GSDLOS'}) {
+        die("Error! Environment not prepared. Have you sourced setup.bash?\n");
+    }
+}
+
+# Libraries
+use util;
+use FileUtils;
+use parent 'DBDrivers::70HyphenFormat';
+
+
+## @function constructor
+#
+sub new
+{
+    my $class = shift(@_);
+    my $self = DBDrivers::70HyphenFormat->new(@_);
+    $self->{'default_file_extension'} = 'gdb';
+    # note: file separator agnostic
+    $self->{'executable_path'} = $ENV{'GSDLHOME'} . '/bin/' . $ENV{'GSDLOS'};
+    $self->{'read_executable'} = 'db2txt';
+    $self->{'keyread_executable'} = 'gdbmkeys';
+    $self->{'write_executable'} = 'txt2db';
+    # Optional Support
+    $self->{'supports_set'} = 1;
+    bless($self, $class);
+    return $self;
+}
+## new(void) => GDBM ##
+
+
+# -----------------------------------------------------------------------------
+#   GDBM IMPLEMENTATION
+# -----------------------------------------------------------------------------
+
+# Handled by BaseDBDriver
+# sub get_infodb_file_path(string, string) => string
+
+# Handled by 70HyphenFormat
+# sub open_infodb_write_handle(string, string?) => filehandle
+# sub close_infodb_write_handle(filehandle) => void
+# sub delete_infodb_entry(filehandle, string) => void
+# sub read_infodb_entry(string, string) => hashmap
+# sub read_infodb_file(string, hashmap) => void
+# sub read_infodb_keys(string, hashmap) => void
+# sub read_infodb_rawentry(string, string) => string
+# sub set_infodb_entry(string, string, hashmap) => integer
+# sub write_infodb_entry(filehandle, string, hashmap) => void
+# sub write_infodb_rawentry(filehandle, string, string) => void
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/GDBMTXTGZ.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/GDBMTXTGZ.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/GDBMTXTGZ.pm	(revision 30355)
@@ -0,0 +1,110 @@
+###############################################################################
+#
+# GDBMTXTGZ.pm -- utility functions for writing to gdbm-txtgz databases
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (c) 2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::GDBMTXTGZ;
+
+# Pragma
+use strict;
+
+# Libraries
+use util;
+use FileUtils;
+# - OO inheritence
+use parent 'DBDrivers::70HyphenFormat';
+
+
+sub new
+{
+    my $class = shift(@_);
+    my $self = DBDrivers::70HyphenFormat->new(@_);
+    # Default TDB file extension
+    $self->{'default_file_extension'} = 'txt.gz';
+    # note: file separator agnostic
+    $self->{'executable_path'} = $ENV{'GSDLHOME'} . '/bin/' . $ENV{'GSDLOS'};
+    $self->{'read_executable'} = 'gzip --decompress --to-stdout';
+    $self->{'keyread_executable'} = $self->{'read_executable'};
+    $self->{'write_executable'} = 'gzip -';
+    bless ($self, $class);
+    return $self;
+}
+
+# -----------------------------------------------------------------------------
+#   GDBM TXT-GZ IMPLEMENTATION
+# -----------------------------------------------------------------------------
+
+# Handled by BaseDBDriver
+# sub get_infodb_file_path(string, string)
+
+# Handled by 70HyphenFormat
+# sub close_infodb_write_handle(filehandle) => void
+# sub read_infodb_file(string, hashmap) => void
+# sub read_infodb_keys(string, hashmap) => void
+# sub write_infodb_entry(filehandle, string, hashmap) => void
+# sub write_infodb_rawentry(filehandle, string, string) => void
+
+
+## @function open_infodb_write_handle(string)
+#
+# Keep infodb in GDBM neutral form => save data as compressed text file, read
+# for txt2db to be run on it later (i.e. by the runtime system, first time the
+# collection is ever accessed).  This makes it easier distribute pre-built
+# collections to various architectures.
+#
+# NB: even if two architectures are little endian (e.g. Intel and ARM procesors)
+# GDBM does *not* guarantee that the database generated on one will work on the
+# other
+#
+# Now only responsible for transforming the optional append argument into the
+# correct redirection operand (either > for clobber or >> for append)
+#
+sub open_infodb_write_handle
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $opt_append = shift(@_);
+    my $infodb_file_handle;
+    # append
+    if (defined $opt_append && $opt_append =~ /^-?append$/) {
+	$infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>>');
+    }
+    # create or clobber
+    else {
+	$infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, '>');
+    }
+    return $infodb_file_handle;
+}
+## open_infodb_write_handle(string) => filehandle ##
+
+## @function set_infodb_entry(string, string, hashmap)
+#
+sub set_infodb_entry
+{
+    my $self = shift(@_);
+    print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n";
+}
+## set_infodb_entry(string, string, hashmap) => void ##
+
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/JDBM.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/JDBM.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/JDBM.pm	(revision 30355)
@@ -0,0 +1,100 @@
+###############################################################################
+#
+# DBDrivers/JDBM.pm -- utility functions for writing to jdbm databases
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::JDBM;
+
+# Pragma
+use strict;
+
+# Libraries
+use util;
+use FileUtils;
+# - OO inheritence
+use parent 'DBDrivers::70HyphenFormat';
+
+sub BEGIN
+{
+    if (!defined $ENV{'GSDLHOME'} || !defined $ENV{'GSDLOS'}) {
+        die("Error! Environment must be prepared by sourcing setup.bash\n");
+    }
+}
+
+
+## @function constructor
+#
+sub new
+{
+    my $class = shift(@_);
+    my $self = DBDrivers::70HyphenFormat->new(@_);
+    $self->{'default_file_extension'} = 'jdb';
+
+    # Executables need a little extra work since we are using Java
+    # - we need to build up the classpath continue the Jar libraries to use
+    my $jdbmwrap_jar = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, 'bin', 'java', 'JDBMWrapper.jar');
+    my $jdbm_jar = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, 'lib', 'java', 'jdbm.jar');
+    my $classpath = &util::pathname_cat($jdbmwrap_jar,$jdbm_jar);
+    # Massage paths for Cygwin. Away to run a java program, using a binary that
+    # is native to Windows, so need Windows directory and path separators
+    if ($^O eq "cygwin") {
+	$classpath = `cygpath -wp "$classpath"`;
+	chomp($classpath);
+	$classpath =~ s%\\%\\\\%g;
+    }
+    $self->{'executable_path'} = '';
+    $self->{'read_executable'} = 'java -cp "' . $classpath . '" Jdb2Txt';
+    $self->{'keyread_executable'} = 'java -cp "' . $classpath . '" JdbKeys';
+    $self->{'write_executable'} = 'java -cp "' . $classpath . '" Txt2Jdb';
+    # Support
+    $self->{'supports_set'} = 1;
+
+    bless($self, $class);
+    return $self;
+}
+## constructor() ##
+
+
+# -----------------------------------------------------------------------------
+#   JDBM IMPLEMENTATION
+# -----------------------------------------------------------------------------
+
+# When DBUtil::* is properly structured with inheritence, then
+# much of this code (along with GDBM and GDBM-TXT-GZ) can be grouped into
+# a shared base class.  Really it is only the the command that needs to
+# be constructed that changes between much of the code that is used
+
+# Handled by BaseDBDriver
+# sub get_infodb_file_path {}
+
+# Handles by 70HyphenFormat
+# sub open_infodb_write_handle(string, string?) => filehandle
+# sub close_infodb_write_handle(filehandle) => void
+# sub read_infodb_file(string, hashmap) => void
+# sub read_infodb_keys(string, hashmap) => void
+# sub write_infodb_entry(filehandle, string, hashmap) => void
+# sub write_infodb_rawentry(filehandle, string, string) => void
+# sub set_infodb_entry(filehandle, string, string) => void
+# sub delete_infodb_entry(filehandle, string) => void
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/MSSQL.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/MSSQL.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/MSSQL.pm	(revision 30355)
@@ -0,0 +1,325 @@
+###############################################################################
+#
+# DBDrivers/MSSQL.pm -- utility functions for writing to mssql databases
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::MSSQL;
+
+# Pragma
+use strict;
+
+# Libraries
+use Encode;
+use DBDrivers::BaseDBDriver;
+
+sub BEGIN
+{
+    @DBDrivers::MSSQL::ISA = ( 'DBDrivers::BaseDBDriver' );
+}
+
+sub new
+{
+    my $class = shift(@_);
+    if ($^O !~ /cygwin|MSWin32/) {
+        print STDERR "Warning! Non-Windows operating system detected... good luck getting this to work.\n";
+    }
+    return bless ($self, $class);
+}
+
+# -----------------------------------------------------------------------------
+#   MSSQL IMPLEMENTATION
+# -----------------------------------------------------------------------------
+
+# The hard coded server connection thingy which should be place in some
+# configuration file.
+# If you have problem connecting to your MS SQL server:
+# 1. Check if your MSSQL server has been started.
+# 2. Check if the TCP/IP connection has been enabled.
+# 3. Use telnet to the server
+# (don't forget to specify the port, which can be found in the configuration manager)
+# If none of the above helped, the you need to start googling then.
+my $host = "localhost,1660"; # Need to look up your SQL server and see what port is it using.
+my $user = "sa"; # Generally "sa" for default admin, but YMMV
+my $pwd = "[When installing the MSSQL, you will be asked to input a password for the sa user, use that password]";
+my $database = "[Create a database in MSSQL and use it here]";
+
+my $mssql_collection_name = "";
+my $mssql_data_table_name = "";
+my $mssql_document_metadata_table_name = "";
+
+
+sub open_infodb_write_handle
+{
+  my $infodb_file_path = shift(@_);
+
+  # You might have to install the DBD::ADO module from CPAN
+  use DBI;
+  use DBD::ADO;
+  Win32::OLE->Option(CP => Win32::OLE::CP_UTF8);
+
+  # Create the unique name for the table
+  # We do not want to change the database for the current running index
+  # Therefore we use timestamp and collection short name to create an unqiue name
+  my $cur_time = time();
+  my $unique_key = $mssql_collection_name . "_" . $cur_time;
+  $mssql_data_table_name = "data_" . $unique_key;
+  $mssql_document_metadata_table_name = "document_metadata_" . $unique_key;
+  print STDERR "MSSQL: Creating unique table name. Unique ID:[" . $unique_key . "]\n";
+      
+  # Store these information into the infodbfile  
+  open(FH, ">" . $infodb_file_path);
+  print FH "mss-host\t" . $host . "\n";
+  print FH "username\t" . $user . "\n";
+  print FH "password\t" . $pwd . "\n";
+  print FH "database\t" . $database . "\n";
+  print FH "tableid\t" . $unique_key . "\n";
+  close(FH);
+  print STDERR "MSSQL: Saving db info into :[" . $infodb_file_path . "]\n";
+
+  # Make the connection
+  my $dsn = "Provider=SQLNCLI;Server=$host;Database=$database";
+  my $infodb_handle = DBI->connect("dbi:ADO:$dsn", $user, $pwd, { RaiseError => 1, AutoCommit => 1}) || return undef;
+  print STDERR "MSSQL: Connect to MS SQL database. DSN:[" . $dsn . "]\n";
+
+  # Make sure the data table has been created.
+  my $data_table_checker_array = dbgetarray($infodb_handle, "SELECT name FROM sysobjects WHERE name = '" . $mssql_data_table_name . "' AND OBJECTPROPERTY(id,'IsUserTable') = 1");
+  if (scalar(@{$data_table_checker_array}) == 0)
+  {
+    dbquery($infodb_handle, "CREATE TABLE " . $mssql_data_table_name . " (one_key NVARCHAR(50) UNIQUE, one_value NVARCHAR(MAX))");
+  }
+  print STDERR "MSSQL: Making sure the data table(" . $mssql_data_table_name . ") exists\n";
+    
+  # Make sure the document_metadata table has been created.
+  my $document_metadata_table_checker_array = dbgetarray($infodb_handle, "SELECT name FROM sysobjects WHERE name = '" . $mssql_document_metadata_table_name . "' AND OBJECTPROPERTY(id,'IsUserTable') = 1");
+  if (scalar(@{$document_metadata_table_checker_array}) == 0)
+  {
+    dbquery($infodb_handle, "CREATE TABLE " . $mssql_document_metadata_table_name . " (id INTEGER IDENTITY(1,1) PRIMARY KEY, docOID NVARCHAR(50), element NVARCHAR(MAX), value NVARCHAR(MAX))");
+    dbquery($infodb_handle, "CREATE INDEX dmd ON " . $mssql_document_metadata_table_name . "(docOID)");
+  } 
+  print STDERR "MSSQL: Making sure the document_metadata table(" . $mssql_data_table_name . ") exists.\n";
+  
+  return $infodb_handle;
+}
+
+
+sub close_infodb_write_handle
+{
+  my $infodb_handle = shift(@_);    
+  
+  $infodb_handle->disconnect();
+}
+
+
+sub get_infodb_file_path
+{
+  my $collection_name = shift(@_);
+  my $infodb_directory_path = shift(@_);
+
+  my $infodb_file_extension = ".mssqldbinfo";
+  my $infodb_file_name = &util::get_dirsep_tail($collection_name) . $infodb_file_extension;
+  
+  # This will be used in the open_infodb_write_handle function
+  $mssql_collection_name =  $collection_name;
+
+  return &util::filename_cat($infodb_directory_path, $infodb_file_name);
+}
+
+
+sub read_infodb_file
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_map = shift(@_);
+
+  print STDERR "******* mssql::read_infodb_file() TO BE IMPLEMENTED!\n";
+  print STDERR "******* See sqlite.pm for comparable implementation that has been coded up!\n";
+}
+
+sub read_infodb_keys
+{
+  my $infodb_file_path = shift(@_);
+  my $infodb_map = shift(@_);
+
+  print STDERR "******* mssql::read_infodb_keys() TO BE IMPLEMENTED!\n";
+  print STDERR "******* See sqlite.pm for comparable implementation that has been coded up!\n";
+}
+
+
+sub write_infodb_entry
+{
+  my $infodb_handle = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_map = shift(@_);
+  
+  # Add the key -> value mapping into the "data" table
+  my $infodb_entry_value = "";
+  foreach my $infodb_value_key (keys(%$infodb_map))
+  {
+    foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}})
+    {
+      $infodb_entry_value .= "<$infodb_value_key>" . &Encode::decode_utf8($infodb_value) . "\n";
+    }
+  }
+  
+  # Prepare the query
+  my $safe_infodb_key = &mssql_safe($infodb_key);
+  my $query = "INSERT INTO " . $mssql_data_table_name . " (one_key, one_value) VALUES (N'" . $safe_infodb_key . "', N'" . &mssql_safe($infodb_entry_value) . "')";
+  dbquery($infodb_handle, $query);
+  
+  # If this infodb entry is for a document, add all the interesting document metadata to the
+  # "document_metadata" table (for use by the dynamic classifiers)
+  if ($infodb_key !~ /\./ && $infodb_entry_value =~ /\<doctype\>doc\n/)
+  {
+    dbquery($infodb_handle, "DELETE FROM " . $mssql_document_metadata_table_name . " WHERE docOID=N'" . $safe_infodb_key . "'");
+    
+    foreach my $infodb_value_key (keys(%$infodb_map))
+    {            
+      # We're not interested in most of the automatically added document metadata
+      next if ($infodb_value_key eq "archivedir" ||
+               $infodb_value_key eq "assocfilepath" ||
+               $infodb_value_key eq "childtype" ||
+               $infodb_value_key eq "contains" ||
+               $infodb_value_key eq "docnum" ||
+               $infodb_value_key eq "doctype" ||
+               $infodb_value_key eq "Encoding" ||
+               $infodb_value_key eq "FileSize" ||
+               $infodb_value_key eq "hascover" ||
+               $infodb_value_key eq "hastxt" ||
+               $infodb_value_key eq "lastmodified" ||
+               $infodb_value_key eq "metadataset" ||
+               $infodb_value_key eq "thistype" ||
+               $infodb_value_key =~ /^metadatafreq\-/ ||
+               $infodb_value_key =~ /^metadatalist\-/);
+      foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}})
+      {
+        $infodb_handle->{LongReadLen} = 65535; # Added for the encoding issue
+        my $query = "INSERT INTO " . $mssql_document_metadata_table_name . " (docOID, element, value) VALUES (N'" . $safe_infodb_key . "', N'" . &mssql_safe(&Encode::decode_utf8($infodb_value_key)) . "', N'" . &mssql_safe(&Encode::decode_utf8($infodb_value)) . "')";
+        dbquery($infodb_handle, $query);
+      }
+    }
+  }
+}
+
+
+sub write_infodb_rawentry
+{
+  my $infodb_handle = shift(@_);
+  my $infodb_key = shift(@_);
+  my $infodb_val = shift(@_);
+  
+  # Prepare the query
+  my $safe_infodb_key = &mssql_safe($infodb_key);
+  my $query = "INSERT INTO " . $mssql_data_table_name . " (one_key, one_value) VALUES (N'" . $safe_infodb_key . "', N'" . &mssql_safe($infodb_val) . "')";
+  dbquery($infodb_handle, $query);
+}
+
+
+ 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
+{
+  my $infodb_handle = shift(@_);
+  my $infodb_key = shift(@_);
+  
+  # Delete the key from the "data" table
+
+  
+  # Prepare the query
+  my $safe_infodb_key = &mssql_safe($infodb_key);
+  my $query = "DELETE FROM " . $mssql_data_table_name . " WHERE one_key=N'" . $safe_infodb_key . "'";
+  dbquery($infodb_handle, $query);
+  
+  # If this infodb entry is for a document, add all the interesting document metadata to the
+  # "document_metadata" table (for use by the dynamic classifiers)
+  if ($infodb_key !~ /\./)
+  {
+      # Possible for there not to be a docOID matching this infodb_key
+      # (entries are only made when <doctype> == doc
+      # Attempt to delete it, and don't complain if one isn't found
+
+      dbquery($infodb_handle, "DELETE FROM " . $mssql_document_metadata_table_name . " WHERE docOID=N'" . $safe_infodb_key . "'");
+      
+  }
+}
+
+
+
+sub mssql_safe
+{
+  my $value = shift(@_);
+  
+  # Escape any single quotes in the value
+  $value =~ s/\'/\'\'/g;
+  
+  return $value;
+}
+
+
+sub dbquery
+{
+  my $infodb_handle = shift(@_);
+  my $sql_query = shift(@_);
+
+  # Execute the SQL statement
+  my $statement_handle = $infodb_handle->prepare($sql_query);
+  $statement_handle->execute();
+  if ($statement_handle->err) 
+  {
+    print STDERR "Error:" . $statement_handle->errstr . "\n";
+    return undef;
+  }
+  
+  return $statement_handle;
+}
+
+
+sub dbgetarray
+{
+  my $infodb_handle = shift(@_);
+  my $sql_query = shift(@_);
+  
+  my $statement_handle = dbquery($infodb_handle, $sql_query);
+  my $return_array = [];
+  
+  # Iterate through the results and push them into an array
+  if (!defined($statement_handle)) 
+  {
+    return [];
+  }
+  
+  while ((my $temp_hash = $statement_handle->fetchrow_hashref()))
+  {
+    push(@$return_array, $temp_hash);
+  }
+
+  return $return_array; 
+}
+
+
+1;
Index: /main/trunk/greenstone2/perllib/DBDrivers/Readme.txt
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/Readme.txt	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/Readme.txt	(revision 30355)
@@ -0,0 +1,37 @@
+===== DBDriver =====
+
+Note that there are a couple of Drivers that could be further separated to
+have even better OO, but I started to get bogged down in multiple inheritence
+problems so I left them as is for now. For instance, separating PipedExecutable
+support from the 70HyphenFormat driver would increase flexibility, but then it
+becomes tricky to say which should inherit from which (in a single inheritence)
+or what order methods should be resolved (in multiple inheritence).
+
+Notes:
+* Didn't finish refactoring SQL based drivers
+* ServerDrivers refactoring not done.
+* Since TDBCluster was the only cluster, didn't do MergableDriver
+
+==== Inheritence Overview ====
+
+  * BaseDBDriver - superclass of all drivers. Some shared utility methods
+                   including support for persistent connections (ala TDB).
+		   Thus this is a candidate for separating out the the
+		   PersistentConnectionsDriver.
+    * 70HyphenFormat - drivers that write and read their data via pipes to
+                       external executables. Data is in simple Greenstone
+		       archive form (i.e. key/value pairs and separated by
+		       seventy hyphens) - this is a candidate for further
+		       separating out a PipedExecutableDriver.
+      * GDBM - makes use of GDBM utils (txt2db, db2txt etc)
+      * GDBMTXTGZ - makes use of gzip (for later use with GDBM)
+      * JDBM - makes use of jdbm.jar and JDBMWrapper.jar
+      * TDB - makes use of TDB utils (txt2tdb, tdb2txt etc)
+    * SQLDrivers - drivers that read/write their data using SQL commands
+      * SQLITE - uses calls to SQLite3 via the command line
+      * MSSQL
+    * ServerDrivers - drivers that act as clients to externally running servers
+      * GDBMS - makes use of a custom GDBM server
+      * TDBS - makes use of a custom TDB server
+    * MergableDrivers - ???
+      * TDBC - ??? Knows how to merge several TDB files into one.
Index: /main/trunk/greenstone2/perllib/DBDrivers/SQLITE.pm
===================================================================
--- /main/trunk/greenstone2/perllib/DBDrivers/SQLITE.pm	(revision 30355)
+++ /main/trunk/greenstone2/perllib/DBDrivers/SQLITE.pm	(revision 30355)
@@ -0,0 +1,428 @@
+###############################################################################
+#
+# DBDrivers/SQLITE.pm -- utility functions for writing to sqlite databases
+#
+# A component of the Greenstone digital library software from the New Zealand
+# Digital Library Project at the University of Waikato, New Zealand.
+#
+# Copyright (C) 2009-2010 DL Consulting Ltd.
+# Copyright (C) 2009-2015 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
+# Ave, Cambridge, MA 02139, USA.
+#
+###############################################################################
+
+package DBDrivers::SQLITE;
+
+# Pragma
+use strict;
+
+# Libraries
+use util;
+use parent 'DBDrivers::BaseDBDriver';
+
+sub BEGIN
+{
+    if (!defined $ENV{'GSDLHOME'} || !defined $ENV{'GSDLOS'}) {
+        die("Error! Environment must be prepared by sourcing setup.bash\n");
+    }
+    @DBDrivers::SQLITE::ISA = ( 'DBDrivers::BaseDBDriver' );
+}
+
+sub new
+{
+    my $class = shift(@_);
+    my $self = DBDrivers::BaseDBDriver->new(@_);
+    $self->{'default_file_extension'} = 'db';
+    # Please set db_fast to 1 if you wish to enable faster I/O to the database
+    # by using optimisations such as PRAGMA journal_mode (MEMORY instead of
+    # DELETE) and synchronous (OFF instead of FULL)
+    # Please be aware that in this case it will be less secure and the database
+    # file may become corrupted if the if the operating system crashes or the
+    # computer loses power before that data has been written to the disk. But
+    # the speed gain is about 50x.
+    $self->{'db_fast'} = 0;
+    # Set to 1 to enable Write Ahead Logging - which is supposed to allow
+    # multiple readers/writers on a SQLite database (incompatible with
+    # db_fast). From SQLite 3.7 onwards, WAL offers limited parallel reader/
+    # writer support but is limited to single computers (doesn't work over
+    # networked filesystems). For details see:
+    # http://www.sqlite.org/draft/wal.html
+    $self->{'db_wal'} = 0;
+    # Sanity checking
+    if ($self->{'db_fast'} && $self->{'db_wal'}) {
+	print "Warning! Write-Ahead Logging is incompatible with certain SQLite optimizations; db_fast flag will be ignored.\n";
+    }
+    # The SQLite path we are using
+    $self->{'sqlite_executable'} = '';
+
+    # Support
+    $self->{'supports_set'} = 1;
+
+    bless($self, $class);
+    return $self;
+}
+
+# -----------------------------------------------------------------------------
+#   SQLITE IMPLEMENTATION
+# -----------------------------------------------------------------------------
+
+## Protected
+
+## @function _getExecutable
+#
+sub _getExecutable
+{
+    my $self = shift(@_);
+    my $sqlite3_exe = $self->{'sqlite_executable'};
+    if ($sqlite3_exe eq '') {
+	# Try a full path first - SQLite3 may live in the Greenstone bin
+	# directory
+	$sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'}, 'bin', $ENV{'GSDLOS'}, 'sqlite3' . &util::get_os_exe());
+	if (!-e "$sqlite3_exe") {
+	    print "Warning! Didn't find SQLite3 on expected path, \"$sqlite3_exe\", let's hope its on the system path.\n";
+	    $sqlite3_exe = 'sqlite3' . &util::get_os_exe();
+	}
+	$self->{'sqlite_executable'} = $sqlite3_exe;
+    }
+    return $sqlite3_exe;
+}
+## _getExecutable() => string ##
+
+
+## @function _readInfoDBCmd(string, string) => string
+#
+sub _readInfoDBCmd
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $sqlcmd = shift(@_);
+    my $result = "";
+    $self->debugPrint('("' . $infodb_file_path . '", "' . $sqlcmd . '")');
+    my $sqlite3_exe = $self->_getExecutable();
+    my $infodb_handle = undef;
+    my $cmd = "\"$sqlite3_exe\" \"$infodb_file_path\" \"$sqlcmd\"";
+    if (!open($infodb_handle, "$cmd |")) {
+	print STDERR "Unable to execute: $cmd\n";
+	print STDERR "$!\n";
+    }
+    else {
+	binmode($infodb_handle, ":utf8");
+	my $line;
+	while (defined($line=<$infodb_handle>)) {
+	    $result .= $line;
+	}
+	close($infodb_handle);
+    }
+    return $result;
+}
+## _readInfoDBCmd(string, string) => string ##
+
+
+## @function _sqliteSafe(string) => string
+#
+sub _sqliteSafe
+{
+    my $self = shift(@_);
+    my $value = shift(@_);
+    # Escape any single quotes in the value
+    $value =~ s/\'/\'\'/g;
+    return $value;
+}
+## _sqliteSafe(string) => string ##
+
+
+## Public
+
+
+# Handled by BaseDBDriver
+# sub get_infodb_file_path {}
+
+
+## @function open_infodb_write_handle(string, string) => handle
+#
+sub open_infodb_write_handle
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $opt_append = shift(@_);
+
+    if (!defined $opt_append) {
+	$opt_append = '';
+    }
+
+    $self->debugPrint('("' . $infodb_file_path . '","' . $opt_append . '")');
+
+    my $sqlite3_exe = $self->_getExecutable();
+    my $infodb_handle = undef;
+
+    # running sqlite3 with the pragma journal_mode=memory, causes sqlite to
+    # print out the word "memory". While this is not a problem usually, in our
+    # case, this ends up going out to the web page first, as part of the web
+    # page's headers, thus ruining the web page which causes an Internal
+    # Server Error (500). Therefore, we redirect sqlite's output to the null
+    # device instead. WAL mode (which also changes the journal) suffers a
+    # similar issue.
+    my $nul_device="";
+    if($self->{'db_fast'} == 1 || $self->{'db_wal'} == 1) {
+        if($ENV{'GSDLOS'} =~ m/windows/) {
+            $nul_device=">NUL";
+	} else {
+            $nul_device=">/dev/null"; # linux, mac
+	}
+    }
+
+    if(!open($infodb_handle, "| \"$sqlite3_exe\" \"$infodb_file_path\"$nul_device"))
+    {
+	print STDERR "Error! Failed to open pipe to \"" . $sqlite3_exe . "\" \"" . $infodb_file_path . "\"\n" . $! . "\n";
+	return undef;
+    }
+
+    binmode($infodb_handle,":utf8");
+
+    # Allow parallel readers/writers by using a Write Ahead Logger
+    if ($self->{'db_wal'}) {
+	print $infodb_handle "PRAGMA journal_mode=WAL;\n";
+    }
+    # Add extra optimisations, less secure but with a massive gain in performan-
+    # ce with large databases which are often updated. They should be set before
+    # the transaction begins. Incompatible with WAL.
+    elsif ($self->{'db_fast'}) {
+	print $infodb_handle "PRAGMA synchronous=OFF;\n";
+	print $infodb_handle "PRAGMA journal_mode=MEMORY;\n";
+    }
+    # If we are *not* appending, drop the table for a fresh start
+    if ($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";
+    # These are crucial for efficiency when importing large amounts of data
+    print $infodb_handle "CREATE INDEX IF NOT EXISTS dmd ON document_metadata(docOID);\n";
+    print $infodb_handle "CREATE INDEX IF NOT EXISTS dme ON document_metadata(element);\n";
+    # This is very important for efficiency, otherwise each command will be act-
+    # ioned one at a time
+    print $infodb_handle "BEGIN TRANSACTION;\n";
+    return $infodb_handle;
+}
+## open_infodb_write_handle(string, string) => handle ##
+
+
+## @function close_infodb_write_handle(handle) => void
+#
+sub close_infodb_write_handle
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    $self->debugPrint('(<handle>)');
+    # Close the transaction we began when opening the file
+    print $infodb_handle "END TRANSACTION;\n";
+    close($infodb_handle);
+}
+## close_infodb_write_handle(handle) => void ##
+
+
+## @function read_infodb_file(string, hashmap) => void
+#
+sub read_infodb_file
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_map = shift(@_);
+    $self->debugPrint('("' . $infodb_file_path . '", <hashmap>)');
+    my $keys_str = $self->_readInfoDBCmd($infodb_file_path,"SELECT key FROM data ORDER BY key;");
+    my @keys = split(/\n/,$keys_str);
+    foreach my $k (@keys) {
+	my $k_safe = $self->_sqliteSafe($k);
+	my $select_val_cmd = "SELECT value FROM data WHERE key='$k_safe';";
+	my $val_str = $self->_readInfoDBCmd($infodb_file_path,$select_val_cmd);
+	$infodb_map->{$k} = $val_str;
+    }
+}
+## read_infodb_file(string, hashmap) => void ##
+
+
+## @function read_infodb_keys(string, hashmap) => void
+#
+sub read_infodb_keys
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_map = shift(@_);
+    $self->debugPrint('("' . $infodb_file_path . '", <hashmap>)');
+    my $keys_str = $self->_readInfoDBCmd($infodb_file_path,"SELECT key FROM data;");
+    my @keys = split(/\n/,$keys_str);
+    foreach my $key (@keys)
+    {
+	$infodb_map->{$key} = 1;
+    }
+}
+## read_infodb_keys(string, hashmap) => void ##
+
+
+## @function read_infodb_rawentry(string, string) => string
+#
+sub read_infodb_rawentry
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    $self->debugPrint('("' . $infodb_file_path . '", "' . $infodb_key . '")');
+    my $key_safe = $self->_sqliteSafe($infodb_key);
+    my $select_val_cmd = "SELECT value FROM data WHERE key='$key_safe';";
+    my $val_str = $self->_readInfoDBCmd($infodb_file_path,$select_val_cmd);
+    return $val_str
+}
+## read_infodb_rawentry(string, string) => string ##
+
+
+## @function read_infodb_entry(string, string) => hashmap
+#
+sub read_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    $self->debugPrint('("' . $infodb_file_path . '", "' . $infodb_key . '")');
+    my $val_str = $self->read_infodb_rawentry($infodb_file_path,$infodb_key);
+    my $rec_hash = $self->convert_infodb_string_to_hash($val_str);
+    return $rec_hash;
+}
+## read_infodb_entry(string, string) => hashmap ##
+
+
+## @function write_infodb_entry(handle, string, hashmap) => void
+#
+sub write_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+    $self->debugPrint('(<handle>, "' . $infodb_key . '", <hashmap>)');
+    # Add the key -> value mapping into the "data" table
+    my $infodb_entry_value = "";
+    foreach my $infodb_value_key (keys(%$infodb_map)) {
+	foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
+	    $infodb_entry_value .= "<$infodb_value_key>" . $infodb_value . "\n";
+	}
+    }
+
+    my $safe_infodb_key = $self->_sqliteSafe($infodb_key);
+    print $infodb_handle "INSERT OR REPLACE INTO data (key, value) VALUES ('" . $safe_infodb_key . "', '" . $self->_sqliteSafe($infodb_entry_value) . "');\n";
+
+    # If this infodb entry is for a document, add all the interesting document
+    # metadata to the "document_metadata" table (for use by the dynamic
+    # classifiers)
+    if ($infodb_key !~ /\./ && $infodb_entry_value =~ /\<doctype\>doc\n/) {
+	print $infodb_handle "DELETE FROM document_metadata WHERE docOID='" . $safe_infodb_key . "';\n";
+	foreach my $infodb_value_key (keys(%$infodb_map)) {
+	    # We're not interested in most of the automatically added document metadata
+	    next if ($infodb_value_key eq "archivedir" ||
+		     $infodb_value_key eq "assocfilepath" ||
+		     $infodb_value_key eq "childtype" ||
+		     $infodb_value_key eq "contains" ||
+		     $infodb_value_key eq "docnum" ||
+		     $infodb_value_key eq "doctype" ||
+		     $infodb_value_key eq "Encoding" ||
+		     $infodb_value_key eq "FileSize" ||
+		     $infodb_value_key eq "hascover" ||
+		     $infodb_value_key eq "hastxt" ||
+		     $infodb_value_key eq "lastmodified" ||
+		     $infodb_value_key eq "metadataset" ||
+		     $infodb_value_key eq "thistype" ||
+		     $infodb_value_key =~ /^metadatafreq\-/ ||
+		     $infodb_value_key =~ /^metadatalist\-/);
+	    foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
+		print $infodb_handle "INSERT INTO document_metadata (docOID, element, value) VALUES ('" . $safe_infodb_key . "', '" . $self->_sqliteSafe($infodb_value_key) . "', '" . $self->_sqliteSafe($infodb_value) . "');\n";
+	    }
+	}
+    }
+
+    #### DEBUGGING
+    #my $new_file = "D:\\sql.txt";
+    #open(FOUT, ">>$new_file") or die "Unable to open $new_file for writing out sql statements...ERROR: $!\n";
+    #print FOUT "BEGIN;\n".$insertStatementsBuffer."\nEND;\n";
+    #close(FOUT);
+    #print STDERR $insertStatementsBuffer;
+    #### END DEBUGGING
+}
+## write_infodb_entry(handle, string, hashmap) => void ##
+
+
+## @function write_infodb_rawentry(handle, string, string) => void
+#
+sub write_infodb_rawentry
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_val = shift(@_);
+    $self->debugPrint('(<handle>, "' . $infodb_key . '", "' . $infodb_val . '")');
+    my $safe_infodb_key = $self->_sqliteSafe($infodb_key);
+    print $infodb_handle "INSERT OR REPLACE INTO data (key, value) VALUES ('" . $safe_infodb_key . "', '" . $self->_sqliteSafe($infodb_val) . "');\n";
+}
+## write_infodb_rawentry(handle, string, string) => void ##
+
+
+## @function set_infodb_entry(string, string, hashmap) => integer
+#
+sub set_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_file_path = shift(@_);
+    my $infodb_key = shift(@_);
+    my $infodb_map = shift(@_);
+    $self->debugPrint('("' . $infodb_file_path . '", "' . $infodb_key . '", <hashmap>)');
+    my $infodb_handle = $self->open_infodb_write_handle($infodb_file_path, "append");
+    if (!defined $infodb_handle) {
+	print STDERR "Error: Failed to open infodb write handle\n";
+	return -1;
+    }
+    else {
+	$self->write_infodb_entry($infodb_handle,$infodb_key,$infodb_map);
+	$self->close_infodb_write_handle($infodb_handle);
+    }
+    # Not currently checking for errors on write to DB
+    return 0;
+}
+## set_infodb_entry(string, string, hashmap) => integer ##
+
+
+## @function delete_infodb_entry(handle, string) => void
+#
+sub delete_infodb_entry
+{
+    my $self = shift(@_);
+    my $infodb_handle = shift(@_);
+    my $infodb_key = shift(@_);
+    $self->debugPrint('(<handle>, "' . $infodb_key . '")');
+    # Delete the key from the "data" table
+    my $safe_infodb_key = $self->_sqliteSafe($infodb_key);
+    print $infodb_handle "DELETE FROM data WHERE key='" . $safe_infodb_key . "';\n";
+    # If this infodb entry is for a document, delete the "document_metadata"
+    # table entry also (for use by the dynamic classifiers)
+    if ($infodb_key !~ /\./) {
+	# Possible for there not to be a docOID matching this infodb_key
+	# (entries are only made when <doctype> == doc
+	# Attempt to delete it, and don't complain if one isn't found
+	print $infodb_handle "DELETE FROM document_metadata WHERE docOID='" . $safe_infodb_key . "';\n";
+    }
+}
+## delete_infodb_entry(handle, string) => void ##
+
+
+1;
