Ignore:
Timestamp:
2008-05-22T16:44:51+12:00 (16 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Created default implementations of getinfo() and setinfo() in dbclass so they don't necessarily be re-implemented for every subclass.

File:
1 edited

Legend:

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

    r15652 r15655  
    9090
    9191// returns true on success
    92 bool sqlitedbclass::getinfo (const text_t& key, infodbclass &info)
    93 {
    94   text_t data;
    95   if (!getkeydata(key, data)) return false;
    96 
    97   // Use getinfoline() to parse the data value into the infodbclass object
    98   text_t::iterator data_iterator = data.begin();
    99   text_t ikey, ivalue;
    100   info.clear();
    101   while (getinfoline(data_iterator, data.end(), ikey, ivalue))
    102   {
    103     info.addinfo(ikey, ivalue);
    104   }
    105 
    106   return true;
    107 }
    108 
    109 
    110 // returns true on success
    11192bool sqlitedbclass::getkeydata (const text_t& key, text_t &data)
    11293{
     
    151132
    152133// returns true on success
    153 bool sqlitedbclass::setinfo (const text_t &key, const infodbclass &info)
    154 {
    155   text_t subkey;
    156   text_t data;
    157 
    158   // get all the keys and values
    159   infodbclass::const_iterator info_here = info.begin();
    160   infodbclass::const_iterator info_end = info.end();
    161   while (info_here != info_end) {
    162     // add the key
    163     subkey.clear();
    164     subkey.push_back('<');
    165     text_t::const_iterator subkey_here = (*info_here).first.begin();
    166     text_t::const_iterator subkey_end = (*info_here).first.end();
    167     while (subkey_here != subkey_end) {
    168       if (*subkey_here == '>') {
    169     subkey.push_back('\\'); subkey.push_back('>');
    170       } else if (*subkey_here == '\n') {
    171     subkey.push_back('\\'); subkey.push_back('n');
    172       } else if (*subkey_here == '\r') {
    173     subkey.push_back('\\'); subkey.push_back('r');
    174       } else if (*subkey_here == '\\') {
    175     subkey.push_back('\\'); subkey.push_back('\\');
    176       } else {
    177     subkey.push_back (*subkey_here);
    178       }
    179       ++subkey_here;
    180     }
    181     subkey.push_back('>');
    182 
    183     // add the values
    184     text_tarray::const_iterator subvalue_here = (*info_here).second.begin();
    185     text_tarray::const_iterator subvalue_end = (*info_here).second.end();
    186     while (subvalue_here != subvalue_end) {
    187       data += subkey;
    188      
    189       text_t::const_iterator thissubvalue_here = (*subvalue_here).begin();
    190       text_t::const_iterator thissubvalue_end = (*subvalue_here).end();
    191       while (thissubvalue_here != thissubvalue_end) {
    192     if (*thissubvalue_here == '>') {
    193       data.push_back('\\'); data.push_back('>');
    194     } else if (*thissubvalue_here == '\n') {
    195       data.push_back('\\'); data.push_back('n');
    196     } else if (*thissubvalue_here == '\r') {
    197       data.push_back('\\'); data.push_back('r');
    198     } else if (*thissubvalue_here == '\\') {
    199       data.push_back('\\'); data.push_back('\\');
    200     } else {
    201       data.push_back (*thissubvalue_here);
    202     }
    203    
    204     ++thissubvalue_here;
    205       }
    206      
    207       data.push_back('\n');
    208       ++subvalue_here;
    209     }
    210 
    211     ++info_here;
    212   }
    213 
    214   return setkeydata(key, data);
    215 }
    216 
    217 
    218 // returns true on success
    219134bool sqlitedbclass::setkeydata (const text_t &key, const text_t &data)
    220135{
     
    233148
    234149
    235 // returns true on success
    236 bool sqlitedbclass::getinfoline (text_t::iterator &here, text_t::iterator end,
    237                  text_t &key, text_t &value)
    238 {
    239   key.clear();
    240   value.clear();
    241 
    242   // ignore white space
    243   while (here != end && is_unicode_space (*here)) ++here;
    244 
    245   // get the '<'
    246   if (here == end || *here != '<') return false;
    247   ++here;
    248  
    249   // get the key
    250   while (here != end && *here != '>') {
    251     key.push_back(*here);
    252     ++here;
    253   }
    254  
    255   // get the '>'
    256   if (here == end || *here != '>') return false;
    257   ++here;
    258  
    259   // get the value
    260   while (here != end && *here != '\n') {
    261     if (*here == '\\') {
    262       // found escape character
    263       ++here;
    264       if (here != end) {
    265     if (*here == 'n') value.push_back ('\n');
    266     else if (*here == 'r') value.push_back ('\r');
    267     else value.push_back(*here);
    268       }
    269 
    270     } else {
    271       // a normal character
    272       value.push_back(*here);
    273     }
    274 
    275     ++here;
    276   }
    277 
    278   return true;
    279 }
    280 
    281 
    282150// ----------------------------------------------------------------------------------------
    283 //   CORE SQL FUNCTIONS
     151//   SQLITE-ONLY FUNCTIONS
    284152// ----------------------------------------------------------------------------------------
    285153
Note: See TracChangeset for help on using the changeset viewer.