diff --git a/src/libs/sqlite/sqlitebasestatement.cpp b/src/libs/sqlite/sqlitebasestatement.cpp index ce22ece5262..dc4dd465e7c 100644 --- a/src/libs/sqlite/sqlitebasestatement.cpp +++ b/src/libs/sqlite/sqlitebasestatement.cpp @@ -251,10 +251,46 @@ sqlite3 *BaseStatement::sqliteDatabaseHandle() const void BaseStatement::checkForStepError(int resultCode) const { switch (resultCode) { - case SQLITE_BUSY: throwStatementIsBusy("SqliteStatement::stepStatement: database engine was unable to acquire the database locks!"); - case SQLITE_ERROR : throwStatementHasError("SqliteStatement::stepStatement: run-time error (such as a constraint violation) has occurred!"); - case SQLITE_MISUSE: throwStatementIsMisused("SqliteStatement::stepStatement: was called inappropriately!"); - case SQLITE_CONSTRAINT: throwConstraintPreventsModification("SqliteStatement::stepStatement: contraint prevent insert or update!"); + case SQLITE_BUSY: + throwStatementIsBusy("SqliteStatement::stepStatement: database engine was unable to " + "acquire the database locks!"); + case SQLITE_ERROR: + throwStatementHasError("SqliteStatement::stepStatement: run-time error (such as a " + "constraint violation) has occurred!"); + case SQLITE_MISUSE: + throwStatementIsMisused("SqliteStatement::stepStatement: was called inappropriately!"); + case SQLITE_CONSTRAINT: + throwConstraintPreventsModification( + "SqliteStatement::stepStatement: contraint prevent insert or update!"); + case SQLITE_TOOBIG: + throwTooBig("SqliteStatement::stepStatement: Some is to bigger than SQLITE_MAX_LENGTH."); + case SQLITE_SCHEMA: + throwSchemaChangeError("SqliteStatement::stepStatement: Schema changed but the statement " + "cannot be recompiled."); + case SQLITE_READONLY: + throwCannotWriteToReadOnlyConnection( + "SqliteStatement::stepStatement: Cannot write to read only connection"); + case SQLITE_PROTOCOL: + throwProtocolError( + "SqliteStatement::stepStatement: Something strang with the file locking happened."); + case SQLITE_NOMEM: + throw std::bad_alloc(); + case SQLITE_NOLFS: + throwDatabaseExceedsMaximumFileSize( + "SqliteStatement::stepStatement: Database exceeds maximum file size."); + case SQLITE_MISMATCH: + throwDataTypeMismatch( + "SqliteStatement::stepStatement: Most probably you used not an integer for a rowid."); + case SQLITE_LOCKED: + throwConnectionIsLocked("SqliteStatement::stepStatement: Database connection is locked."); + case SQLITE_IOERR: + throwInputOutputError("SqliteStatement::stepStatement: An IO error happened."); + case SQLITE_INTERRUPT: + throwExecutionInterrupted("SqliteStatement::stepStatement: Execution was interrupted."); + case SQLITE_CORRUPT: + throwDatabaseIsCorrupt("SqliteStatement::stepStatement: Database is corrupt."); + case SQLITE_CANTOPEN: + throwCannotOpen("SqliteStatement::stepStatement: Cannot open database or temporary file."); } throwUnknowError("SqliteStatement::stepStatement: unknown error has happened"); @@ -263,10 +299,17 @@ void BaseStatement::checkForStepError(int resultCode) const void BaseStatement::checkForResetError(int resultCode) const { switch (resultCode) { - case SQLITE_BUSY: throwStatementIsBusy("SqliteStatement::stepStatement: database engine was unable to acquire the database locks!"); - case SQLITE_ERROR : throwStatementHasError("SqliteStatement::stepStatement: run-time error (such as a constraint violation) has occurred!"); - case SQLITE_MISUSE: throwStatementIsMisused("SqliteStatement::stepStatement: was called inappropriately!"); - case SQLITE_CONSTRAINT: throwConstraintPreventsModification("SqliteStatement::stepStatement: contraint prevent insert or update!"); + case SQLITE_BUSY: + throwStatementIsBusy("SqliteStatement::stepStatement: database engine was unable to " + "acquire the database locks!"); + case SQLITE_ERROR: + throwStatementHasError("SqliteStatement::stepStatement: run-time error (such as a " + "constraint violation) has occurred!"); + case SQLITE_MISUSE: + throwStatementIsMisused("SqliteStatement::stepStatement: was called inappropriately!"); + case SQLITE_CONSTRAINT: + throwConstraintPreventsModification( + "SqliteStatement::stepStatement: contraint prevent insert or update!"); } throwUnknowError("SqliteStatement::reset: unknown error has happened"); @@ -278,7 +321,8 @@ void BaseStatement::checkForPrepareError(int resultCode) const case SQLITE_BUSY: throwStatementIsBusy("SqliteStatement::prepareStatement: database engine was unable to acquire the database locks!"); case SQLITE_ERROR : throwStatementHasError("SqliteStatement::prepareStatement: run-time error (such as a constraint violation) has occurred!"); case SQLITE_MISUSE: throwStatementIsMisused("SqliteStatement::prepareStatement: was called inappropriately!"); - case SQLITE_IOERR: throwIoError("SqliteStatement::prepareStatement: IO error happened!"); + case SQLITE_IOERR: + throwInputOutputError("SqliteStatement::prepareStatement: IO error happened!"); } throwUnknowError("SqliteStatement::prepareStatement: unknown error has happened"); @@ -346,9 +390,9 @@ void BaseStatement::throwStatementIsMisused(const char *whatHasHappened) const throw StatementIsMisused(whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())); } -void BaseStatement::throwIoError(const char *whatHasHappened) const +void BaseStatement::throwInputOutputError(const char *whatHasHappened) const { - throw IoError(whatHasHappened); + throw InputOutputError(whatHasHappened); } void BaseStatement::throwConstraintPreventsModification(const char *whatHasHappened) const @@ -384,6 +428,56 @@ void BaseStatement::throwBingingTooBig(const char *whatHasHappened) const throw BindingTooBig(whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())); } +void BaseStatement::throwTooBig(const char *whatHasHappened) const +{ + throw TooBig{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwSchemaChangeError(const char *whatHasHappened) const +{ + throw SchemeChangeError{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwCannotWriteToReadOnlyConnection(const char *whatHasHappened) const +{ + throw CannotWriteToReadOnlyConnection{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwProtocolError(const char *whatHasHappened) const +{ + throw ProtocolError{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwDatabaseExceedsMaximumFileSize(const char *whatHasHappened) const +{ + throw DatabaseExceedsMaximumFileSize{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwDataTypeMismatch(const char *whatHasHappened) const +{ + throw DataTypeMismatch{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwConnectionIsLocked(const char *whatHasHappened) const +{ + throw ConnectionIsLocked{whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle())}; +} + +void BaseStatement::throwExecutionInterrupted(const char *whatHasHappened) const +{ + throw ExecutionInterrupted{whatHasHappened}; +} + +void BaseStatement::throwDatabaseIsCorrupt(const char *whatHasHappened) const +{ + throw DatabaseIsCorrupt{whatHasHappened}; +} + +void BaseStatement::throwCannotOpen(const char *whatHasHappened) const +{ + throw CannotOpen{whatHasHappened}; +} + QString BaseStatement::columnName(int column) const { return QString::fromUtf8(sqlite3_column_name(m_compiledStatement.get(), column)); diff --git a/src/libs/sqlite/sqlitebasestatement.h b/src/libs/sqlite/sqlitebasestatement.h index 2480a4674a6..bae41665d5c 100644 --- a/src/libs/sqlite/sqlitebasestatement.h +++ b/src/libs/sqlite/sqlitebasestatement.h @@ -109,7 +109,7 @@ public: [[noreturn]] void throwStatementIsBusy(const char *whatHasHappened) const; [[noreturn]] void throwStatementHasError(const char *whatHasHappened) const; [[noreturn]] void throwStatementIsMisused(const char *whatHasHappened) const; - [[noreturn]] void throwIoError(const char *whatHasHappened) const; + [[noreturn]] void throwInputOutputError(const char *whatHasHappened) const; [[noreturn]] void throwConstraintPreventsModification(const char *whatHasHappened) const; [[noreturn]] void throwNoValuesToFetch(const char *whatHasHappened) const; [[noreturn]] void throwInvalidColumnFetched(const char *whatHasHappened) const; @@ -117,6 +117,16 @@ public: [[noreturn]] void throwWrongBingingName(const char *whatHasHappened) const; [[noreturn]] void throwUnknowError(const char *whatHasHappened) const; [[noreturn]] void throwBingingTooBig(const char *whatHasHappened) const; + [[noreturn]] void throwTooBig(const char *whatHasHappened) const; + [[noreturn]] void throwSchemaChangeError(const char *whatHasHappened) const; + [[noreturn]] void throwCannotWriteToReadOnlyConnection(const char *whatHasHappened) const; + [[noreturn]] void throwProtocolError(const char *whatHasHappened) const; + [[noreturn]] void throwDatabaseExceedsMaximumFileSize(const char *whatHasHappened) const; + [[noreturn]] void throwDataTypeMismatch(const char *whatHasHappened) const; + [[noreturn]] void throwConnectionIsLocked(const char *whatHasHappened) const; + [[noreturn]] void throwExecutionInterrupted(const char *whatHasHappened) const; + [[noreturn]] void throwDatabaseIsCorrupt(const char *whatHasHappened) const; + [[noreturn]] void throwCannotOpen(const char *whatHasHappened) const; QString columnName(int column) const; diff --git a/src/libs/sqlite/sqliteexception.h b/src/libs/sqlite/sqliteexception.h index bd4245934c8..a46d30d851d 100644 --- a/src/libs/sqlite/sqliteexception.h +++ b/src/libs/sqlite/sqliteexception.h @@ -91,10 +91,10 @@ public: } }; -class IoError : public Exception +class InputOutputError : public Exception { public: - IoError(const char *whatErrorHasHappen) + InputOutputError(const char *whatErrorHasHappen) : Exception(whatErrorHasHappen) { } @@ -267,6 +267,14 @@ public: } }; +class TooBig : public Exception +{ +public: + TooBig(const char *whatErrorHasHappen, Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + class CannotConvert : public Exception { public: @@ -299,4 +307,84 @@ public: {} }; +class SchemeChangeError : public Exception +{ +public: + SchemeChangeError(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class CannotWriteToReadOnlyConnection : public Exception +{ +public: + CannotWriteToReadOnlyConnection(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class ProtocolError : public Exception +{ +public: + ProtocolError(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class DatabaseExceedsMaximumFileSize : public Exception +{ +public: + DatabaseExceedsMaximumFileSize(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class DataTypeMismatch : public Exception +{ +public: + DataTypeMismatch(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class ConnectionIsLocked : public Exception +{ +public: + ConnectionIsLocked(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class ExecutionInterrupted : public Exception +{ +public: + ExecutionInterrupted(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class DatabaseIsCorrupt : public Exception +{ +public: + DatabaseIsCorrupt(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; + +class CannotOpen : public Exception +{ +public: + CannotOpen(const char *whatErrorHasHappen, + Utils::SmallString &&errorMessage = Utils::SmallString()) + : Exception(whatErrorHasHappen, std::move(errorMessage)) + {} +}; } // namespace Sqlite