source: trunk/include/qsqlquery.h

Last change on this file was 196, checked in by rudi, 14 years ago

Add SQL module (currently it isn't build by default, however it's needed for QtDesigner)

File size: 4.2 KB
Line 
1/****************************************************************************
2**
3** Definition of QSqlQuery class
4**
5** Created : 2000-11-03
6**
7** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
8**
9** This file is part of the sql module of the Qt GUI Toolkit.
10**
11** This file may be distributed under the terms of the Q Public License
12** as defined by Trolltech ASA of Norway and appearing in the file
13** LICENSE.QPL included in the packaging of this file.
14**
15** This file may be distributed and/or modified under the terms of the
16** GNU General Public License version 2 as published by the Free Software
17** Foundation and appearing in the file LICENSE.GPL included in the
18** packaging of this file.
19**
20** Licensees holding valid Qt Enterprise Edition licenses may use this
21** file in accordance with the Qt Commercial License Agreement provided
22** with the Software.
23**
24** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26**
27** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
28** information about Qt Commercial License Agreements.
29** See http://www.trolltech.com/qpl/ for QPL licensing information.
30** See http://www.trolltech.com/gpl/ for GPL licensing information.
31**
32** Contact info@trolltech.com if any conditions of this licensing are
33** not clear to you.
34**
35**********************************************************************/
36
37#ifndef QSQLQUERY_H
38#define QSQLQUERY_H
39
40#ifndef QT_H
41#include "qobject.h"
42#include "qstring.h"
43#include "qvariant.h"
44#include "qvaluelist.h"
45#include "qsqlerror.h"
46#include "qsqlfield.h"
47#include "qsql.h"
48#endif // QT_H
49
50#ifndef QT_NO_SQL
51
52class QSqlDriver;
53class QSqlResult;
54class QSqlDatabase;
55
56class Q_EXPORT QSqlResultShared : public QObject, public QShared
57{
58 Q_OBJECT
59public:
60 QSqlResultShared( QSqlResult* result );
61 virtual ~QSqlResultShared();
62 QSqlResult* sqlResult;
63 QString executedQuery;
64private slots:
65 void slotResultDestroyed();
66};
67
68class Q_EXPORT QSqlQuery
69{
70public:
71 QSqlQuery( QSqlResult * r );
72 QSqlQuery( const QString& query = QString::null, QSqlDatabase* db = 0 );
73 Q_EXPLICIT QSqlQuery( QSqlDatabase* db );
74 QSqlQuery( const QSqlQuery& other );
75 QSqlQuery& operator=( const QSqlQuery& other );
76 virtual ~QSqlQuery();
77
78 bool isValid() const;
79 bool isActive() const;
80 bool isNull( int field ) const;
81 int at() const;
82 QString lastQuery() const;
83 int numRowsAffected() const;
84 QSqlError lastError() const;
85 bool isSelect() const;
86 int size() const;
87 const QSqlDriver* driver() const;
88 const QSqlResult* result() const;
89 bool isForwardOnly() const;
90 void setForwardOnly( bool forward );
91
92 virtual bool exec ( const QString& query );
93 virtual QVariant value( int i ) const;
94
95 virtual bool seek( int i, bool relative = FALSE );
96 virtual bool next();
97 virtual bool prev();
98 virtual bool first();
99 virtual bool last();
100
101 // prepared query support
102 bool exec();
103 bool prepare( const QString& query );
104 void bindValue( const QString& placeholder, const QVariant& val );
105 void bindValue( int pos, const QVariant& val );
106 void addBindValue( const QVariant& val );
107 // remove these overloads in 4.0
108 void bindValue( const QString& placeholder, const QVariant& val, QSql::ParameterType type );
109 void bindValue( int pos, const QVariant& val, QSql::ParameterType type );
110 void addBindValue( const QVariant& val, QSql::ParameterType type );
111 QVariant boundValue( const QString& placeholder ) const;
112 QVariant boundValue( int pos ) const;
113 QMap<QString, QVariant> boundValues() const;
114 QString executedQuery() const;
115
116protected:
117 virtual void beforeSeek();
118 virtual void afterSeek();
119
120private:
121 void init( const QString& query, QSqlDatabase* db );
122 void deref();
123 bool checkDetach();
124 QSqlResultShared* d;
125};
126
127
128#endif // QT_NO_SQL
129#endif
Note: See TracBrowser for help on using the repository browser.