Ignore:
Timestamp:
2008-05-20T17:19:33+12:00 (16 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Quick implementation of setinfo().

File:
1 edited

Legend:

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

    r15602 r15603  
    6363  }
    6464
     65  if (sqlitefile != NULL && mode == DB_WRITER_CREATE)
     66  {
     67    sqlexec("CREATE TABLE data (key TEXT, value TEXT, PRIMARY KEY(key))");
     68  }
     69
    6570  return (sqlitefile != NULL);
    6671}
     
    8085bool sqliteclass::getinfo(const text_t& key, infodbclass &info)
    8186{
    82   text_t sql_cmd = "SELECT value FROM table WHERE key=" + key;
     87  text_t sql_cmd = "SELECT value FROM data WHERE key='" + key + "'";
    8388
    8489  vector<text_tmap> sql_results;
     
    109114  if (sqlitefile == NULL) return false;
    110115
    111   // !! TO IMPLEMENT
    112   return false;
     116  text_t subkey;
     117  text_t data;
     118
     119  // get all the keys and values
     120  infodbclass::const_iterator info_here = info.begin();
     121  infodbclass::const_iterator info_end = info.end();
     122  while (info_here != info_end) {
     123    // add the key
     124    subkey.clear();
     125    subkey.push_back('<');
     126    text_t::const_iterator subkey_here = (*info_here).first.begin();
     127    text_t::const_iterator subkey_end = (*info_here).first.end();
     128    while (subkey_here != subkey_end) {
     129      if (*subkey_here == '>') {
     130    subkey.push_back('\\'); subkey.push_back('>');
     131      } else if (*subkey_here == '\n') {
     132    subkey.push_back('\\'); subkey.push_back('n');
     133      } else if (*subkey_here == '\r') {
     134    subkey.push_back('\\'); subkey.push_back('r');
     135      } else if (*subkey_here == '\\') {
     136    subkey.push_back('\\'); subkey.push_back('\\');
     137      } else {
     138    subkey.push_back (*subkey_here);
     139      }
     140      ++subkey_here;
     141    }
     142    subkey.push_back('>');
     143
     144    // add the values
     145    text_tarray::const_iterator subvalue_here = (*info_here).second.begin();
     146    text_tarray::const_iterator subvalue_end = (*info_here).second.end();
     147    while (subvalue_here != subvalue_end) {
     148      data += subkey;
     149     
     150      text_t::const_iterator thissubvalue_here = (*subvalue_here).begin();
     151      text_t::const_iterator thissubvalue_end = (*subvalue_here).end();
     152      while (thissubvalue_here != thissubvalue_end) {
     153    if (*thissubvalue_here == '>') {
     154      data.push_back('\\'); data.push_back('>');
     155    } else if (*thissubvalue_here == '\n') {
     156      data.push_back('\\'); data.push_back('n');
     157    } else if (*thissubvalue_here == '\r') {
     158      data.push_back('\\'); data.push_back('r');
     159    } else if (*thissubvalue_here == '\\') {
     160      data.push_back('\\'); data.push_back('\\');
     161    } else {
     162      data.push_back (*thissubvalue_here);
     163    }
     164   
     165    ++thissubvalue_here;
     166      }
     167     
     168      data.push_back('\n');
     169      ++subvalue_here;
     170    }
     171
     172    ++info_here;
     173  }
     174
     175  outconvertclass text_t2ascii;
     176  (*logout) << text_t2ascii << "Inserting for " << key << ":\n" << data << "\n";
     177
     178  text_t sql_cmd = "INSERT INTO data (key, value) VALUES ('" + key + "', '" + data + "')";
     179  return sqlexec(sql_cmd);
    113180}
    114181
     
    116183void sqliteclass::deletekey(const text_t &key)
    117184{
    118   if (sqlitefile == NULL) return;
     185  if (sqlitefile == NULL) return; 
    119186
    120187  // !! TO IMPLEMENT
Note: See TracChangeset for help on using the changeset viewer.