QSqlError: Mark deprecated functiond with QT_DEPRECATED
And move the default argument from the deprecated constructor to the new one Also make sure that the error number is consistent across the two constructor Change-Id: I3721266b39ab493f0add35b2d1f892b2f6094992 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
c0825cbfc0
commit
89ecac4607
@ -107,7 +107,8 @@ QSqlError::QSqlError(const QString& driverText, const QString& databaseText, Err
|
||||
d->driverError = driverText;
|
||||
d->databaseError = databaseText;
|
||||
d->errorType = type;
|
||||
d->errorCode = QString::number(number);
|
||||
if (number != -1)
|
||||
d->errorCode = QString::number(number);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -287,7 +288,7 @@ void QSqlError::setType(ErrorType type)
|
||||
#if QT_DEPRECATED_SINCE(5, 3)
|
||||
int QSqlError::number() const
|
||||
{
|
||||
return d->errorCode.toInt();
|
||||
return d->errorCode.isEmpty() ? -1 : d->errorCode.toInt();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -60,15 +60,13 @@ public:
|
||||
UnknownError
|
||||
};
|
||||
#if QT_DEPRECATED_SINCE(5, 3)
|
||||
QSqlError( const QString& driverText = QString(),
|
||||
const QString& databaseText = QString(),
|
||||
ErrorType type = NoError,
|
||||
int number = -1);
|
||||
QT_DEPRECATED QSqlError(const QString &driverText, const QString &databaseText,
|
||||
ErrorType type, int number);
|
||||
#endif
|
||||
QSqlError(const QString &driverText,
|
||||
const QString &databaseText,
|
||||
ErrorType type,
|
||||
const QString &errorCode);
|
||||
QSqlError(const QString &driverText = QString(),
|
||||
const QString &databaseText = QString(),
|
||||
ErrorType type = NoError,
|
||||
const QString &errorCode = QString());
|
||||
QSqlError(const QSqlError& other);
|
||||
QSqlError& operator=(const QSqlError& other);
|
||||
bool operator==(const QSqlError& other) const;
|
||||
@ -79,7 +77,7 @@ public:
|
||||
QString databaseText() const;
|
||||
ErrorType type() const;
|
||||
#if QT_DEPRECATED_SINCE(5, 3)
|
||||
int number() const;
|
||||
QT_DEPRECATED int number() const;
|
||||
#endif
|
||||
QString nativeErrorCode() const;
|
||||
QString text() const;
|
||||
|
@ -102,6 +102,7 @@ void tst_QSqlError::construction()
|
||||
QCOMPARE(obj1.databaseText(), QString("databasetext"));
|
||||
QCOMPARE(obj1.type(), QSqlError::UnknownError);
|
||||
QCOMPARE(obj1.number(), 123);
|
||||
QCOMPARE(obj1.nativeErrorCode(), QStringLiteral("123"));
|
||||
QVERIFY(obj1.isValid());
|
||||
|
||||
QSqlError obj2(obj1);
|
||||
@ -109,6 +110,7 @@ void tst_QSqlError::construction()
|
||||
QCOMPARE(obj2.databaseText(), obj1.databaseText());
|
||||
QCOMPARE(obj2.type(), obj1.type());
|
||||
QCOMPARE(obj2.number(), obj1.number());
|
||||
QCOMPARE(obj2.nativeErrorCode(), obj1.nativeErrorCode());
|
||||
QVERIFY(obj2.isValid());
|
||||
|
||||
QSqlError obj3 = obj2;
|
||||
@ -116,10 +118,16 @@ void tst_QSqlError::construction()
|
||||
QCOMPARE(obj3.databaseText(), obj2.databaseText());
|
||||
QCOMPARE(obj3.type(), obj2.type());
|
||||
QCOMPARE(obj3.number(), obj2.number());
|
||||
QCOMPARE(obj3.nativeErrorCode(), obj2.nativeErrorCode());
|
||||
QVERIFY(obj3.isValid());
|
||||
|
||||
QSqlError obj4;
|
||||
QVERIFY(!obj4.isValid());
|
||||
QCOMPARE(obj4.driverText(), QString());
|
||||
QCOMPARE(obj4.databaseText(), QString());
|
||||
QCOMPARE(obj4.type(), QSqlError::NoError);
|
||||
QCOMPARE(obj4.number(), -1);
|
||||
QCOMPARE(obj4.nativeErrorCode(), QString());
|
||||
|
||||
QSqlError obj5(QStringLiteral("drivertext"), QStringLiteral("databasetext"),
|
||||
QSqlError::UnknownError, QStringLiteral("123"));
|
||||
@ -138,6 +146,16 @@ void tst_QSqlError::construction()
|
||||
QCOMPARE(obj6.number(), 0);
|
||||
QCOMPARE(obj6.nativeErrorCode(), QStringLiteral("Err123"));
|
||||
QVERIFY(obj6.isValid());
|
||||
|
||||
// Default constructed object as constructed before Qt 5.3
|
||||
QSqlError obj7(QString(), QString(), QSqlError::NoError, -1);
|
||||
QVERIFY(!obj7.isValid());
|
||||
QCOMPARE(obj7.driverText(), QString());
|
||||
QCOMPARE(obj7.databaseText(), QString());
|
||||
QCOMPARE(obj7.type(), QSqlError::NoError);
|
||||
QCOMPARE(obj7.number(), -1);
|
||||
QCOMPARE(obj7.nativeErrorCode(), QString());
|
||||
|
||||
}
|
||||
|
||||
void tst_QSqlError::operators()
|
||||
|
Loading…
Reference in New Issue
Block a user