- Timestamp:
- 2010-01-15T17:32:09+13:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/recpt/historydb.cpp
r19062 r21485 29 29 #include "recptproto.h" 30 30 #include "recptprototools.h" 31 #include "dbclass.h" 32 33 #ifdef USE_GDBM 31 34 #include "gdbmclass.h" 35 #endif 36 32 37 33 38 #define MAX_RECORDS 20 34 39 #define HIST_SEP ';' 40 41 42 dbclass* 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 35 55 36 56 // returns true on success (in which case historyinfo will contain … … 39 59 const text_t &gsdlhome, ostream &logout) { 40 60 41 text_t historyfile = filename_cat(gsdlhome, "etc", "history.gdb");42 43 61 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 44 68 // 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)) { 48 70 // get history list 49 71 text_t historyresult; 50 72 51 historydb .getkeydata(userid, historyresult);73 historydb->getkeydata(userid, historyresult); 52 74 53 75 if (historyresult != "") { // there are entries, process them … … 56 78 result = true; 57 79 } 58 historydb .closedatabase();80 historydb->closedatabase(); 59 81 60 82 } else { … … 62 84 logout << text_t2ascii << "couldn't open history database " << historyfile << "\n"; 63 85 } 86 87 delete historydb; 64 88 return result; 65 89 } … … 71 95 bool set_history_info (const text_t &userid, const text_t &history, const text_t &gsdlhome, bool display) { 72 96 73 text_t historyfile = filename_cat(gsdlhome, "etc", "history.gdb");74 75 97 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(); 78 103 79 104 text_t oldhistoryresult; … … 81 106 int numentries=0; 82 107 83 if (!historydb.opendatabase(historyfile, DB_READER, 1000, true)) { 108 // open the history database 109 if (!historydb->opendatabase(historyfile, DB_READER, 1000, true)) { 84 110 // not created yet 85 111 oldhistoryresult=""; … … 89 115 90 116 // get history list 91 if (! historydb .getkeydata(userid, oldhistoryresult)) {117 if (! historydb->getkeydata(userid, oldhistoryresult)) { 92 118 oldhistoryresult=""; 93 119 if (!display) return true; // dont need to save 94 120 } 95 historydb .closedatabase();121 historydb->closedatabase(); 96 122 } 97 123 … … 105 131 106 132 // 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; 108 134 109 135 // add on new linethe new record to the front of the list, then add the … … 115 141 } 116 142 117 if (historydb .setkeydata(userid, newhistoryresult))143 if (historydb->setkeydata(userid, newhistoryresult)) 118 144 result=true; 119 145 120 historydb.closedatabase(); 146 historydb->closedatabase(); 147 delete historydb; 121 148 return result; 122 149 } … … 125 152 bool delete_all_history_info (const text_t &userid, const text_t &gsdlhome) { 126 153 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(); 128 158 129 159 // 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; 136 165 return true; 137 166
Note:
See TracChangeset
for help on using the changeset viewer.