Changeset 15642
- Timestamp:
- 2008-05-22T15:19:10+12:00 (16 years ago)
- Location:
- gsdl/trunk/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/sqlitedbclass.cpp
r15640 r15642 38 38 39 39 // returns true if opened 40 bool sqlitedbclass::opendatabase (const text_t &filename, int mode, int num_retrys,40 bool sqlitedbclass::opendatabase (const text_t &filename, int mode, int num_retrys, 41 41 #ifdef __WIN32__ 42 42 bool need_filelock 43 43 #else 44 44 bool 45 45 #endif 46 46 ) … … 72 72 73 73 74 void sqlitedbclass::closedatabase ()74 void sqlitedbclass::closedatabase () 75 75 { 76 76 if (sqlitefile == NULL) return; … … 82 82 83 83 84 void sqlitedbclass::deletekey (const text_t &key) 85 { 86 text_t sql_cmd = "DELETE FROM data WHERE key='" + key + "'"; 87 sqlexec(sql_cmd); 88 } 89 90 91 // returns true if exists 92 bool sqlitedbclass::exists (const text_t& key) 93 { 94 text_t sql_cmd = "SELECT value FROM data WHERE key='" + key + "'"; 95 vector<text_tmap> sql_results; 96 if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0) 97 { 98 return false; 99 } 100 101 return true; 102 } 103 104 84 105 // returns true on success 85 bool sqlitedbclass::getinfo (const text_t& key, infodbclass &info)106 bool sqlitedbclass::getinfo (const text_t& key, infodbclass &info) 86 107 { 87 108 text_t sql_cmd = "SELECT value FROM data WHERE key='" + key + "'"; … … 106 127 107 128 108 // returns true if exists 109 bool sqlitedbclass::exists(const text_t& key) 110 { 111 text_t sql_cmd = "SELECT value FROM data WHERE key='" + key + "'"; 129 // returns array of keys 130 text_tarray sqlitedbclass::getkeys () 131 { 132 text_tarray keys; 133 134 // Get all the entries in the "key" column of the table 135 text_t sql_cmd = "SELECT key FROM data"; 112 136 vector<text_tmap> sql_results; 113 137 if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0) 114 138 { 115 return false; 116 } 117 118 return true; 139 return keys; 140 } 141 142 // Iterate through the keys and add them to the array to be returned 143 vector<text_tmap>::iterator sql_results_iterator = sql_results.begin(); 144 while (sql_results_iterator != sql_results.end()) 145 { 146 text_tmap sql_result = (*sql_results_iterator); 147 keys.push_back(sql_result["key"]); 148 sql_results_iterator++; 149 } 150 151 return keys; 119 152 } 120 153 121 154 122 155 // returns true on success 123 bool sqlitedbclass::setinfo (const text_t &key, const infodbclass &info)156 bool sqlitedbclass::setinfo (const text_t &key, const infodbclass &info) 124 157 { 125 158 text_t subkey; … … 196 229 197 230 198 void sqlitedbclass::deletekey (const text_t &key)199 {200 text_t sql_cmd = "DELETE FROM data WHERE key='" + key + "'";201 sqlexec(sql_cmd);202 }203 204 205 text_tarray sqlitedbclass::getkeys ()206 {207 text_tarray keys;208 209 // Get all the entries in the "key" column of the table210 text_t sql_cmd = "SELECT key FROM data";211 vector<text_tmap> sql_results;212 if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0)213 {214 return keys;215 }216 217 // Iterate through the keys and add them to the array to be returned218 vector<text_tmap>::iterator sql_results_iterator = sql_results.begin();219 while (sql_results_iterator != sql_results.end())220 {221 text_tmap sql_result = (*sql_results_iterator);222 keys.push_back(sql_result["key"]);223 sql_results_iterator++;224 }225 226 return keys;227 }228 229 230 231 // returns true on success 231 232 bool sqlitedbclass::getinfoline (text_t::iterator &here, text_t::iterator end, 232 233 text_t &key, text_t &value) 233 234 { 234 235 key.clear(); -
gsdl/trunk/lib/sqlitedbclass.h
r15640 r15642 41 41 bool opendatabase (const text_t &filename, int mode, int num_retrys, 42 42 bool need_filelock); 43 43 44 void closedatabase (); 44 45 45 // returns true on success 46 bool getinfo (const text_t& key, infodbclass &info); 46 void deletekey (const text_t &key); 47 47 48 48 // returns true if exists … … 50 50 51 51 // returns true on success 52 bool getinfo (const text_t& key, infodbclass &info); 53 54 // returns array of keys 55 text_tarray getkeys (); 56 57 // returns true on success 52 58 bool setinfo (const text_t &key, const infodbclass &info); 53 54 void deletekey (const text_t &key);55 56 text_tarray getkeys ();57 59 58 60 protected:
Note:
See TracChangeset
for help on using the changeset viewer.