Changeset 15636

Show
Ignore:
Timestamp:
22.05.2008 14:06:54 (11 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Changing the setinfo() function to use either INSERT or UPDATE, depending on whether the key already exists.

Files:
1 modified

Legend:

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

    r15635 r15636  
    182182  } 
    183183 
    184   outconvertclass text_t2ascii; 
    185   (*logout) << text_t2ascii << "Inserting for " << key << ":\n" << data << "\n"; 
    186  
    187   text_t sql_cmd = "INSERT INTO data (key, value) VALUES ('" + key + "', '" + data + "')"; 
    188   return sqlexec(sql_cmd); 
     184  // We need to do either an INSERT or UPDATE depending on whether the key already exists 
     185  if (!exists(key)) 
     186  { 
     187    text_t sql_cmd = "INSERT INTO data (key, value) VALUES ('" + key + "', '" + data + "')"; 
     188    return sqlexec(sql_cmd); 
     189  } 
     190  else 
     191  { 
     192    text_t sql_cmd = "UPDATE data SET value='" + data + "' WHERE key='" + key + "'"; 
     193    return sqlexec(sql_cmd); 
     194  } 
    189195} 
    190196