Ignore:
Timestamp:
2010-01-15T17:32:09+13:00 (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.