source: trunk/src/sql/kernel/qsqlerror.cpp@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtSql module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qsqlerror.h"
43#include "qdebug.h"
44
45QT_BEGIN_NAMESPACE
46
47#ifndef QT_NO_DEBUG_STREAM
48QDebug operator<<(QDebug dbg, const QSqlError &s)
49{
50 dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
51 ", " << s.databaseText() << ')';
52 return dbg.space();
53}
54#endif
55
56/*!
57 \class QSqlError
58 \brief The QSqlError class provides SQL database error information.
59
60 \ingroup database
61 \inmodule QtSql
62
63 A QSqlError object can provide database-specific error data,
64 including the driverText() and databaseText() messages (or both
65 concatenated together as text()), and the error number() and
66 type(). The functions all have setters so that you can create and
67 return QSqlError objects from your own classes, for example from
68 your own SQL drivers.
69
70 \sa QSqlDatabase::lastError(), QSqlQuery::lastError()
71*/
72
73/*!
74 \enum QSqlError::ErrorType
75
76 This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.
77
78 \value NoError No error occurred.
79 \value ConnectionError Connection error.
80 \value StatementError SQL statement syntax error.
81 \value TransactionError Transaction failed error.
82 \value UnknownError Unknown error.
83
84 \omitvalue None
85 \omitvalue Connection
86 \omitvalue Statement
87 \omitvalue Transaction
88 \omitvalue Unknown
89*/
90
91/*!
92 Constructs an error containing the driver error text \a
93 driverText, the database-specific error text \a databaseText, the
94 type \a type and the optional error number \a number.
95*/
96
97QSqlError::QSqlError(const QString& driverText, const QString& databaseText, ErrorType type,
98 int number)
99 : driverError(driverText), databaseError(databaseText), errorType(type), errorNumber(number)
100{
101}
102
103/*!
104 Creates a copy of \a other.
105*/
106QSqlError::QSqlError(const QSqlError& other)
107 : driverError(other.driverError), databaseError(other.databaseError),
108 errorType(other.errorType),
109 errorNumber(other.errorNumber)
110{
111}
112
113/*!
114 Assigns the \a other error's values to this error.
115*/
116
117QSqlError& QSqlError::operator=(const QSqlError& other)
118{
119 driverError = other.driverError;
120 databaseError = other.databaseError;
121 errorType = other.errorType;
122 errorNumber = other.errorNumber;
123 return *this;
124}
125
126/*!
127 Destroys the object and frees any allocated resources.
128*/
129
130QSqlError::~QSqlError()
131{
132}
133
134/*!
135 Returns the text of the error as reported by the driver. This may
136 contain database-specific descriptions. It may also be empty.
137
138 \sa setDriverText() databaseText() text()
139*/
140QString QSqlError::driverText() const
141{
142 return driverError;
143}
144
145/*!
146 Sets the driver error text to the value of \a driverText.
147
148 \sa driverText() setDatabaseText() text()
149*/
150
151void QSqlError::setDriverText(const QString& driverText)
152{
153 driverError = driverText;
154}
155
156/*!
157 Returns the text of the error as reported by the database. This
158 may contain database-specific descriptions; it may be empty.
159
160 \sa setDatabaseText() driverText() text()
161*/
162
163QString QSqlError::databaseText() const
164{
165 return databaseError;
166}
167
168/*!
169 Sets the database error text to the value of \a databaseText.
170
171 \sa databaseText() setDriverText() text()
172*/