Changeset 21485


Ignore:
Timestamp:
2010-01-15T17:32:09+13:00 (12 years ago)
Author:
mdewsnip
Message:

Modifying historydb.cpp so it uses the more general dbclass object instead of being hard-wired to use gdbmclass. However, this class is still set up to use gdbm, provided USE_GDBM is set (which it always is in the main Greenstone). The problem with the history database is it is Greenstone-specific, not collection-specific, so there is no infodbtype option to check to see what database type should be used (a new option will need to be created in the main.cfg file). If USE_GDBM isn't set, the historydb class will do nothing.

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/Makefile.in

    r21324 r21485  
    8181endif
    8282
     83# Currently not configurable, and always on
     84USE_GDBM = 1
     85ifeq ($(USE_GDBM), 1)
     86GDBM_DEFINES = -DUSE_GDBM
     87GDBM_INCLUDES = -I$(COMMON_PACKAGES_DIR)/gdbm/include
     88else
     89GDBM_DEFINES =
     90GDBM_INCLUDES =
     91endif
     92
    8393USE_SQLITE = @USE_SQLITE@
    8494ifeq ($(USE_SQLITE), 1)
     
    125135CXX = @CXX@
    126136CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
    127 DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(Z3950_DEFS)
    128 INCLUDES = -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib -I$(COMMON_PACKAGES_DIR)/gdbm/include \
     137DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(GDBM_DEFINES) $(Z3950_DEFS)
     138INCLUDES = -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib \
    129139        -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) \
    130140    $(MG_INCLUDES) $(MGPP_INCLUDES) \
    131         -I$(COMMON_PACKAGES_DIR)/expat/include $(FASTCGI_INCLUDES) $(Z3950_INCLUDES)
     141        -I$(COMMON_PACKAGES_DIR)/expat/include $(FASTCGI_INCLUDES) $(GDBM_INCLUDES) $(Z3950_INCLUDES)
    132142INSTALL = @INSTALL@
    133143LDFLAGS = @LDFLAGS@ @COMPAT32BITFLAGS@
  • main/trunk/greenstone2/runtime-src/src/recpt/historydb.cpp

    r19062 r21485  
    2929#include "recptproto.h"
    3030#include "recptprototools.h"
     31#include "dbclass.h"
     32
     33#ifdef USE_GDBM
    3134#include "gdbmclass.h"
     35#endif
     36
    3237
    3338#define MAX_RECORDS 20
    3439#define HIST_SEP ';'
     40
     41
     42dbclass* get_history_db_ptr ()
     43{
     44  // Create a dbclass of the correct type
     45  dbclass *historydb = NULL;
     46
     47  // Use GDBM only at this stage
     48#ifdef USE_GDBM
     49    historydb = new gdbmclass();
     50#endif
     51
     52  return historydb;
     53}
     54
    3555
    3656// returns true on success (in which case historyinfo will contain
     
    3959               const text_t &gsdlhome, ostream &logout) {
    4060
    41   text_t historyfile = filename_cat(gsdlhome, "etc", "history.gdb");
    42  
    4361  bool result = false;
     62
     63  // Create a dbclass of the correct type
     64  dbclass *historydb = get_history_db_ptr();
     65  if (historydb == NULL) return false;
     66  text_t historyfile = filename_cat(gsdlhome, "etc", "history") + historydb->getfileextension();
     67 
    4468  // open the history database 
    45   gdbmclass historydb;
    46  
    47   if (historydb.opendatabase(historyfile, DB_READER, 1000, true)) {
     69  if (historydb->opendatabase(historyfile, DB_READER, 1000, true)) {
    4870    // get history list
    4971    text_t historyresult;
    5072   
    51     historydb.getkeydata(userid, historyresult);
     73    historydb->getkeydata(userid, historyresult);
    5274   
    5375    if (historyresult != "") { //  there are entries, process them
     
    5678      result = true;
    5779    }
    58     historydb.closedatabase();
     80    historydb->closedatabase();
    5981   
    6082  } else {
     
    6284    logout << text_t2ascii << "couldn't open history database " << historyfile << "\n";
    6385  }
     86
     87  delete historydb;
    6488  return result;
    6589}
     
    7195bool set_history_info (const text_t &userid, const text_t &history, const text_t &gsdlhome, bool display) {
    7296
    73   text_t historyfile = filename_cat(gsdlhome, "etc", "history.gdb");
    74  
    7597  bool result = false;
    76   // open the history database 
    77   gdbmclass historydb;
     98
     99  // Create a dbclass of the correct type
     100  dbclass *historydb = get_history_db_ptr();
     101  if (historydb == NULL) return false;
     102  text_t historyfile = filename_cat(gsdlhome, "etc", "history") + historydb->getfileextension();
    78103 
    79104  text_t oldhistoryresult;
     
    81106  int numentries=0;
    82107
    83   if (!historydb.opendatabase(historyfile, DB_READER, 1000, true)) {
     108  // open the history database 
     109  if (!historydb->opendatabase(historyfile, DB_READER, 1000, true)) {
    84110    // not created yet
    85111    oldhistoryresult="";
     
    89115
    90116    // get history list
    91    if (! historydb.getkeydata(userid, oldhistoryresult)) {
     117   if (! historydb->getkeydata(userid, oldhistoryresult)) {
    92118     oldhistoryresult="";
    93119     if (!display) return true; // dont need to save
    94120   }
    95    historydb.closedatabase();
     121   historydb->closedatabase();
    96122  }
    97123
     
    105131 
    106132  // open for writing
    107   if (!historydb.opendatabase(historyfile, DB_WRITER_CREATE, 1000, true)) return false;
     133  if (!historydb->opendatabase(historyfile, DB_WRITER_CREATE, 1000, true)) return false;
    108134 
    109135  // add on new linethe new record to the front of the list, then add the
     
    115141  }
    116142 
    117   if (historydb.setkeydata(userid, newhistoryresult))
     143  if (historydb->setkeydata(userid, newhistoryresult))
    118144    result=true;
    119145 
    120   historydb.closedatabase();
     146  historydb->closedatabase();
     147  delete historydb;
    121148  return result;
    122149}
     
    125152bool delete_all_history_info (const text_t &userid, const text_t &gsdlhome) {
    126153
    127   text_t historyfile = filename_cat(gsdlhome, "etc", "history.gdb");
     154  // Create a dbclass of the correct type
     155  dbclass *historydb = get_history_db_ptr();
     156  if (historydb == NULL) return false;
     157  text_t historyfile = filename_cat(gsdlhome, "etc", "history") + historydb->getfileextension();
    128158 
    129159  // open the history database 
    130   gdbmclass historydb;
    131  
    132   if (!historydb.opendatabase(historyfile, DB_WRITER, 1000, true)) return false;
    133 
    134   historydb.deletekey(userid);
    135   historydb.closedatabase();
     160  if (!historydb->opendatabase(historyfile, DB_WRITER, 1000, true)) return false;
     161
     162  historydb->deletekey(userid);
     163  historydb->closedatabase();
     164  delete historydb;
    136165  return true;
    137166 
  • main/trunk/greenstone2/runtime-src/src/recpt/win32.mak

    r21435 r21485  
    4444DLLDEBUG = 0
    4545ENABLE_ACCENTFOLD = 1
     46USE_GDBM = 1
    4647USE_SQLITE = 1
    4748ENABLE_MG = 1
     
    7374!ELSE
    7475ACCENTFOLD_LIBS =
     76!ENDIF
     77
     78!IF $(USE_GDBM)
     79GDBM_DEFINES = -DUSE_GDBM
     80GDBM_INCLUDES = -I"$(COMMON_PACKAGES_DIR)\gdbm\gdbm-1.8.3" -I"$(COMMON_PACKAGES_DIR)\gdbm\gdbm-1.8.3\windows"
     81!ELSE
     82GDBM_DEFINES =
     83GDBM_INCLUDES =
    7584!ENDIF
    7685
     
    121130CC = cl
    122131DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE \
    123         -DGSDL_NOCACHE $(Z3950_DEFS) $(MG_DEFS) $(MGPP_DEFS)
     132        -DGSDL_NOCACHE $(GDBM_DEFINES) $(Z3950_DEFS) $(MG_DEFS) $(MGPP_DEFS)
    124133INCLUDES = -I. -I"$(GSDL_DIR)" -I"$(COMMON_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(PROTOCOL_DIR)" \
    125134    $(MG_INCLUDES) $(MGPP_INCLUDES) \
    126135    -I"$(COMMON_PACKAGES_DIR)\windows\crypt\crypt" -I"$(COMMON_PACKAGES_DIR)\windows\expat\expat" \
    127     -I"$(COMMON_PACKAGES_DIR)\gdbm\gdbm-1.8.3" -I"$(COMMON_PACKAGES_DIR)\gdbm\gdbm-1.8.3\windows" \
     136    $(GDBM_INCLUDES) \
    128137    $(Z3950_INCLUDES)
    129138LDFLAGS =
Note: See TracChangeset for help on using the changeset viewer.