basic delete works

This commit is contained in:
VaclavT 2021-07-09 23:42:43 +02:00
parent ddb9441e23
commit 5e69ce1047
5 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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"
};

View File

@ -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) {}
};

View File

@ -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<ColIntegerValue>(value);
}

1
row.h
View File

@ -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);