1 #ifndef EASYQTSQL_UPDATEQUERY_H 2 #define EASYQTSQL_UPDATEQUERY_H 29 #ifndef EASY_QT_SQL_MAIN 65 m_updateMap[field] = value;
85 for (
auto it = map.begin(); it != map.end(); ++it)
87 m_updateMap[it.key()] = it.value();
126 m_params.append(last);
131 template <
typename... Rest>
NonQueryResult where(
const QString &expr,
const QVariant &first,
const Rest&... rest)
133 m_params.append(first);
134 return where(expr, rest...);
142 QString sql =
"UPDATE " + m_table +
" SET ";
143 QStringList fieldValuePairs;
145 for (
auto it = m_updateMap.begin(); it != m_updateMap.end(); ++it)
147 fieldValuePairs.append(it.key() +
"=?");
150 sql += fieldValuePairs.join(
",");
152 if (!m_whereExpr.isEmpty())
154 sql +=
" WHERE " + m_whereExpr;
159 for (
auto it = m_updateMap.begin(); it != m_updateMap.end(); ++it)
161 q.addBindValue(it.value());
164 for (
auto it = m_params.begin(); it != m_params.end(); ++it)
171 #ifdef DB_EXCEPTIONS_ENABLED 184 QVariantMap m_updateMap;
185 QVariantList m_params;
189 #endif // EASYQTSQL_UPDATEQUERY_H NonQueryResult where(const QString &expr)
Executes update query with expr condition.
Definition: EasyQtSql_UpdateQuery.h:104
UpdateQuery(const QString &table, const QSqlDatabase &db)
Definition: EasyQtSql_UpdateQuery.h:42
NonQueryResult exec()
Executes UPDATE query without conditions.
Definition: EasyQtSql_UpdateQuery.h:140
NonQueryResult where(const QString &expr, const QVariant &first, const Rest &... rest)
Definition: EasyQtSql_UpdateQuery.h:131
QSqlQuery wrapper for non-select query results reading.
Definition: EasyQtSql_NonQueryResult.h:38
NonQueryResult where(const QString &expr, const QVariant &last)
Executes update query with expr condition and last parameter binding.
Definition: EasyQtSql_UpdateQuery.h:124
QSqlQuery wrapper for UPDATE ... SET ... WHERE ... query execution.
Definition: EasyQtSql_UpdateQuery.h:39
Exception class for SQL errors handling.
Definition: EasyQtSql_DBException.h:38