TreeFrogFramework 2.10
Loading...
Searching...
No Matches
tsqlquery.h
Go to the documentation of this file.
1#pragma once
2#include <QtSql>
3#include <TGlobal>
4
5
6class T_CORE_EXPORT TSqlQuery : public QSqlQuery {
7public:
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 static QString formatValue(const QVariant &val, const QMetaType &type, int databaseId = 0);
33 static QString formatValue(const QVariant &val, const QMetaType &type, const QSqlDatabase &database);
34 static QString formatValue(const QVariant &val, const QMetaType &type, const QSqlDriver *driver);
35 static QString formatValue(const QVariant &val, const QSqlDriver *driver);
36 static QString formatValue(const QVariant &val, const QSqlDatabase &database) { return formatValue(val, database.driver()); }
37
38private:
39 QString _connectionName;
40 QVariantList _boundValues; // For prepared query
41};
42
43
44inline QVariant TSqlQuery::getNextValue()
45{
46 return (next()) ? record().value(0) : QVariant();
47}
48
49
51{
52 return QSqlQuery::numRowsAffected();
53}
54
55
56inline int TSqlQuery::size() const
57{
58 return QSqlQuery::size();
59}
60
61
62inline bool TSqlQuery::next()
63{
64 return QSqlQuery::next();
65}
66
67
68inline QVariant TSqlQuery::value(int index) const
69{
70 return QSqlQuery::value(index);
71}
72
73
74inline QVariant TSqlQuery::value(const QString &name) const
75{
76 return QSqlQuery::value(name);
77}
78
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:68
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:50
QVariant getNextValue()
Returns the value of first field in the next object and advances the internal iterator by one positio...
Definition tsqlquery.h:44
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:56
static QString formatValue(const QVariant &val, const QSqlDatabase &database)
Definition tsqlquery.h:36
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
Definition tsqlquery.h:62
#define T_CORE_EXPORT
Definition tdeclexport.h:28