void SqliteDB::insertRecord( record_t &data, const QString &tablename) { QStringList hdr = data.keys(); QString fields; QString values; fields.append("("); values.append("("); QMapIterator<QString, QString> iter(data); while(iter.hasNext()){ iter.next(); fields.append(iter.key()+","); QString temp = QString(iter.value()); values.append("\'"+temp.replace("'", "''")+"\',"); } fields.remove(fields.size()-1, 1); values.remove(values.size()-1, 1); fields.append(")"); values.append(")"); QString statement = "INSERT INTO "; statement.append( tablename ); statement.append( fields ); statement.append(" VALUES "); statement.append( values ); exec(statement); }
void SqliteDB::updateRecord( record_t &data, const QString &cond, const QString &tablename) { QStringList hdr = data.keys(); QString values; QMapIterator<QString, QString> iter(data); while(iter.hasNext()){ iter.next(); QString temp = QString(iter.value()); values.append(iter.key()+"=\'"+temp.replace("'", "''")+"\',"); } values.remove(values.size()-1, 1); QString statement = "UPDATE "; statement.append( tablename ); statement.append(" SET "); statement.append( values ); statement.append(" WHERE "); statement.append( cond ); exec(statement); }