diff options
author | Jan de Visser <jan@de-visser.net> | 2021-11-13 17:30:29 -0500 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-12-04 20:49:22 +0330 |
commit | c369626ac19c4f03fb15e5d869c6c9d39ad56fa3 (patch) | |
tree | 48bbb36e363b2e0c414e2ed2e5bb8b58368b3145 /Userland/Libraries/LibSQL | |
parent | 001949d77a3e78ccd54a28f075d5e67619ed79bd (diff) | |
download | serenity-c369626ac19c4f03fb15e5d869c6c9d39ad56fa3.zip |
LibSQL: Gracefully react to unimplemented valid SQL
Fixes a crash that was caused by a syntax error which is difficult to
catch by the parser: usually identifiers are accepted in column lists,
but they are not in a list of column values to be inserted in an INSERT.
Fixed this by putting in a heuristic check; we probably need a better
way to do this.
Included tests for this case.
Also introduced a new SQL Error code, `NotYetImplemented`, and return
that instead of crashing when encountering unimplemented SQL.
Diffstat (limited to 'Userland/Libraries/LibSQL')
-rw-r--r-- | Userland/Libraries/LibSQL/AST/Expression.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Libraries/LibSQL/AST/Expression.cpp b/Userland/Libraries/LibSQL/AST/Expression.cpp index d4030b3532..ce4c972e0c 100644 --- a/Userland/Libraries/LibSQL/AST/Expression.cpp +++ b/Userland/Libraries/LibSQL/AST/Expression.cpp @@ -169,6 +169,10 @@ Value UnaryOperatorExpression::evaluate(ExecutionContext& context) const Value ColumnNameExpression::evaluate(ExecutionContext& context) const { + if (!context.current_row) { + context.result->set_error(SQLErrorCode::SyntaxError, column_name()); + return Value::null(); + } auto& descriptor = *context.current_row->descriptor(); VERIFY(context.current_row->size() == descriptor.size()); Optional<size_t> index_in_row; |