本文整理汇总了C++中QSqlQueryModel::submit方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQueryModel::submit方法的具体用法?C++ QSqlQueryModel::submit怎么用?C++ QSqlQueryModel::submit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlQueryModel
的用法示例。
在下文中一共展示了QSqlQueryModel::submit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readContents
bool DatabaseBackup::readContents(const QString &filename) {
qDebug() << "Read contents from " + filename;
QFile file(filename);
QSqlQueryModel query;
bool res = false;
if (file.open(QIODevice::ReadOnly)) {
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (doc.isObject()) {
res = true;
QJsonArray tables = doc.object().take("database").toObject().take("tables").toArray();
QJsonArray::const_iterator i = tables.constBegin();
while (i != tables.constEnd()) {
QString tableName = (*i).toObject().take("name").toString();
qDebug() << tableName;
QJsonArray records = (*i).toObject().take("records").toArray();
QJsonArray::const_iterator recordIterator = records.constBegin();
while (recordIterator != records.constEnd()) {
QVariantMap record = (*recordIterator).toObject().toVariantMap();
QStringList fields = record.keys();
QStringList values;
QStringList::const_iterator fieldIterator = fields.constBegin();
while (fieldIterator != fields.constEnd()) {
values << record.take(*fieldIterator).toString();
++fieldIterator;
}
qDebug() << "INSERT INTO " + tableName + " (" + fields.join(',') + ")" + " VALUES ('" + values.join("','") + "')";
query.setQuery( QSqlQuery("INSERT INTO " + tableName + " (" + fields.join(',') + ")" + " VALUES ('" + values.join("','") + "')") );
qDebug() << "Errors?" << query.lastError();
++ recordIterator;
}
++i;
}
}
query.submit();
}
file.close();
return res;
}