Sqlite: Add extended exceptions for errors

Change-Id: I297bf7a82625198200b0e4ed260d81358d31c56c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2023-03-13 15:44:34 +01:00
parent 093584a10c
commit 37563679cc
4 changed files with 44 additions and 10 deletions

View File

@@ -318,11 +318,13 @@ void BaseStatement::checkForStepError(int resultCode) const
case SQLITE_BUSY:
throw StatementIsBusy(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_MISSING_COLLSEQ:
throw StatementHasErrorMissingCollatingSequence(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_RETRY:
throw StatementHasErrorRetry(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_SNAPSHOT:
throw StatementHasErrorSnapshot(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR:
throwStatementHasError("SqliteStatement::stepStatement: run-time error (such as a "
"constraint violation) has occurred!");
throw StatementHasError(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_MISUSE:
throwStatementIsMisused("SqliteStatement::stepStatement: was called inappropriately!");
case SQLITE_CONSTRAINT_CHECK:
@@ -469,11 +471,13 @@ void BaseStatement::checkForPrepareError(int resultCode) const
case SQLITE_BUSY:
throw StatementIsBusy(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_MISSING_COLLSEQ:
throw StatementHasErrorMissingCollatingSequence(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_RETRY:
throw StatementHasErrorRetry(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR_SNAPSHOT:
throw StatementHasErrorSnapshot(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_ERROR:
throwStatementHasError("SqliteStatement::prepareStatement: run-time error (such as a "
"constraint violation) has occurred!");
throw StatementHasError(sqlite3_errmsg(sqliteDatabaseHandle()));
case SQLITE_MISUSE:
throwStatementIsMisused("SqliteStatement::prepareStatement: was called inappropriately!");
case SQLITE_IOERR_READ:
@@ -578,11 +582,6 @@ bool BaseStatement::isReadOnlyStatement() const
return sqlite3_stmt_readonly(m_compiledStatement.get());
}
void BaseStatement::throwStatementHasError(const char *) const
{
throw StatementHasError(sqlite3_errmsg(sqliteDatabaseHandle()));
}
void BaseStatement::throwStatementIsMisused(const char *) const
{
throw StatementIsMisused(sqlite3_errmsg(sqliteDatabaseHandle()));

View File

@@ -117,7 +117,6 @@ public:
void checkBindingParameterCount(int bindingParameterCount) const;
void checkColumnCount(int columnCount) const;
bool isReadOnlyStatement() const;
[[noreturn]] void throwStatementHasError(const char *whatHasHappened) const;
[[noreturn]] void throwStatementIsMisused(const char *whatHasHappened) const;
[[noreturn]] void throwConstraintPreventsModification(const char *whatHasHappened) const;
[[noreturn]] void throwNoValuesToFetch(const char *whatHasHappened) const;

View File

@@ -494,4 +494,19 @@ const char *DatabaseIsBusyTimeout::what() const noexcept
return "Sqlite::DatabaseIsBusyTimeout";
}
const char *StatementHasErrorMissingCollatingSequence::what() const noexcept
{
return "Sqlite::StatementHasErrorMissingCollatingSequence";
}
const char *StatementHasErrorRetry::what() const noexcept
{
return "Sqlite::StatementHasErrorRetry";
}
const char *StatementHasErrorSnapshot::what() const noexcept
{
return "Sqlite::StatementHasErrorSnapshot";
}
} // namespace Sqlite

View File

@@ -93,6 +93,27 @@ public:
const char *what() const noexcept override;
};
class SQLITE_EXPORT StatementHasErrorMissingCollatingSequence : public StatementHasError
{
public:
using StatementHasError::StatementHasError;
const char *what() const noexcept override;
};
class SQLITE_EXPORT StatementHasErrorRetry : public StatementHasError
{
public:
using StatementHasError::StatementHasError;
const char *what() const noexcept override;
};
class SQLITE_EXPORT StatementHasErrorSnapshot : public StatementHasError
{
public:
using StatementHasError::StatementHasError;
const char *what() const noexcept override;
};
class SQLITE_EXPORT StatementIsMisused : public ExceptionWithMessage
{
public: