Changeset 15642


Ignore:
Timestamp:
2008-05-22T15:19:10+12:00 (16 years ago)
Author:
mdewsnip
Message:

Function rearrange.

Location:
gsdl/trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/lib/sqlitedbclass.cpp

    r15640 r15642  
    3838
    3939// returns true if opened
    40 bool sqlitedbclass::opendatabase(const text_t &filename, int mode, int num_retrys,
     40bool sqlitedbclass::opendatabase (const text_t &filename, int mode, int num_retrys,
    4141#ifdef __WIN32__
    42                    bool need_filelock
     42                  bool need_filelock
    4343#else
    44                    bool
     44                  bool
    4545#endif
    4646                  )
     
    7272
    7373
    74 void sqlitedbclass::closedatabase()
     74void sqlitedbclass::closedatabase ()
    7575{
    7676  if (sqlitefile == NULL) return;
     
    8282
    8383
     84void 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
     92bool 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
    84105// returns true on success
    85 bool sqlitedbclass::getinfo(const text_t& key, infodbclass &info)
     106bool sqlitedbclass::getinfo (const text_t& key, infodbclass &info)
    86107{
    87108  text_t sql_cmd = "SELECT value FROM data WHERE key='" + key + "'";
     
    106127
    107128
    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
     130text_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";
    112136  vector<text_tmap> sql_results;
    113137  if (!sqlgetarray(sql_cmd, sql_results) || sql_results.size() == 0)
    114138  {
    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;
    119152}
    120153
    121154
    122155// returns true on success
    123 bool sqlitedbclass::setinfo(const text_t &key, const infodbclass &info)
     156bool sqlitedbclass::setinfo (const text_t &key, const infodbclass &info)
    124157{
    125158  text_t subkey;
     
    196229
    197230
    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 table
    210   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 returned
    218   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 
    230231// returns true on success
    231232bool sqlitedbclass::getinfoline (text_t::iterator &here, text_t::iterator end,
    232                   text_t &key, text_t &value)
     233                text_t &key, text_t &value)
    233234{
    234235  key.clear();
  • gsdl/trunk/lib/sqlitedbclass.h

    r15640 r15642  
    4141  bool opendatabase (const text_t &filename, int mode, int num_retrys,
    4242             bool need_filelock);
     43
    4344  void closedatabase ();
    4445
    45   // returns true on success
    46   bool getinfo (const text_t& key, infodbclass &info);
     46  void deletekey (const text_t &key);
    4747
    4848  // returns true if exists
     
    5050
    5151  // 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
    5258  bool setinfo (const text_t &key, const infodbclass &info);
    53 
    54   void deletekey (const text_t &key);
    55 
    56   text_tarray getkeys ();
    5759
    5860protected:
Note: See TracChangeset for help on using the changeset viewer.