1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +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:
Jan de Visser 2021-10-23 10:46:33 -04:00 committed by Andreas Kling
parent 0cfb5eec32
commit 9022cf99ff
5 changed files with 125 additions and 55 deletions

View file

@ -437,13 +437,32 @@ private:
String m_column_name;
};
#define __enum_UnaryOperator(S) \
S(Minus, "-") \
S(Plus, "+") \
S(BitwiseNot, "~") \
S(Not, "NOT")
enum class UnaryOperator {
Minus,
Plus,
BitwiseNot,
Not,
#undef __UnaryOperator
#define __UnaryOperator(code, name) code,
__enum_UnaryOperator(__UnaryOperator)
#undef __UnaryOperator
};
constexpr char const* UnaryOperator_name(UnaryOperator op)
{
switch (op) {
#undef __UnaryOperator
#define __UnaryOperator(code, name) \
case UnaryOperator::code: \
return name;
__enum_UnaryOperator(__UnaryOperator)
#undef __UnaryOperator
default : VERIFY_NOT_REACHED();
}
}
class UnaryOperatorExpression : public NestedExpression {
public:
UnaryOperatorExpression(UnaryOperator type, NonnullRefPtr<Expression> expression)
@ -459,28 +478,47 @@ private:
UnaryOperator m_type;
};
// Note: These are in order of highest-to-lowest operator precedence.
#define __enum_BinaryOperator(S) \
S(Concatenate, "||") \
S(Multiplication, "*") \
S(Division, "/") \
S(Modulo, "%") \
S(Plus, "+") \
S(Minus, "-") \
S(ShiftLeft, "<<") \
S(ShiftRight, ">>") \
S(BitwiseAnd, "&") \
S(BitwiseOr, "|") \
S(LessThan, "<") \
S(LessThanEquals, "<=") \
S(GreaterThan, ">") \
S(GreaterThanEquals, ">=") \
S(Equals, "=") \
S(NotEquals, "!=") \
S(And, "and") \
S(Or, "or")
enum class BinaryOperator {
// Note: These are in order of highest-to-lowest operator precedence.
Concatenate,
Multiplication,
Division,
Modulo,
Plus,
Minus,
ShiftLeft,
ShiftRight,
BitwiseAnd,
BitwiseOr,
LessThan,
LessThanEquals,
GreaterThan,
GreaterThanEquals,
Equals,
NotEquals,
And,
Or,
#undef __BinaryOperator
#define __BinaryOperator(code, name) code,
__enum_BinaryOperator(__BinaryOperator)
#undef __BinaryOperator
};
constexpr char const* BinaryOperator_name(BinaryOperator op)
{
switch (op) {
#undef __BinaryOperator
#define __BinaryOperator(code, name) \
case BinaryOperator::code: \
return name;
__enum_BinaryOperator(__BinaryOperator)
#undef __BinaryOperator
default : VERIFY_NOT_REACHED();
}
}
class BinaryOperatorExpression : public NestedDoubleExpression {
public:
BinaryOperatorExpression(BinaryOperator type, NonnullRefPtr<Expression> lhs, NonnullRefPtr<Expression> rhs)