1 #ifndef EASYQTSQL_PREPAREDQUERY_H 2 #define EASYQTSQL_PREPAREDQUERY_H 29 #ifndef EASY_QT_SQL_MAIN 66 PreparedQuery(
const QString &stmt,
const QSqlDatabase &db,
bool forwardOnly =
true)
69 m_query.setForwardOnly(forwardOnly);
70 m_query.prepare(stmt);
77 const bool res = m_query.exec();
79 #ifdef DB_EXCEPTIONS_ENABLED 95 m_query.bindValue(m_index, bindValue);
102 m_query.bindValue(m_index, paramWrapper.
value, QSql::In);
104 addAliasIfSet(paramWrapper, m_index);
111 m_query.bindValue(m_index, paramWrapper.
value, QSql::Out);
113 addAliasIfSet(paramWrapper, m_index);
120 m_query.bindValue(m_index, paramWrapper.
value, QSql::InOut);
122 addAliasIfSet(paramWrapper, m_index);
127 template <
typename... Rest>
QueryResult &
exec(
const QVariant &bindValue,
const Rest&... rest)
129 m_query.bindValue(m_index, bindValue);
133 return exec(rest...);
138 m_query.bindValue(m_index, paramWrapper.
value, QSql::In);
140 addAliasIfSet(paramWrapper, m_index);
144 return exec(rest...);
149 m_query.bindValue(m_index, paramWrapper.
value, QSql::Out);
151 addAliasIfSet(paramWrapper, m_index);
155 return exec(rest...);
160 m_query.bindValue(m_index, paramWrapper.
value, QSql::InOut);
162 addAliasIfSet(paramWrapper, m_index);
166 return exec(rest...);
176 QMap<QString, int> m_aliases;
180 if (!paramWrapper.
alias.isEmpty())
182 m_aliases[paramWrapper.
alias] = index;
187 #endif // EASYQTSQL_PREPAREDQUERY_H Input SQL parameters wrapper.
Definition: EasyQtSql_ParamDirectionWrapper.h:61
Class for query preparation and execution.
Definition: EasyQtSql_PreparedQuery.h:63
const QString alias
Definition: EasyQtSql_ParamDirectionWrapper.h:50
PreparedQuery(const QString &stmt, const QSqlDatabase &db, bool forwardOnly=true)
Definition: EasyQtSql_PreparedQuery.h:66
QueryResult & exec(const Out ¶mWrapper)
Definition: EasyQtSql_PreparedQuery.h:109
QueryResult & exec(const Out ¶mWrapper, const Rest &... rest)
Definition: EasyQtSql_PreparedQuery.h:147
QueryResult & exec(const In ¶mWrapper)
Definition: EasyQtSql_PreparedQuery.h:100
QueryResult & exec(const InOut ¶mWrapper)
Definition: EasyQtSql_PreparedQuery.h:118
QueryResult & exec(const InOut ¶mWrapper, const Rest &... rest)
Definition: EasyQtSql_PreparedQuery.h:158
QueryResult & exec()
Definition: EasyQtSql_PreparedQuery.h:73
QSqlQuery wrapper with handy data fetch methods.
Definition: EasyQtSql_QueryResult.h:39
QueryResult & exec(const QVariant &bindValue, const Rest &... rest)
Definition: EasyQtSql_PreparedQuery.h:127
Base parameters wrapper struct.
Definition: EasyQtSql_ParamDirectionWrapper.h:40
Output SQL parameters wrapper.
Definition: EasyQtSql_ParamDirectionWrapper.h:76
Bidirectional SQL parameters wrapper.
Definition: EasyQtSql_ParamDirectionWrapper.h:91
QueryResult & exec(const In ¶mWrapper, const Rest &... rest)
Definition: EasyQtSql_PreparedQuery.h:136
QueryResult & exec(const QVariant &bindValue)
Definition: EasyQtSql_PreparedQuery.h:93
Exception class for SQL errors handling.
Definition: EasyQtSql_DBException.h:38
const QVariant value
Definition: EasyQtSql_ParamDirectionWrapper.h:49