Debian Codegraph @

lib/generated_column.c

raw symbols SCIP
1 /*
2 Copyright (C) 2024 Sutou Kouhei <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "grn.h"
20 #include "grn_expr_executor.h"
21 #include "grn_generated_column.h"
22 #include "grn_store.h"
23
24 void
25 grn_generated_column_update(grn_ctx *ctx,
26 grn_obj *column,
27 grn_id id,
28 int section,
29 grn_obj *old_value,
30 grn_obj *new_value)
31 {
32 grn_ja *ja = (grn_ja *)column;
33 grn_expr_executor executor;
34 grn_expr_executor_init(ctx, &executor, ja->parsed_generator);
35 grn_id *source_ids = DB_OBJ(column)->source;
36 grn_expr_executor_add_replace_value(ctx, &executor, source_ids[0], new_value);
37 grn_obj *value = grn_expr_executor_exec(ctx, &executor, id);
38 if (ctx->rc == GRN_SUCCESS) {
39 grn_obj_set_value(ctx, column, id, value, GRN_OBJ_SET);
40 }
41 grn_expr_executor_fin(ctx, &executor);
42 }
43
44 void
45 grn_generated_column_build(grn_ctx *ctx, grn_obj *column)
46 {
47 grn_obj *table = grn_ctx_at(ctx, column->header.domain);
48 grn_id *source_ids = DB_OBJ(column)->source;
49 grn_obj *source = grn_ctx_at(ctx, source_ids[0]);
50 grn_obj_set_visibility(ctx, column, false);
51 if (ctx->rc == GRN_SUCCESS) {
52 grn_obj *generator = ((grn_ja *)(column))->parsed_generator;
53 grn_table_apply_expr(ctx, table, column, generator);
54 }
55 if (ctx->rc == GRN_SUCCESS) {
56 grn_obj_set_visibility(ctx, column, true);
57 }
58 grn_obj_unref(ctx, source);
59 grn_obj_unref(ctx, table);
60 }