1 | /* |
2 | * This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
5 | * |
6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
7 | */ |
8 | |
9 | #include "monetdb_config.h" |
10 | #include "sql_query.h" |
11 | |
12 | static stacked_query * |
13 | sq_create( sql_allocator *sa, sql_rel *rel, int sql_state) |
14 | { |
15 | stacked_query *q = SA_NEW(sa, stacked_query); |
16 | |
17 | assert(rel); |
18 | q->rel = rel; |
19 | q->sql_state = sql_state; |
20 | return q; |
21 | } |
22 | |
23 | sql_query * |
24 | query_create( mvc *sql) |
25 | { |
26 | sql_query *q = SA_NEW(sql->sa, sql_query); |
27 | |
28 | q->sql = sql; |
29 | q->outer = sql_stack_new(sql->sa, 32); |
30 | return q; |
31 | } |
32 | |
33 | void |
34 | query_push_outer(sql_query *q, sql_rel *r, int sql_state) |
35 | { |
36 | stacked_query *sq = sq_create(q->sql->sa, r, sql_state); |
37 | assert(sq); |
38 | sql_stack_push(q->outer, sq); |
39 | } |
40 | |
41 | sql_rel * |
42 | query_pop_outer(sql_query *q) |
43 | { |
44 | stacked_query *sq = sql_stack_pop(q->outer); |
45 | sql_rel *r = sq->rel; |
46 | return r; |
47 | } |
48 | |
49 | sql_rel * |
50 | query_fetch_outer(sql_query *q, int i) |
51 | { |
52 | stacked_query *sq = sql_stack_fetch(q->outer, i); |
53 | if (!sq) |
54 | return NULL; |
55 | return sq->rel; |
56 | } |
57 | |
58 | int |
59 | query_fetch_outer_state(sql_query *q, int i) |
60 | { |
61 | stacked_query *sq = sql_stack_fetch(q->outer, i); |
62 | if (!sq) |
63 | return 0; |
64 | return sq->sql_state; |
65 | } |
66 | |
67 | void |
68 | query_update_outer(sql_query *q, sql_rel *r, int i) |
69 | { |
70 | stacked_query *sq = sql_stack_fetch(q->outer, i); |
71 | sq->rel = r; |
72 | } |
73 | |
74 | int |
75 | query_has_outer(sql_query *q) |
76 | { |
77 | return sql_stack_top(q->outer); |
78 | } |
79 | |