TreeFrogFramework  1.18
tsqlquery.h
Go to the documentation of this file.
1 #ifndef TSQLQUERY_H
2 #define TSQLQUERY_H
3 
4 #include <QtSql>
5 #include <TGlobal>
6 
7 
8 class T_CORE_EXPORT TSqlQuery : public QSqlQuery
9 {
10 public:
11  TSqlQuery(int databaseId = 0);
12  TSqlQuery(QSqlDatabase db);
13 
14  TSqlQuery &prepare(const QString &query);
15  bool load(const QString &filename);
16  TSqlQuery &bind(const QString &placeholder, const QVariant &val);
17  TSqlQuery &bind(int pos, const QVariant &val);
18  TSqlQuery &addBind(const QVariant &val);
19  QVariant getNextValue();
20  QString queryDirPath() const;
21  bool exec(const QString &query);
22  bool exec();
23  int numRowsAffected() const;
24  int size() const;
25  bool next();
26  QVariant value(int index) const;
27 
28  static void clearCachedQueries();
29  static QString escapeIdentifier(const QString &identifier, QSqlDriver::IdentifierType type = QSqlDriver::FieldName, int databaseId = 0);
30  static QString escapeIdentifier(const QString &identifier, QSqlDriver::IdentifierType type, const QSqlDriver *driver);
31  static QString formatValue(const QVariant &val, QVariant::Type type = QVariant::Invalid, int databaseId = 0);
32  static QString formatValue(const QVariant &val, QVariant::Type type, const QSqlDatabase &database);
33  static QString formatValue(const QVariant &val, const QSqlDatabase &database);
34 };
35 
36 
40 inline TSqlQuery &TSqlQuery::prepare(const QString &query)
41 {
42  QSqlQuery::prepare(query);
43  return *this;
44 }
45 
50 inline TSqlQuery &TSqlQuery::bind(const QString &placeholder, const QVariant &val)
51 {
52  QSqlQuery::bindValue(placeholder, val);
53  return *this;
54 }
55 
60 inline TSqlQuery &TSqlQuery::bind(int pos, const QVariant &val)
61 {
62  QSqlQuery::bindValue(pos, val);
63  return *this;
64 }
65 
72 inline TSqlQuery &TSqlQuery::addBind(const QVariant &val)
73 {
74  QSqlQuery::addBindValue(val);
75  return *this;
76 }
77 
83 inline QVariant TSqlQuery::getNextValue()
84 {
85  return (next()) ? record().value(0) : QVariant();
86 }
87 
88 #endif // TSQLQUERY_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
Definition: tfnamespace.h:24
Definition: tfnamespace.h:295
The TSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: tsqlquery.h:8
TSqlQuery & addBind(const QVariant &val)
Adds the value val to the list of values when using positional value binding and returns the query ob...
Definition: tsqlquery.h:72
TSqlQuery & prepare(const QString &query)
Prepares the SQL query query for execution.
Definition: tsqlquery.h:40
TSqlQuery & bind(const QString &placeholder, const QVariant &val)
Set the placeholder placeholder to be bound to value val in the prepared statement.
Definition: tsqlquery.h:50
QVariant getNextValue()
Returns the value of first field in the next object and advances the internal iterator by one positio...
Definition: tsqlquery.h:83