forked from qt-creator/qt-creator
Sqlite: Change error handling for reset
Error handling in reset() is not needed because it is only repeating the errors of step(). We do already handle them. Reset() is also mostly called in destructors so we can not do much about error there. Reset is only now reset the statement to a clean state again which is what we want. Task-number: QDS-4286 Change-Id: Ifa50859f3d47cc110ef03d7273a01d4419eca9aa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -110,12 +110,9 @@ void BaseStatement::waitForUnlockNotify() const
|
|||||||
unlockNotification.wait();
|
unlockNotification.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseStatement::reset() const
|
void BaseStatement::reset() const noexcept
|
||||||
{
|
{
|
||||||
int resultCode = sqlite3_reset(m_compiledStatement.get());
|
sqlite3_reset(m_compiledStatement.get());
|
||||||
|
|
||||||
if (resultCode != SQLITE_OK)
|
|
||||||
checkForResetError(resultCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseStatement::next() const
|
bool BaseStatement::next() const
|
||||||
@@ -448,42 +445,6 @@ void BaseStatement::checkForStepError(int resultCode) const
|
|||||||
throwUnknowError("SqliteStatement::stepStatement: unknown error has happened");
|
throwUnknowError("SqliteStatement::stepStatement: unknown error has happened");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseStatement::checkForResetError(int resultCode) const
|
|
||||||
{
|
|
||||||
switch (resultCode) {
|
|
||||||
case SQLITE_BUSY_RECOVERY:
|
|
||||||
case SQLITE_BUSY_SNAPSHOT:
|
|
||||||
case SQLITE_BUSY_TIMEOUT:
|
|
||||||
case SQLITE_BUSY:
|
|
||||||
throwStatementIsBusy("SqliteStatement::stepStatement: database engine was unable to "
|
|
||||||
"acquire the database locks!");
|
|
||||||
case SQLITE_ERROR_MISSING_COLLSEQ:
|
|
||||||
case SQLITE_ERROR_RETRY:
|
|
||||||
case SQLITE_ERROR_SNAPSHOT:
|
|
||||||
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_CHECK:
|
|
||||||
case SQLITE_CONSTRAINT_COMMITHOOK:
|
|
||||||
case SQLITE_CONSTRAINT_FOREIGNKEY:
|
|
||||||
case SQLITE_CONSTRAINT_FUNCTION:
|
|
||||||
case SQLITE_CONSTRAINT_NOTNULL:
|
|
||||||
case SQLITE_CONSTRAINT_PINNED:
|
|
||||||
case SQLITE_CONSTRAINT_PRIMARYKEY:
|
|
||||||
case SQLITE_CONSTRAINT_ROWID:
|
|
||||||
case SQLITE_CONSTRAINT_TRIGGER:
|
|
||||||
case SQLITE_CONSTRAINT_UNIQUE:
|
|
||||||
case SQLITE_CONSTRAINT_VTAB:
|
|
||||||
case SQLITE_CONSTRAINT:
|
|
||||||
throwConstraintPreventsModification(
|
|
||||||
"SqliteStatement::stepStatement: contraint prevent insert or update!");
|
|
||||||
}
|
|
||||||
|
|
||||||
throwUnknowError("SqliteStatement::reset: unknown error has happened");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseStatement::checkForPrepareError(int resultCode) const
|
void BaseStatement::checkForPrepareError(int resultCode) const
|
||||||
{
|
{
|
||||||
switch (resultCode) {
|
switch (resultCode) {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
bool next() const;
|
bool next() const;
|
||||||
void step() const;
|
void step() const;
|
||||||
void reset() const;
|
void reset() const noexcept;
|
||||||
|
|
||||||
Type fetchType(int column) const;
|
Type fetchType(int column) const;
|
||||||
int fetchIntValue(int column) const;
|
int fetchIntValue(int column) const;
|
||||||
@@ -109,7 +109,6 @@ public:
|
|||||||
sqlite3 *sqliteDatabaseHandle() const;
|
sqlite3 *sqliteDatabaseHandle() const;
|
||||||
|
|
||||||
[[noreturn]] void checkForStepError(int resultCode) const;
|
[[noreturn]] void checkForStepError(int resultCode) const;
|
||||||
[[noreturn]] void checkForResetError(int resultCode) const;
|
|
||||||
[[noreturn]] void checkForPrepareError(int resultCode) const;
|
[[noreturn]] void checkForPrepareError(int resultCode) const;
|
||||||
[[noreturn]] void checkForBindingError(int resultCode) const;
|
[[noreturn]] void checkForBindingError(int resultCode) const;
|
||||||
void setIfIsReadyToFetchValues(int resultCode) const;
|
void setIfIsReadyToFetchValues(int resultCode) const;
|
||||||
@@ -174,7 +173,6 @@ public:
|
|||||||
{
|
{
|
||||||
Resetter resetter{this};
|
Resetter resetter{this};
|
||||||
BaseStatement::next();
|
BaseStatement::next();
|
||||||
resetter.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindValues() {}
|
void bindValues() {}
|
||||||
@@ -192,7 +190,6 @@ public:
|
|||||||
Resetter resetter{this};
|
Resetter resetter{this};
|
||||||
bindValues(values...);
|
bindValues(values...);
|
||||||
BaseStatement::next();
|
BaseStatement::next();
|
||||||
resetter.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ResultType, typename... QueryTypes>
|
template<typename ResultType, typename... QueryTypes>
|
||||||
@@ -209,8 +206,6 @@ public:
|
|||||||
|
|
||||||
setMaximumResultCount(resultValues.size());
|
setMaximumResultCount(resultValues.size());
|
||||||
|
|
||||||
resetter.reset();
|
|
||||||
|
|
||||||
return resultValues;
|
return resultValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,8 +220,6 @@ public:
|
|||||||
if (BaseStatement::next())
|
if (BaseStatement::next())
|
||||||
resultValue = createValue<ResultType>();
|
resultValue = createValue<ResultType>();
|
||||||
|
|
||||||
resetter.reset();
|
|
||||||
|
|
||||||
return resultValue;
|
return resultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +234,6 @@ public:
|
|||||||
if (BaseStatement::next())
|
if (BaseStatement::next())
|
||||||
resultValue = createOptionalValue<Utils::optional<ResultType>>();
|
resultValue = createOptionalValue<Utils::optional<ResultType>>();
|
||||||
|
|
||||||
resetter.reset();
|
|
||||||
|
|
||||||
return resultValue;
|
return resultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +262,6 @@ public:
|
|||||||
if (control == CallbackControl::Abort)
|
if (control == CallbackControl::Abort)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetter.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container, typename... QueryTypes>
|
template<typename Container, typename... QueryTypes>
|
||||||
@@ -284,8 +273,6 @@ public:
|
|||||||
|
|
||||||
while (BaseStatement::next())
|
while (BaseStatement::next())
|
||||||
emplaceBackValues(container);
|
emplaceBackValues(container);
|
||||||
|
|
||||||
resetter.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ResultType, typename... QueryTypes>
|
template<typename ResultType, typename... QueryTypes>
|
||||||
@@ -392,12 +379,6 @@ public:
|
|||||||
statement.bindValues(queryValues...);
|
statement.bindValues(queryValues...);
|
||||||
}
|
}
|
||||||
|
|
||||||
~SqliteResultRange()
|
|
||||||
{
|
|
||||||
if (!std::uncaught_exceptions())
|
|
||||||
resetter.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Resetter resetter;
|
Resetter resetter;
|
||||||
};
|
};
|
||||||
@@ -418,8 +399,9 @@ public:
|
|||||||
|
|
||||||
~SqliteResultRangeWithTransaction()
|
~SqliteResultRangeWithTransaction()
|
||||||
{
|
{
|
||||||
|
resetter.reset();
|
||||||
|
|
||||||
if (!std::uncaught_exceptions()) {
|
if (!std::uncaught_exceptions()) {
|
||||||
resetter.reset();
|
|
||||||
m_transaction.commit();
|
m_transaction.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,25 +433,13 @@ private:
|
|||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
try {
|
if (statement)
|
||||||
if (statement)
|
statement->reset();
|
||||||
statement->reset();
|
|
||||||
} catch (...) {
|
|
||||||
statement = nullptr;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
statement = nullptr;
|
statement = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Resetter() noexcept
|
~Resetter() noexcept { reset(); }
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (statement)
|
|
||||||
statement->reset();
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StatementImplementation *statement;
|
StatementImplementation *statement;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user