From 5e69ce10472f70988df9cdf7b1a19174f58a9f4d Mon Sep 17 00:00:00 2001 From: VaclavT Date: Fri, 9 Jul 2021 23:42:43 +0200 Subject: [PATCH] basic delete works --- executor.cpp | 4 ++-- main.cpp | 4 +++- parser.h | 2 ++ row.cpp | 5 +++++ row.h | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/executor.cpp b/executor.cpp index 02fcee0..676cb24 100644 --- a/executor.cpp +++ b/executor.cpp @@ -140,8 +140,8 @@ bool Executor::execute_delete(DeleteFromTableNode& node) { auto it = table->m_rows.begin(); for ( ; it != table->m_rows.end(); ) { if (evalWhere(node.where.get(), table, it)) { - std::cout << "delete here" << std::endl; - ++it; // TODO this does not work : it = table->m_rows.erase(it); + // TODO this can be really expensive operation + it = table->m_rows.erase(it); } else { ++it; } diff --git a/main.cpp b/main.cpp index 070e0dd..fb40d20 100644 --- a/main.cpp +++ b/main.cpp @@ -22,10 +22,12 @@ int main(int argc, char *argv[]) { "select i, s from a where i = 1", "select i, s from a where s = 'two'", "select i, s from a where i <= 3 and s = 'one'", + "select i, s from a where i > 0", + "delete from a where i = 4", + "select i, s from a where i > 0", "update a set f = 9.99 where i = 3", // "update a set s = 'three', f = 1.0 + 2.0 where i = 3", "select i, s, f from a where i = 3" -// "delete from a where i = 4", // "select i, s from a where i > 0" }; diff --git a/parser.h b/parser.h index 0a755cc..810970a 100644 --- a/parser.h +++ b/parser.h @@ -66,6 +66,8 @@ struct ColDefNode : Node { Node(NodeType::column_def), name(col_name), type(col_type), order(col_order), length(col_len), null(nullable) {} }; + + struct TrueNode : Node { TrueNode() : Node(NodeType::true_node) {} }; diff --git a/row.cpp b/row.cpp index ee4ec59..40e2f85 100644 --- a/row.cpp +++ b/row.cpp @@ -29,6 +29,11 @@ Row::Row(const Row &other) { } } +Row& Row::operator=(Row other) { + std::swap(m_columns, other.m_columns); + return *this; +} + void Row::setColumnValue(int col_index, int value) { m_columns[col_index] = std::make_unique(value); } diff --git a/row.h b/row.h index 41fc34e..002e1a0 100644 --- a/row.h +++ b/row.h @@ -99,6 +99,7 @@ class Row { public: Row(int cols_count); Row(const Row &other); + Row& operator=(Row other); void setColumnValue(int col_index, int value); void setColumnValue(int col_index, double value);