mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibSQL: Add better error handling to evaluate
and execute
methods
There was a lot of `VERIFY_NOT_REACHED` error handling going on. Fixed most of those. A bit of a caveat is that after every `evaluate` call for expressions that are part of a statement the error status of the `SQLResult` return value must be called.
This commit is contained in:
parent
0cfb5eec32
commit
9022cf99ff
Notes:
sideshowbarker
2024-07-18 01:54:09 +09:00
Author: https://github.com/JanDeVisser
Commit: 9022cf99ff
Pull-request: https://github.com/SerenityOS/serenity/pull/10598
Reviewed-by: https://github.com/trflynn89 ✅
5 changed files with 125 additions and 55 deletions
|
@ -41,21 +41,25 @@ constexpr char const* command_tag(SQLCommand command)
|
|||
}
|
||||
}
|
||||
|
||||
#define ENUMERATE_SQL_ERRORS(S) \
|
||||
S(NoError, "No error") \
|
||||
S(DatabaseUnavailable, "Database Unavailable") \
|
||||
S(StatementUnavailable, "Statement with id '{}' Unavailable") \
|
||||
S(SyntaxError, "Syntax Error") \
|
||||
S(DatabaseDoesNotExist, "Database '{}' does not exist") \
|
||||
S(SchemaDoesNotExist, "Schema '{}' does not exist") \
|
||||
S(SchemaExists, "Schema '{}' already exist") \
|
||||
S(TableDoesNotExist, "Table '{}' does not exist") \
|
||||
S(ColumnDoesNotExist, "Column '{}' does not exist") \
|
||||
S(TableExists, "Table '{}' already exist") \
|
||||
S(InvalidType, "Invalid type '{}'") \
|
||||
S(InvalidDatabaseName, "Invalid database name '{}'") \
|
||||
S(InvalidValueType, "Invalid type for attribute '{}'") \
|
||||
S(InvalidNumberOfValues, "Number of values does not match number of columns")
|
||||
#define ENUMERATE_SQL_ERRORS(S) \
|
||||
S(NoError, "No error") \
|
||||
S(DatabaseUnavailable, "Database Unavailable") \
|
||||
S(StatementUnavailable, "Statement with id '{}' Unavailable") \
|
||||
S(SyntaxError, "Syntax Error") \
|
||||
S(DatabaseDoesNotExist, "Database '{}' does not exist") \
|
||||
S(SchemaDoesNotExist, "Schema '{}' does not exist") \
|
||||
S(SchemaExists, "Schema '{}' already exist") \
|
||||
S(TableDoesNotExist, "Table '{}' does not exist") \
|
||||
S(ColumnDoesNotExist, "Column '{}' does not exist") \
|
||||
S(TableExists, "Table '{}' already exist") \
|
||||
S(InvalidType, "Invalid type '{}'") \
|
||||
S(InvalidDatabaseName, "Invalid database name '{}'") \
|
||||
S(InvalidValueType, "Invalid type for attribute '{}'") \
|
||||
S(InvalidNumberOfValues, "Number of values does not match number of columns") \
|
||||
S(BooleanOperatorTypeMismatch, "Cannot apply '{}' operator to non-boolean operands") \
|
||||
S(NumericOperatorTypeMismatch, "Cannot apply '{}' operator to non-numeric operands") \
|
||||
S(IntegerOperatorTypeMismatch, "Cannot apply '{}' operator to non-numeric operands") \
|
||||
S(InvalidOperator, "Invalid operator '{}'")
|
||||
|
||||
enum class SQLErrorCode {
|
||||
#undef __ENUMERATE_SQL_ERROR
|
||||
|
@ -113,6 +117,13 @@ public:
|
|||
int updated() const { return m_update_count; }
|
||||
int inserted() const { return m_insert_count; }
|
||||
int deleted() const { return m_delete_count; }
|
||||
void set_error(SQLErrorCode code, String argument = {})
|
||||
{
|
||||
m_error.code = code;
|
||||
m_error.error_argument = argument;
|
||||
}
|
||||
|
||||
bool has_error() const { return m_error.code != SQLErrorCode::NoError; }
|
||||
SQLError const& error() const { return m_error; }
|
||||
bool has_results() const { return m_has_results; }
|
||||
Vector<Tuple> const& results() const { return m_result_set; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue