Index: /main/trunk/greenstone2/runtime-src/src/colservr/Makefile.in
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/Makefile.in	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/Makefile.in	(revision 22050)
@@ -158,5 +158,7 @@
 	search.cpp \
 	source.cpp \
-	sqlbrowsefilter.cpp
+	sqlbrowsefilter.cpp \
+	sqlqueryfilter.cpp \
+	sqlfilter.cpp
 
 OBJECTS = \
@@ -179,5 +181,7 @@
 	search.o \
 	source.o \
-	sqlbrowsefilter.o
+	sqlbrowsefilter.o \
+	sqlqueryfilter.o \
+	sqlfilter.o
 
 LIBRARY = gsdlcolservr.a
Index: /main/trunk/greenstone2/runtime-src/src/colservr/collectserver.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/collectserver.cpp	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/collectserver.cpp	(revision 22050)
@@ -52,4 +52,39 @@
   else {
     cerr << "Error: buildtype '" << buildtype << "' is not a recognized indexer for Greenstone." << endl;
+  }
+
+}
+
+
+void check_if_valid_infodbtype(const text_t& infodbtype)
+{
+  if (infodbtype=="gdbm") {
+#ifndef USE_GDBM
+    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'gdbm'." << endl;
+#endif
+  }
+  else if (infodbtype=="gdbm-txtgz") {
+#ifndef USE_GDBM
+    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'gdbm-txtgz'." << endl;
+#endif
+  }
+  else if (infodbtype=="jdbm") {
+#ifndef USE_JDBM
+    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'jdbm'." << endl;
+#endif
+  }
+  else if (infodbtype=="sqlite") {
+#ifndef USE_SQLITE
+    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'sqlite'." << endl;
+#endif
+  }
+  else if (infodbtype=="mssql") {
+#ifndef USE_MSSQL
+    cerr << "Warning: Greenstone installation has not been compiled to support infodbtype 'mssql'." << endl;
+#endif
+  }
+
+  else {
+    cerr << "Error: infodbtype '" << infodbtype << "' is not a recognized database type for Greenstone." << endl;
   }
 
@@ -242,4 +277,8 @@
       //collectinfo.searchTypes = cfgline;
     }
+    else if (key == "infodbtype") {
+      check_if_valid_infodbtype(value); // prints warning if value (database type) is invalid
+      collectinfo.infodbType = value;
+    }
     else if (key == "separate_cjk") {
       if (value == "true") collectinfo.isSegmented = true;
Index: /main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp	(revision 22050)
@@ -34,4 +34,5 @@
 #include "browsefilter.h"
 #include "sqlbrowsefilter.h"
+#include "sqlqueryfilter.h"
 #include "queryfilter.h"
 
@@ -335,7 +336,7 @@
     dbclass *db_ptr = NULL;
 
-#ifdef USE_SQLITE
     if (infodbtype == "sqlite")
       {
+#ifdef USE_SQLITE
 	sqlitedbclass *sql_db_ptr = new sqlitedbclass();
 	db_ptr = sql_db_ptr;
@@ -345,10 +346,19 @@
 	sqlbrowsefilter->set_sql_db_ptr(sql_db_ptr);
 	cserver->add_filter (sqlbrowsefilter);  
-      }
-#endif
+
+	// add a sql query filter
+	sqlqueryfilterclass *sqlqueryfilter = new sqlqueryfilterclass();
+	sqlqueryfilter->set_sql_db_ptr(sql_db_ptr);
+	cserver->add_filter (sqlqueryfilter);  
+
+#else
+	cerr << "Warning: infodbtype of 'sqlite' was not compiled in to " << endl;
+	cerr << "         this installation of Greenstone";
+#endif
+      }
   
-#ifdef USE_MSSQL
     if (infodbtype == "mssql")
       {
+#ifdef USE_MSSQL
 	mssqldbclass *mssql_db_ptr = new mssqldbclass();
 	db_ptr = mssql_db_ptr;
@@ -358,14 +368,20 @@
 	sqlbrowsefilter->set_sql_db_ptr(mssql_db_ptr);
 	cserver->add_filter (sqlbrowsefilter);  
-      }
-#endif
+#else
+	cerr << "Warning: infodbtype of 'mssql' was not compiled in to " << endl;
+	cerr << "         this installation of Greenstone";
+#endif
+      }
+
+    if (infodbtype == "jdbm") {
 
 #ifdef USE_JDBM
-    if (infodbtype == "jdbm") {
-
 	jdbmnaiveclass *jdbm_db_ptr = new jdbmnaiveclass(gsdlhome);
 	db_ptr = jdbm_db_ptr;
-    }
-#endif
+#else
+	cerr << "Warning: infodbtype of 'jdbm' was not compiled in to " << endl;
+	cerr << "         this installation of Greenstone";
+#endif
+    }
 
     // Use GDBM if the infodb type is empty or not one of the values above
@@ -373,4 +389,7 @@
 #ifdef USE_GDBM
       db_ptr = new gdbmclass();
+#else
+	cerr << "Warning: infodbtype of 'gdbm' was not compiled in to " << endl;
+	cerr << "         this installation of Greenstone";
 #endif
     }
Index: /main/trunk/greenstone2/runtime-src/src/colservr/comtypes.h
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/comtypes.h	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/comtypes.h	(revision 22050)
@@ -106,5 +106,6 @@
   text_t         receptionist;
   text_t         buildType;           // 'mg' or 'mgpp' or 'lucene'
-  text_t         authenticate;      // 'document' or 'collection'
+  text_t         infodbType;          // 'gdbm', 'sqlite', etc.
+  text_t         authenticate;        // 'document' or 'collection'
   text_t         auth_group;          // 'mygroup' 'yourgroup'
   text_tmap      public_documents;    // the acl to allow access to listed documents
Index: /main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 22050)
@@ -265,5 +265,5 @@
 		      endresults, phrasematch, logout);  
 
-    vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
+  vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
    
   // do query
Index: /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.cpp	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.cpp	(revision 22050)
@@ -3,4 +3,5 @@
  * sqlbrowsefilter.cpp -- 
  * Copyright (C) 2008  DL Consulting Ltd
+ * Copyright (C) 2010  New Zealand Digital Library Project
  *
  * A component of the Greenstone digital library software
@@ -25,58 +26,12 @@
 
 #include "sqlbrowsefilter.h"
-#include "fileutil.h"
-
 
 sqlbrowsefilterclass::sqlbrowsefilterclass ()
-{
-  sql_db_ptr = NULL;
-}
+  : sqlfilterclass()
+{}
 
 
 sqlbrowsefilterclass::~sqlbrowsefilterclass ()
-{
-}
-
-
-void sqlbrowsefilterclass::configure (const text_t &key, const text_tarray &cfgline)
-{
-  filterclass::configure (key, cfgline);
-
-  if (key == "indexstem")
-  {
-    indexstem = cfgline[0];
-  }
-}
-
-
-bool sqlbrowsefilterclass::init (ostream &logout)
-{
-  outconvertclass text_t2ascii;
-
-  if (!filterclass::init(logout)) return false;
-
-  if (sql_db_ptr == NULL)
-  {
-    // most likely a configuration problem
-    logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
-    return false;
-  }
-
-  if (indexstem.empty())
-  {
-    indexstem = collection;
-  }
-
-  // get the filename for the database and make sure it exists
-  sql_db_filename = resolve_db_filename(indexstem,sql_db_ptr->getfileextension());
-  if (!file_exists(sql_db_filename))
-  {
-    logout << text_t2ascii << "warning: database \"" << sql_db_filename << "\" does not exist\n\n";
-    return false;
-  }
-
-  return true;
-}
-
+{}
 
 void sqlbrowsefilterclass::filter (const FilterRequest_t &request,
@@ -86,20 +41,5 @@
   outconvertclass text_t2ascii;
 
-  response.clear();
-  err = noError;
-
-  if (sql_db_ptr == NULL) {
-    // most likely a configuration problem
-    logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
-    err = configurationError;
-    return;
-  }
-
-  // open the database
-  sql_db_ptr->setlogout (&logout);
-  if (!sql_db_ptr->opendatabase (sql_db_filename, DB_READER, 100, false)) {
-    // most likely a system problem (we have already checked that the database exists)
-    logout << text_t2ascii << "system problem: open on database \"" << sql_db_filename << "\" failed\n\n";
-    err = systemProblem;
+  if (!connect_to_sqldb(response,err,logout)) {
     return;
   }
@@ -201,4 +141,5 @@
   }
 
-  sql_db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  disconnect_from_sqldb();
+
 }
Index: /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.h
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.h	(revision 22049)
+++ /main/trunk/greenstone2/runtime-src/src/colservr/sqlbrowsefilter.h	(revision 22050)
@@ -3,4 +3,5 @@
  * sqlbrowsefilter.h -- 
  * Copyright (C) 2008  DL Consulting Ltd
+ * Copyright (C) 2010  New Zealand Digital Library Project
  *
  * A component of the Greenstone digital library software
@@ -27,32 +28,15 @@
 #define SQLBROWSEFILTER_H
 
-
-#include "filter.h"
-#include "comtypes.h"
-#include "sqldbclass.h"
-#include "text_t.h"
+#include "sqlfilter.h"
 
 
-class sqlbrowsefilterclass : public filterclass {
-protected:
-  text_t sql_db_filename;
-  text_t indexstem;
-  sqldbclass *sql_db_ptr;
-
-public:
+class sqlbrowsefilterclass : public sqlfilterclass 
+{
+ public:
   sqlbrowsefilterclass ();
   virtual ~sqlbrowsefilterclass ();
-
+  
   text_t get_filter_name () { return "SQLBrowseFilter"; }
-
-  // configure should be called once for each configuration line
-  // default configures the default filter options
-  virtual void configure (const text_t &key, const text_tarray &cfgline);
-
-  // the sql db ptr remains the responsibility of the calling code and
-  // should be destroyed after this sqlbrowsefilter is destroyed
-  void set_sql_db_ptr (sqldbclass *sql_db_ptr_arg) { sql_db_ptr = sql_db_ptr_arg; }
-
-  bool init (ostream &logout);
+  
   void filter (const FilterRequest_t &request,
 	       FilterResponse_t &response,
