[196] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Implementation of QSqlError 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 | #include "qsqlerror.h"
|
---|
| 38 | #include <qmessagebox.h>
|
---|
| 39 |
|
---|
| 40 | #ifndef QT_NO_SQL
|
---|
| 41 |
|
---|
| 42 | /*!
|
---|
| 43 | \class QSqlError qsqlerror.h
|
---|
| 44 | \brief The QSqlError class provides SQL database error information.
|
---|
| 45 |
|
---|
| 46 | \ingroup database
|
---|
| 47 | \module sql
|
---|
| 48 |
|
---|
| 49 | This class is used to report database-specific errors. An error
|
---|
| 50 | description and (if appropriate) a database-specific error number
|
---|
| 51 | can be obtained using this class.
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | /*!
|
---|
| 55 | \enum QSqlError::Type
|
---|
| 56 |
|
---|
| 57 | This enum type describes the type of SQL error that occurred.
|
---|
| 58 |
|
---|
| 59 | \value None no error occurred
|
---|
| 60 | \value Connection connection error
|
---|
| 61 | \value Statement SQL statement syntax error
|
---|
| 62 | \value Transaction transaction failed error
|
---|
| 63 | \value Unknown unknown error
|
---|
| 64 | */
|
---|
| 65 |
|
---|
| 66 | /*!
|
---|
| 67 | Constructs an error containing the driver error text \a
|
---|
| 68 | driverText, the database-specific error text \a databaseText, the
|
---|
| 69 | type \a type and the optional error number \a number.
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | QSqlError::QSqlError( const QString& driverText,
|
---|
| 73 | const QString& databaseText,
|
---|
| 74 | int type,
|
---|
| 75 | int number )
|
---|
| 76 | : driverError(driverText),
|
---|
| 77 | databaseError(databaseText),
|
---|
| 78 | errorType(type),
|
---|
| 79 | errorNumber(number)
|
---|
| 80 | {
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /*!
|
---|
| 84 | Creates a copy of \a other.
|
---|
| 85 | */
|
---|
| 86 |
|
---|
| 87 | QSqlError::QSqlError( const QSqlError& other )
|
---|
| 88 | : driverError(other.driverError),
|
---|
| 89 | databaseError(other.databaseError),
|
---|
| 90 | errorType(other.errorType),
|
---|
| 91 | errorNumber(other.errorNumber)
|
---|
| 92 | {
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /*!
|
---|
| 96 | Sets the error equal to \a other.
|
---|
| 97 | */
|
---|
| 98 |
|
---|
| 99 | QSqlError& QSqlError::operator=( const QSqlError& other )
|
---|
| 100 | {
|
---|
| 101 | driverError = other.driverError;
|
---|
| 102 | databaseError = other.databaseError;
|
---|
| 103 | errorType = other.errorType;
|
---|
| 104 | errorNumber = other.errorNumber;
|
---|
| 105 | return *this;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /*!
|
---|
| 109 | Destroys the object and frees any allocated resources.
|
---|
| 110 | */
|
---|
| 111 |
|
---|
| 112 | QSqlError::~QSqlError()
|
---|
| 113 | {
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /*!
|
---|
| 117 | Returns the text of the error as reported by the driver. This may
|
---|
| 118 | contain database-specific descriptions.
|
---|
| 119 | */
|
---|
| 120 | QString QSqlError::driverText() const
|
---|
| 121 | {
|
---|
| 122 | return driverError;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /*!
|
---|
| 126 | Sets the driver error text to the value of \a driverText.
|
---|
| 127 | */
|
---|
| 128 |
|
---|
| 129 | void QSqlError::setDriverText( const QString& driverText )
|
---|
| 130 | {
|
---|
| 131 | driverError = driverText;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /*!
|
---|
| 135 | Returns the text of the error as reported by the database. This
|
---|
| 136 | may contain database-specific descriptions.
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | QString QSqlError::databaseText() const
|
---|
| 140 | {
|
---|
| 141 | return databaseError;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /*!
|
---|
| 145 | Sets the database error text to the value of \a databaseText.
|
---|
| 146 | */
|
---|
| 147 |
|
---|
| 148 | void QSqlError::setDatabaseText( const QString& databaseText )
|
---|
| 149 | {
|
---|
| 150 | databaseError = databaseText;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | /*!
|
---|
| 154 | Returns the error type, or -1 if the type cannot be determined.
|
---|
| 155 |
|
---|
| 156 | \sa QSqlError::Type.
|
---|
| 157 | */
|
---|
| 158 |
|
---|
| 159 | int QSqlError::type() const
|
---|
| 160 | {
|
---|
| 161 | return errorType;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | /*!
|
---|
| 165 | Sets the error type to the value of \a type.
|
---|
| 166 | */
|
---|
| 167 |
|
---|
| 168 | void QSqlError::setType( int type )
|
---|
| 169 | {
|
---|
| 170 | errorType = type;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /*!
|
---|
| 174 | Returns the database-specific error number, or -1 if it cannot be
|
---|
| 175 | determined.
|
---|
| 176 | */
|
---|
| 177 |
|
---|
| 178 | int QSqlError::number() const
|
---|
| 179 | {
|
---|
| 180 | return errorNumber;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | /*!
|
---|
| 184 | Sets the database-specific error number to \a number.
|
---|
| 185 | */
|
---|
| 186 |
|
---|
| 187 | void QSqlError::setNumber( int number )
|
---|
| 188 | {
|
---|
| 189 | errorNumber = number;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*!
|
---|
| 193 | This is a convenience function that returns databaseText() and
|
---|
| 194 | driverText() concatenated into a single string.
|
---|
| 195 |
|
---|
| 196 | \sa showMessage(), driverText(), databaseText()
|
---|
| 197 | */
|
---|
| 198 |
|
---|
| 199 | QString QSqlError::text() const
|
---|
| 200 | {
|
---|
| 201 | if ( databaseError.endsWith("\n") )
|
---|
| 202 | return databaseError + driverError;
|
---|
| 203 | else
|
---|
| 204 | return databaseError + " " + driverError;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /*!
|
---|
| 208 | \obsolete
|
---|
| 209 |
|
---|
| 210 | This is a convenience function that pops up a QMessageBox
|
---|
| 211 | containing the message returned by text(). An additional string
|
---|
| 212 | can be passed in via the \a msg parameter, which will be
|
---|
| 213 | concatenated with the text() message.
|
---|
| 214 |
|
---|
| 215 | \sa text(), driverText(), databaseText()
|
---|
| 216 | */
|
---|
| 217 | void QSqlError::showMessage( const QString& msg ) const
|
---|
| 218 | {
|
---|
| 219 | #ifndef QT_NO_MESSAGEBOX
|
---|
| 220 | QMessageBox::warning( NULL, "SQL Error", msg + text(),
|
---|
| 221 | QMessageBox::Ok, QMessageBox::NoButton );
|
---|
| 222 | #endif // QT_NO_MESSAGEBOX
|
---|
| 223 | }
|
---|
| 224 | #endif // QT_NO_SQL
|
---|