1
/******************************************************
2
Executes SQL stored procedures and their control structures
6
Created 1/20/1998 Heikki Tuuri
7
*******************************************************/
12
#include "eval0proc.ic"
15
/**************************************************************************
16
Performs an execution step of an if-statement node. */
21
/* out: query thread to run next or NULL */
22
que_thr_t* thr) /* in: query thread */
25
elsif_node_t* elsif_node;
30
ut_ad(que_node_get_type(node) == QUE_NODE_IF);
32
if (thr->prev_node == que_node_get_parent(node)) {
34
/* Evaluate the condition */
38
if (eval_node_get_ibool_val(node->cond)) {
40
/* The condition evaluated to TRUE: start execution
41
from the first statement in the statement list */
43
thr->run_node = node->stat_list;
45
} else if (node->else_part) {
46
thr->run_node = node->else_part;
48
} else if (node->elsif_list) {
49
elsif_node = node->elsif_list;
52
eval_exp(elsif_node->cond);
54
if (eval_node_get_ibool_val(
57
/* The condition evaluated to TRUE:
58
start execution from the first
59
statement in the statement list */
61
thr->run_node = elsif_node->stat_list;
66
elsif_node = que_node_get_next(elsif_node);
68
if (elsif_node == NULL) {
78
/* Move to the next statement */
79
ut_ad(que_node_get_next(thr->prev_node) == NULL);
84
if (thr->run_node == NULL) {
85
thr->run_node = que_node_get_parent(node);
91
/**************************************************************************
92
Performs an execution step of a while-statement node. */
97
/* out: query thread to run next or NULL */
98
que_thr_t* thr) /* in: query thread */
104
node = thr->run_node;
105
ut_ad(que_node_get_type(node) == QUE_NODE_WHILE);
107
ut_ad((thr->prev_node == que_node_get_parent(node))
108
|| (que_node_get_next(thr->prev_node) == NULL));
110
/* Evaluate the condition */
112
eval_exp(node->cond);
114
if (eval_node_get_ibool_val(node->cond)) {
116
/* The condition evaluated to TRUE: start execution
117
from the first statement in the statement list */
119
thr->run_node = node->stat_list;
121
thr->run_node = que_node_get_parent(node);
127
/**************************************************************************
128
Performs an execution step of an assignment statement node. */
133
/* out: query thread to run next or NULL */
134
que_thr_t* thr) /* in: query thread */
140
node = thr->run_node;
141
ut_ad(que_node_get_type(node) == QUE_NODE_ASSIGNMENT);
143
/* Evaluate the value to assign */
147
eval_node_copy_val(node->var->alias, node->val);
149
thr->run_node = que_node_get_parent(node);
154
/**************************************************************************
155
Performs an execution step of a for-loop node. */
160
/* out: query thread to run next or NULL */
161
que_thr_t* thr) /* in: query thread */
169
node = thr->run_node;
171
ut_ad(que_node_get_type(node) == QUE_NODE_FOR);
173
parent = que_node_get_parent(node);
175
if (thr->prev_node != parent) {
177
/* Move to the next statement */
178
thr->run_node = que_node_get_next(thr->prev_node);
180
if (thr->run_node != NULL) {
185
/* Increment the value of loop_var */
187
loop_var_value = 1 + eval_node_get_int_val(node->loop_var);
189
/* Initialize the loop */
191
eval_exp(node->loop_start_limit);
192
eval_exp(node->loop_end_limit);
194
loop_var_value = eval_node_get_int_val(node->loop_start_limit);
197
= (int) eval_node_get_int_val(node->loop_end_limit);
200
/* Check if we should do another loop */
202
if (loop_var_value > node->loop_end_value) {
204
/* Enough loops done */
206
thr->run_node = parent;
208
eval_node_set_int_val(node->loop_var, loop_var_value);
210
thr->run_node = node->stat_list;
216
/**************************************************************************
217
Performs an execution step of an exit statement node. */
222
/* out: query thread to run next or NULL */
223
que_thr_t* thr) /* in: query thread */
226
que_node_t* loop_node;
230
node = thr->run_node;
232
ut_ad(que_node_get_type(node) == QUE_NODE_EXIT);
234
/* Loops exit by setting thr->run_node as the loop node's parent, so
235
find our containing loop node and get its parent. */
237
loop_node = que_node_get_containing_loop_node(node);
239
/* If someone uses an EXIT statement outside of a loop, this will
243
thr->run_node = que_node_get_parent(loop_node);
248
/**************************************************************************
249
Performs an execution step of a return-statement node. */
254
/* out: query thread to run next or NULL */
255
que_thr_t* thr) /* in: query thread */
262
node = thr->run_node;
264
ut_ad(que_node_get_type(node) == QUE_NODE_RETURN);
268
while (que_node_get_type(parent) != QUE_NODE_PROC) {
270
parent = que_node_get_parent(parent);
275
thr->run_node = que_node_get_parent(parent);