~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/sql/kernel/qsqlerror.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the sql module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
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
****************************************************************************/
 
28
 
 
29
#include "qsqlerror.h"
 
30
#include "qdebug.h"
 
31
 
 
32
#ifndef QT_NO_DEBUG_STREAM
 
33
QDebug operator<<(QDebug dbg, const QSqlError &s)
 
34
{
 
35
    dbg.nospace() << "QSqlError(" << s.number() << ", \"" << s.driverText() <<
 
36
                     "\", \"" << s.databaseText() << "\")";
 
37
    return dbg.space();
 
38
}
 
39
#endif
 
40
 
 
41
/*!
 
42
    \class QSqlError
 
43
    \brief The QSqlError class provides SQL database error information.
 
44
 
 
45
    \ingroup database
 
46
    \module sql
 
47
 
 
48
    A QSqlError object can provide database-specific error data,
 
49
    including the driverText() and databaseText() messages (or both
 
50
    concatenated together as text()), and the error number() and
 
51
    type(). The functions all have setters so that you can create and
 
52
    return QSqlError objects from your own classes, for example from
 
53
    your own SQL drivers.
 
54
 
 
55
    \sa QSqlDatabase::lastError(), QSqlQuery::lastError()
 
56
*/
 
57
 
 
58
/*!
 
59
    \enum QSqlError::ErrorType
 
60
 
 
61
    This enum type describes the type of SQL error that occurred.
 
62
 
 
63
    \value NoError  No error occurred.
 
64
    \value ConnectionError  Connection error.
 
65
    \value StatementError  SQL statement syntax error.
 
66
    \value TransactionError  Transaction failed error.
 
67
    \value UnknownError  Unknown error.
 
68
 
 
69
    \omitvalue None
 
70
    \omitvalue Connection
 
71
    \omitvalue Statement
 
72
    \omitvalue Transaction
 
73
    \omitvalue Unknown
 
74
*/
 
75
 
 
76
/*!
 
77
    Constructs an error containing the driver error text \a
 
78
    driverText, the database-specific error text \a databaseText, the
 
79
    type \a type and the optional error number \a number.
 
80
*/
 
81
 
 
82
QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,
 
83
                    int number)
 
84
    : driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number)
 
85
{
 
86
}
 
87
 
 
88
/*!
 
89
    Creates a copy of \a other.
 
90
*/
 
91
QSqlError::QSqlError(const QSqlError& other)
 
92
    : driverError(other.driverError), databaseError(other.databaseError),
 
93
      errorType(other.errorType),
 
94
      errorNumber(other.errorNumber)
 
95
{
 
96
}
 
97
 
 
98
/*!
 
99
    Assigns the \a other error's values to this error.
 
100
*/
 
101
 
 
102
QSqlError& QSqlError::operator=(const QSqlError& other)
 
103
{
 
104
    driverError = other.driverError;
 
105
    databaseError = other.databaseError;
 
106
    errorType = other.errorType;
 
107
    errorNumber = other.errorNumber;
 
108
    return *this;
 
109
}
 
110
 
 
111
/*!
 
112
    Destroys the object and frees any allocated resources.
 
113
*/
 
114
 
 
115
QSqlError::~QSqlError()
 
116
{
 
117
}
 
118
 
 
119
/*!
 
120
    Returns the text of the error as reported by the driver. This may
 
121
    contain database-specific descriptions. It may also be empty.
 
122
 
 
123
    \sa setDriverText() databaseText() text()
 
124
*/
 
125
QString QSqlError::driverText() const
 
126
{
 
127
    return driverError;
 
128
}
 
129
 
 
130
/*!
 
131
    Sets the driver error text to the value of \a driverText.
 
132
 
 
133
    \sa driverText() setDatabaseText() text()
 
134
*/
 
135
 
 
136
void QSqlError::setDriverText(const QString& driverText)
 
137
{
 
138
    driverError = driverText;
 
139
}
 
140
 
 
141
/*!
 
142
    Returns the text of the error as reported by the database. This
 
143
    may contain database-specific descriptions; it may be empty.
 
144
 
 
145
    \sa setDatabaseText() driverText() text()
 
146
*/
 
147
 
 
148
QString QSqlError::databaseText() const
 
149
{
 
150
    return databaseError;
 
151
}
 
152
 
 
153
/*!
 
154
    Sets the database error text to the value of \a databaseText.
 
155
 
 
156
    \sa databaseText() setDriverText() text()
 
157
*/
 
158
 
 
159
void QSqlError::setDatabaseText(const QString& databaseText)
 
160
{
 
161
    databaseError = databaseText;
 
162
}
 
163
 
 
164
/*!
 
165
    Returns the error type, or -1 if the type cannot be determined.
 
166
 
 
167
    \sa setType()
 
168
*/
 
169
 
 
170
QSqlError::ErrorType QSqlError::type() const
 
171
{
 
172
    return errorType;
 
173
}
 
174
 
 
175
/*!
 
176
    Sets the error type to the value of \a type.
 
177
 
 
178
    \sa type()
 
179
*/
 
180
 
 
181
void QSqlError::setType(ErrorType type)
 
182
{
 
183
    errorType = type;
 
184
}
 
185
 
 
186
/*!
 
187
    Returns the database-specific error number, or -1 if it cannot be
 
188
    determined.
 
189
 
 
190
    \sa setNumber()
 
191
*/
 
192
 
 
193
int QSqlError::number() const
 
194
{
 
195
    return errorNumber;
 
196
}
 
197
 
 
198
/*!
 
199
    Sets the database-specific error number to \a number.
 
200
 
 
201
    \sa number()
 
202
*/
 
203
 
 
204
void QSqlError::setNumber(int number)
 
205
{
 
206
    errorNumber = number;
 
207
}
 
208
 
 
209
/*!
 
210
    This is a convenience function that returns databaseText() and
 
211
    driverText() concatenated into a single string.
 
212
 
 
213
    \sa driverText() databaseText()
 
214
*/
 
215
 
 
216
QString QSqlError::text() const
 
217
{
 
218
    QString result = databaseError;
 
219
    if (!databaseError.endsWith(QLatin1String("\n")))
 
220
        result += QLatin1Char(' ');
 
221
    result += driverError;
 
222
    return result;
 
223
}