将VariantMap添加到数据库
insertRecord(const QVariantMap &trans)
{
bool ret = false;
if(trans.isEmpty())
{
return ret;
}
QString dbName = QString("./data/Record.db")
QString sql = "INSERT INTO table";
QString keys = "(";
QString V = “"; #存放表名
QVariantList list;
QVariantMap::const_iterator iter = trans.constBegin(); #遍历Map
while(iter != trans.constEnd()){
keys +=i.key(); #保存字段
keys += ", ";
v += "?,"; 保存值
list << i.value(); 保存值
++iter;
}
keys = keys.trimmed();#除去两边的空格
keys = keys.left(keys.length()-1);
sql += keys;
sql += ") VALUES( ";
V = V.trimmed();
v = v.left(v.leghts()-1); 除去最后一个逗号
sql += v;
ret = help(dbname).execQuery(sql,list);
}