LibSQL: First cut of SQL WHERE clause

Filters matching rows by doing a table scan and evaluating the `WHERE`
expression for every row.

Does not use indexes, for one because they do not exist yet.
This commit is contained in:
Jan de Visser 2021-10-21 18:13:29 -04:00 committed by Andreas Kling
parent 9d1e27d8a8
commit 0cfb5eec32
Notes: sideshowbarker 2024-07-18 01:54:13 +09:00

View File

@ -34,9 +34,15 @@ RefPtr<SQLResult> Select::execute(ExecutionContext& context) const
}
context.result = SQLResult::construct();
AK::NonnullRefPtr<TupleDescriptor> descriptor = AK::adopt_ref(*new TupleDescriptor);
Tuple tuple(descriptor);
for (auto& row : context.database->select_all(*table)) {
context.current_row = &row;
Tuple tuple(descriptor);
if (where_clause()) {
auto where_result = where_clause()->evaluate(context);
if (!where_result)
continue;
}
tuple.clear();
for (auto& col : columns) {
auto value = col.expression()->evaluate(context);
tuple.append(value);