Changeset 15623

Show
Ignore:
Timestamp:
22.05.2008 10:43:11 (12 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Implemented a first cut at the getinfo() function.

Location:
gsdl/trunk/lib
Files:
2 modified

Legend:

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

    r15603 r15623  
    2525 
    2626#include "sqliteclass.h" 
     27#include "unitool.h" 
    2728 
    2829 
     
    9394  } 
    9495 
     96  outconvertclass text_t2ascii; 
     97 
    9598  text_tmap sql_result = sql_results[0]; 
    96  
    97   // !! TO FINISH 
     99  text_t sql_result_value = sql_result["value"]; 
     100  (*logout) << text_t2ascii << "Result: " << sql_result_value << "\n"; 
     101 
     102  text_t::iterator sql_result_value_iterator = sql_result_value.begin(); 
     103  text_t ikey, ivalue; 
     104  info.clear(); 
     105  while (getinfoline(sql_result_value_iterator, sql_result_value.end(), ikey, ivalue)) 
     106  { 
     107    info.addinfo(ikey, ivalue); 
     108  } 
    98109 
    99110  return true; 
     
    207218 
    208219 
     220// returns true on success 
     221bool sqliteclass::getinfoline (text_t::iterator &here, text_t::iterator end,  
     222                   text_t &key, text_t &value) 
     223{ 
     224  key.clear(); 
     225  value.clear(); 
     226 
     227  // ignore white space 
     228  while (here != end && is_unicode_space (*here)) ++here; 
     229 
     230  // get the '<' 
     231  if (here == end || *here != '<') return false; 
     232  ++here; 
     233   
     234  // get the key 
     235  while (here != end && *here != '>') { 
     236    key.push_back(*here); 
     237    ++here; 
     238  } 
     239   
     240  // get the '>' 
     241  if (here == end || *here != '>') return false; 
     242  ++here; 
     243   
     244  // get the value 
     245  while (here != end && *here != '\n') { 
     246    if (*here == '\\') {  
     247      // found escape character 
     248      ++here; 
     249      if (here != end) { 
     250    if (*here == 'n') value.push_back ('\n'); 
     251    else if (*here == 'r') value.push_back ('\r'); 
     252    else value.push_back(*here); 
     253      } 
     254 
     255    } else { 
     256      // a normal character 
     257      value.push_back(*here); 
     258    } 
     259 
     260    ++here; 
     261  } 
     262 
     263  return true; 
     264} 
     265 
     266 
     267// ---------------------------------------------------------------------------------------- 
     268//   CORE SQL FUNCTIONS 
     269// ---------------------------------------------------------------------------------------- 
     270 
    209271// sqlexec simply executes the given sql statement - it doesn't obtain a 
    210272// result set - returns true if the sql statement was executed successfully 
     
    259321 
    260322 
    261 // sqlgetarray executes sql and returns the result set in result 
     323// sqlgetarray executes sql and returns the result set in sql_results 
    262324bool sqliteclass::sqlgetarray(const text_t &sql_cmd, vector<text_tmap> &sql_results) 
    263325{ 
  • gsdl/trunk/lib/sqliteclass.h

    r15602 r15623  
    6565  sqlite3* sqlitefile; 
    6666 
    67   bool sqlgetarray(const text_t &sql_cmd, vector<text_tmap> &sql_results); 
    68   bool sqlexec(const text_t &sql_cmd); 
     67  bool getinfoline (text_t::iterator &here, text_t::iterator end,  
     68            text_t &key, text_t &value); 
     69 
     70  bool sqlgetarray (const text_t &sql_cmd, vector<text_tmap> &sql_results); 
     71  bool sqlexec (const text_t &sql_cmd); 
    6972}; 
    7073