QtSql/qsql_odbc.h Source File

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:
85  QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p);
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:
110  QODBCPrivate *d;
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;
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();
150  QODBCDriverPrivate* d;
151  friend class QODBCPrivate;
152 };
153 
155 
157 
158 #endif // QSQL_ODBC_H
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const
#define QT_END_NAMESPACE
Definition: qglobal.h:128
virtual QStringList tables(QSql::TableType tableType) const
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
bool fetchFirst()
bool nextResult()
QODBCResult(const QODBCDriver *db, QODBCDriverPrivate *p)
bool fetchNext()
virtual QString formatValue(const QSqlField &field, bool trimStrings=false) const
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual bool hasFeature(DriverFeature f) const =0
bool reset(const QString &query)
virtual void close()=0
bool fetchPrevious()
#define Q_EXPORT_SQLDRIVER_ODBC
Definition: qsql_odbc.h:55
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
bool isNull(int field)
QVariant data(int field)
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual bool rollbackTransaction()
virtual bool commitTransaction()
virtual bool open(const QString &db, const QString &user=QString(), const QString &password=QString(), const QString &host=QString(), int port=-1, const QString &connOpts=QString())=0
virtual void setForwardOnly(bool forward)
bool fetchLast()
virtual QSqlResult * createResult() const =0
GLfloat GLfloat p
Definition: GLee.h:5416
QSqlRecord record() const
QVariant handle() const
virtual QSqlRecord record(const QString &tableName) const
virtual QSqlIndex primaryIndex(const QString &tableName) const
bool prepare(const QString &query)
bool fetch(int i)
virtual QVariant handle() const
void virtual_hook(int id, void *data)
TableType
Definition: qsql.h:74
int numRowsAffected()
#define QT_END_HEADER
Definition: qglobal.h:142
virtual bool beginTransaction()
virtual ~QODBCResult()
GLclampf f
Definition: GLee.h:9303
virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const