QSql/QSqlite: return extended error codes by default

SQlite allows to return fine-granulated error codes but this behavior is
not enabled by default (due to backwards compatibility concerns).
Enable them for the SQLite driver by default but provide an option to
disable them when needed.

[ChangeLog][QtSql][QSQLITE] The plugin now returns the extended error
codes by default.

Change-Id: I59cec9aea46eb03f1e7ca02903d769c003a1ae30
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Christian Ehrlicher 2021-01-10 20:14:53 +01:00
parent ce90248882
commit f8f629cc13
2 changed files with 5 additions and 0 deletions

View File

@ -721,6 +721,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c
bool sharedCache = false;
bool openReadOnlyOption = false;
bool openUriOption = false;
bool useExtendedResultCodes = true;
#if QT_CONFIG(regularexpression)
static const QLatin1String regexpConnectOption = QLatin1String("QSQLITE_ENABLE_REGEXP");
bool defineRegexp = false;
@ -744,6 +745,8 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c
openUriOption = true;
} else if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE")) {
sharedCache = true;
} else if (option == QLatin1String("QSQLITE_NO_USE_EXTENDED_RESULT_CODES")) {
useExtendedResultCodes = false;
}
#if QT_CONFIG(regularexpression)
else if (option.startsWith(regexpConnectOption)) {
@ -774,6 +777,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c
if (res == SQLITE_OK) {
sqlite3_busy_timeout(d->access, timeOut);
sqlite3_extended_result_codes(d->access, useExtendedResultCodes);
setOpen(true);
setOpenError(false);
#if QT_CONFIG(regularexpression)

View File

@ -1208,6 +1208,7 @@ QSqlRecord QSqlDatabase::record(const QString& tablename) const
\li QSQLITE_OPEN_URI
\li QSQLITE_ENABLE_SHARED_CACHE
\li QSQLITE_ENABLE_REGEXP
\li QSQLITE_NO_USE_EXTENDED_RESULT_CODES
\endlist
\li