TreeFrogFramework  2.8
tsqlquery.h
Go to the documentation of this file.
1 #pragma once
2 #include <QtSql>
3 #include <TGlobal>
4 
5 
6 class T_CORE_EXPORT TSqlQuery : public QSqlQuery {
7 public:
8  TSqlQuery(int databaseId = 0);
9  TSqlQuery(const QSqlDatabase &db);
10 
11  TSqlQuery &prepare(const QString &query);
12  bool load(const QString &filename);
13  bool loadPreparedQuery(const QString &filename) { return load(filename); }
14  TSqlQuery &bind(const QString &placeholder, const QVariant &val);
15  TSqlQuery &bind(int pos, const QVariant &val);
16  TSqlQuery &addBind(const QVariant &val);
17  QVariant boundValue(int pos) const;
18  QVariantList boundValues() const;
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  QVariant value(const QString &name) const;
28 
29  static void clearCachedQueries();
30  static QString escapeIdentifier(const QString &identifier, QSqlDriver::IdentifierType type = QSqlDriver::FieldName, int databaseId = 0);
31  static QString escapeIdentifier(const QString &identifier, QSqlDriver::IdentifierType type, const QSqlDriver *driver);
32 #if QT_VERSION < 0x060000
33  static QString formatValue(const QVariant &val, QVariant::Type type = QVariant::Invalid, int databaseId = 0);
34  static QString formatValue(const QVariant &val, QVariant::Type type, const QSqlDatabase &database);
35  static QString formatValue(const QVariant &val, QVariant::Type type, const QSqlDriver *driver);
36 #else
37  static QString formatValue(const QVariant &val, const QMetaType &type, int databaseId = 0);
38  static QString formatValue(const QVariant &val, const QMetaType &type, const QSqlDatabase &database);
39  static QString formatValue(const QVariant &val, const QMetaType &type, const QSqlDriver *driver);
40 #endif
41  static QString formatValue(const QVariant &val, const QSqlDriver *driver);
42  static QString formatValue(const QVariant &val, const QSqlDatabase &database) { return formatValue(val, database.driver()); }
43 
44 private:
45  QString _connectionName;
46  QVariantList _boundValues; // For prepared query
47 };
48 
49 
50 inline QVariant TSqlQuery::getNextValue()
51 {
52  return (next()) ? record().value(0) : QVariant();
53 }
54 
55 
56 inline int TSqlQuery::numRowsAffected() const
57 {
58  return QSqlQuery::numRowsAffected();
59 }
60 
61 
62 inline int TSqlQuery::size() const
63 {
64  return QSqlQuery::size();
65 }
66 
67 
68 inline bool TSqlQuery::next()
69 {
70  return QSqlQuery::next();
71 }
72 
73 
74 inline QVariant TSqlQuery::value(int index) const
75 {
76  return QSqlQuery::value(index);
77 }
78 
79 
80 inline QVariant TSqlQuery::value(const QString &name) const
81 {
82  return QSqlQuery::value(name);
83 }
84 
The TSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: tsqlquery.h:6
QVariant value(int index) const
Returns the value of field index in the current record.
Definition: tsqlquery.h:74
int numRowsAffected() const
Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.
Definition: tsqlquery.h:56
QVariant getNextValue()
Returns the value of first field in the next object and advances the internal iterator by one positio...
Definition: tsqlquery.h:50
bool loadPreparedQuery(const QString &filename)
Definition: tsqlquery.h:13
int size() const
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...
Definition: tsqlquery.h:62
static QString formatValue(const QVariant &val, const QSqlDatabase &database)
Definition: tsqlquery.h:42
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
Definition: tsqlquery.h:68
@ Type
Definition: tfnamespace.h:330
@ Invalid
Definition: tfnamespace.h:22
#define T_CORE_EXPORT
Definition: tdeclexport.h:28