updates a single property or label
| 49 | |
| 50 | // updates a single property or label |
| 51 | static void _ConvertUpdateItem |
| 52 | ( |
| 53 | GraphContext *gc, |
| 54 | rax *updates, |
| 55 | const cypher_astnode_t *update_item |
| 56 | ) { |
| 57 | ASSERT(gc != NULL); |
| 58 | ASSERT(updates != NULL); |
| 59 | ASSERT(update_item != NULL); |
| 60 | |
| 61 | const char *alias = NULL; // entity being updated |
| 62 | const char *attribute = NULL; // attribute being set |
| 63 | const cypher_astnode_t *prop_expr = NULL; |
| 64 | const cypher_astnode_t *ast_prop = NULL; |
| 65 | const cypher_astnode_t *ast_key = NULL; // AST node attribute set |
| 66 | const cypher_astnode_t *ast_value = NULL; // AST node value set |
| 67 | const cypher_astnode_type_t type = cypher_astnode_type(update_item); |
| 68 | |
| 69 | bool set_labels = false; |
| 70 | bool remove_labels = false; |
| 71 | UPDATE_MODE update_mode = UPDATE_MERGE; |
| 72 | //-------------------------------------------------------------------------- |
| 73 | // determine the type of assignment |
| 74 | //-------------------------------------------------------------------------- |
| 75 | // 1. override - MATCH (a) SET a = {v: 5} |
| 76 | // 2. merge - MATCH (a) SET a += {v: 5} |
| 77 | // 3. update - MATCH (a) SET a.v = 5 |
| 78 | // 4. label set - MATCH (a) SET a:Label1:Label2 |
| 79 | // 5. label del - MATCH (a) REMOVE a:Label1:Label2 |
| 80 | // 6. attr del - MATCH (a) REMOVE a.v |
| 81 | //-------------------------------------------------------------------------- |
| 82 | |
| 83 | if(type == CYPHER_AST_SET_ALL_PROPERTIES) { |
| 84 | // MATCH (a) SET a = {v: 5} |
| 85 | update_mode = UPDATE_REPLACE; |
| 86 | |
| 87 | // alias |
| 88 | prop_expr = cypher_ast_set_all_properties_get_identifier(update_item); |
| 89 | ASSERT(cypher_astnode_type(prop_expr) == CYPHER_AST_IDENTIFIER); |
| 90 | alias = cypher_ast_identifier_get_name(prop_expr); |
| 91 | // value |
| 92 | ast_value = cypher_ast_set_all_properties_get_expression(update_item); |
| 93 | } else if(type == CYPHER_AST_MERGE_PROPERTIES) { |
| 94 | // MATCH (a) SET a += {v: 5} |
| 95 | // alias |
| 96 | prop_expr = cypher_ast_merge_properties_get_identifier(update_item); |
| 97 | ASSERT(cypher_astnode_type(prop_expr) == CYPHER_AST_IDENTIFIER); |
| 98 | alias = cypher_ast_identifier_get_name(prop_expr); |
| 99 | // value |
| 100 | ast_value = cypher_ast_merge_properties_get_expression(update_item); |
| 101 | } else if(type == CYPHER_AST_SET_PROPERTY) { |
| 102 | // MATCH (a) SET a.v = 5 |
| 103 | |
| 104 | // alias |
| 105 | ast_prop = cypher_ast_set_property_get_property(update_item); |
| 106 | prop_expr = cypher_ast_property_operator_get_expression(ast_prop); |
| 107 | ASSERT(cypher_astnode_type(prop_expr) == CYPHER_AST_IDENTIFIER); |
| 108 | alias = cypher_ast_identifier_get_name(prop_expr); |
no test coverage detected