Qt 4.8
qsql_odbc.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSQL_ODBC_H
43 #define QSQL_ODBC_H
44 
45 #include <QtSql/qsqldriver.h>
46 #include <QtSql/qsqlresult.h>
47 
48 #if defined (Q_OS_WIN32)
49 #include <QtCore/qt_windows.h>
50 #endif
51 
52 #ifdef QT_PLUGIN
53 #define Q_EXPORT_SQLDRIVER_ODBC
54 #else
55 #define Q_EXPORT_SQLDRIVER_ODBC Q_SQL_EXPORT
56 #endif
57 
58 #ifdef Q_OS_UNIX
59 #define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs
60 #endif
61 
62 #if defined(Q_CC_BOR)
63 // workaround for Borland to make sure that SQLBIGINT is defined
64 # define _MSC_VER 900
65 #endif
66 #include <sql.h>
67 #if defined(Q_CC_BOR)
68 # undef _MSC_VER
69 #endif
70 
71 #include <sqlext.h>
72 
74 
76 
77 class QODBCPrivate;
78 class QODBCDriverPrivate;
79 class QODBCDriver;
80 class QSqlRecordInfo;
81 
82 class QODBCResult : public QSqlResult
83 {
84 public:
86  virtual ~QODBCResult();
87 
88  bool prepare(const QString& query);
89  bool exec();
90 
91  QVariant handle() const;
92  virtual void setForwardOnly(bool forward);
93 
94 protected:
95  bool fetchNext();
96  bool fetchFirst();
97  bool fetchLast();
98  bool fetchPrevious();
99  bool fetch(int i);
100  bool reset (const QString& query);
101  QVariant data(int field);
102  bool isNull(int field);
103  int size();
104  int numRowsAffected();
105  QSqlRecord record() const;
106  void virtual_hook(int id, void *data);
107  bool nextResult();
108 
109 private:
111 };
112 
114 {
115  Q_OBJECT
116 public:
117  explicit QODBCDriver(QObject *parent=0);
118  QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent=0);
119  virtual ~QODBCDriver();
120  bool hasFeature(DriverFeature f) const;
121  void close();
122  QSqlResult *createResult() const;
123  QStringList tables(QSql::TableType) const;
124  QSqlRecord record(const QString& tablename) const;
125  QSqlIndex primaryIndex(const QString& tablename) const;
126  QVariant handle() const;
127  QString formatValue(const QSqlField &field,
128  bool trimStrings) const;
129  bool open(const QString& db,
130  const QString& user,
131  const QString& password,
132  const QString& host,
133  int port,
134  const QString& connOpts);
135 
136  QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
137 
138 protected Q_SLOTS:
139  bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
140 
141 protected:
142  bool beginTransaction();
143  bool commitTransaction();
144  bool rollbackTransaction();
145 
146 private:
147  void init();
148  bool endTrans();
149  void cleanup();
151  friend class QODBCPrivate;
152 };
153 
155 
157 
158 #endif // QSQL_ODBC_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
Definition: qsql_odbc.cpp:1241
bool nextResult()
Definition: qsql_odbc.cpp:1679
bool fetchPrevious()
Positions the result to the previous record (row) in the result.
Definition: qsql_odbc.cpp:1070
int type
Definition: qmetatype.cpp:239
bool fetchNext()
Positions the result to the next available record (row) in the result.
Definition: qsql_odbc.cpp:1026
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QODBCPrivate * d
Definition: qsql_odbc.h:110
DriverFeature
This enum contains a list of features a driver might support.
Definition: qsqldriver.h:75
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
Definition: qsql_odbc.cpp:1246
bool fetchLast()
Positions the result to the last record (last row) in the result.
Definition: qsql_odbc.cpp:1089
QVariant data(int field)
Returns the data for field index in the current row as a QVariant.
Definition: qsql_odbc.cpp:1128
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
Definition: qsqldriver.h:68
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool fetchFirst()
Positions the result to the first record (row 0) in the result.
Definition: qsql_odbc.cpp:1048
virtual void setForwardOnly(bool forward)
Sets forward only mode to forward.
Definition: qsql_odbc.cpp:1734
#define Q_EXPORT_SQLDRIVER_ODBC
Definition: qsql_odbc.h:55
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool fetch(int i)
Positions the result to an arbitrary (zero-based) row index.
Definition: qsql_odbc.cpp:990
static bool init
void virtual_hook(int id, void *data)
Definition: qsql_odbc.cpp:1718
bool isNull(int field)
Returns true if the field at position index in the current row is null; otherwise returns false...
Definition: qsql_odbc.cpp:1228
QODBCDriverPrivate * d
Definition: qsql_odbc.h:150
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
TableType
Definition: qsql.h:74
virtual ~QODBCResult()
Definition: qsql_odbc.cpp:895
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
Definition: qsql_odbc.cpp:1257
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
static void cleanup()
Definition: qpicture.cpp:1508
QODBCResult(const QODBCDriver *db, QODBCDriverPrivate *p)
Definition: qsql_odbc.cpp:889
bool exec()
Executes the query, returning true if successful; otherwise returns false.
Definition: qsql_odbc.cpp:1318
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
Definition: qsql_odbc.cpp:1667
#define QT_END_HEADER
Definition: qglobal.h:137
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
Definition: qsqlresult.h:63
QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
Definition: qsql_odbc.cpp:1674
IdentifierType
This enum contains a list of SQL identifier types.
Definition: qsqldriver.h:83
bool reset(const QString &query)
Sets the result to use the SQL statement query for subsequent data retrieval.
Definition: qsql_odbc.cpp:907
int open(const char *, int,...)