~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
3
Copyright (C) 1998, 2009, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
4
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
8
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License along with
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file eval/eval0proc.c
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Executes SQL stored procedures and their control structures
22
23
Created 1/20/1998 Heikki Tuuri
24
*******************************************************/
25
26
#include "eval0proc.h"
27
28
#ifdef UNIV_NONINL
29
#include "eval0proc.ic"
30
#endif
31
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
32
/**********************************************************************//**
33
Performs an execution step of an if-statement node.
34
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
35
UNIV_INTERN
36
que_thr_t*
37
if_step(
38
/*====*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
40
{
41
	if_node_t*	node;
42
	elsif_node_t*	elsif_node;
43
44
	ut_ad(thr);
45
46
	node = thr->run_node;
47
	ut_ad(que_node_get_type(node) == QUE_NODE_IF);
48
49
	if (thr->prev_node == que_node_get_parent(node)) {
50
51
		/* Evaluate the condition */
52
53
		eval_exp(node->cond);
54
55
		if (eval_node_get_ibool_val(node->cond)) {
56
57
			/* The condition evaluated to TRUE: start execution
58
			from the first statement in the statement list */
59
60
			thr->run_node = node->stat_list;
61
62
		} else if (node->else_part) {
63
			thr->run_node = node->else_part;
64
65
		} else if (node->elsif_list) {
66
			elsif_node = node->elsif_list;
67
68
			for (;;) {
69
				eval_exp(elsif_node->cond);
70
71
				if (eval_node_get_ibool_val(
72
					    elsif_node->cond)) {
73
74
					/* The condition evaluated to TRUE:
75
					start execution from the first
76
					statement in the statement list */
77
78
					thr->run_node = elsif_node->stat_list;
79
80
					break;
81
				}
82
83
				elsif_node = que_node_get_next(elsif_node);
84
85
				if (elsif_node == NULL) {
86
					thr->run_node = NULL;
87
88
					break;
89
				}
90
			}
91
		} else {
92
			thr->run_node = NULL;
93
		}
94
	} else {
95
		/* Move to the next statement */
96
		ut_ad(que_node_get_next(thr->prev_node) == NULL);
97
98
		thr->run_node = NULL;
99
	}
100
101
	if (thr->run_node == NULL) {
102
		thr->run_node = que_node_get_parent(node);
103
	}
104
105
	return(thr);
106
}
107
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
108
/**********************************************************************//**
109
Performs an execution step of a while-statement node.
110
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
111
UNIV_INTERN
112
que_thr_t*
113
while_step(
114
/*=======*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
115
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
116
{
117
	while_node_t*	node;
118
119
	ut_ad(thr);
120
121
	node = thr->run_node;
122
	ut_ad(que_node_get_type(node) == QUE_NODE_WHILE);
123
124
	ut_ad((thr->prev_node == que_node_get_parent(node))
125
	      || (que_node_get_next(thr->prev_node) == NULL));
126
127
	/* Evaluate the condition */
128
129
	eval_exp(node->cond);
130
131
	if (eval_node_get_ibool_val(node->cond)) {
132
133
		/* The condition evaluated to TRUE: start execution
134
		from the first statement in the statement list */
135
136
		thr->run_node = node->stat_list;
137
	} else {
138
		thr->run_node = que_node_get_parent(node);
139
	}
140
141
	return(thr);
142
}
143
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
144
/**********************************************************************//**
145
Performs an execution step of an assignment statement node.
146
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
147
UNIV_INTERN
148
que_thr_t*
149
assign_step(
150
/*========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
151
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
152
{
153
	assign_node_t*	node;
154
155
	ut_ad(thr);
156
157
	node = thr->run_node;
158
	ut_ad(que_node_get_type(node) == QUE_NODE_ASSIGNMENT);
159
160
	/* Evaluate the value to assign */
161
162
	eval_exp(node->val);
163
164
	eval_node_copy_val(node->var->alias, node->val);
165
166
	thr->run_node = que_node_get_parent(node);
167
168
	return(thr);
169
}
170
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
171
/**********************************************************************//**
172
Performs an execution step of a for-loop node.
173
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
174
UNIV_INTERN
175
que_thr_t*
176
for_step(
177
/*=====*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
178
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
179
{
180
	for_node_t*	node;
181
	que_node_t*	parent;
182
	lint		loop_var_value;
183
184
	ut_ad(thr);
185
186
	node = thr->run_node;
187
188
	ut_ad(que_node_get_type(node) == QUE_NODE_FOR);
189
190
	parent = que_node_get_parent(node);
191
192
	if (thr->prev_node != parent) {
193
194
		/* Move to the next statement */
195
		thr->run_node = que_node_get_next(thr->prev_node);
196
197
		if (thr->run_node != NULL) {
198
199
			return(thr);
200
		}
201
202
		/* Increment the value of loop_var */
203
204
		loop_var_value = 1 + eval_node_get_int_val(node->loop_var);
205
	} else {
206
		/* Initialize the loop */
207
208
		eval_exp(node->loop_start_limit);
209
		eval_exp(node->loop_end_limit);
210
211
		loop_var_value = eval_node_get_int_val(node->loop_start_limit);
212
213
		node->loop_end_value
214
                  = (int) eval_node_get_int_val(node->loop_end_limit);
215
	}
216
217
	/* Check if we should do another loop */
218
219
	if (loop_var_value > node->loop_end_value) {
220
221
		/* Enough loops done */
222
223
		thr->run_node = parent;
224
	} else {
225
		eval_node_set_int_val(node->loop_var, loop_var_value);
226
227
		thr->run_node = node->stat_list;
228
	}
229
230
	return(thr);
231
}
232
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
233
/**********************************************************************//**
234
Performs an execution step of an exit statement node.
235
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
236
UNIV_INTERN
237
que_thr_t*
238
exit_step(
239
/*======*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
240
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
241
{
242
	exit_node_t*	node;
243
	que_node_t*	loop_node;
244
245
	ut_ad(thr);
246
247
	node = thr->run_node;
248
249
	ut_ad(que_node_get_type(node) == QUE_NODE_EXIT);
250
251
	/* Loops exit by setting thr->run_node as the loop node's parent, so
252
	find our containing loop node and get its parent. */
253
254
	loop_node = que_node_get_containing_loop_node(node);
255
256
	/* If someone uses an EXIT statement outside of a loop, this will
257
	trigger. */
258
	ut_a(loop_node);
259
260
	thr->run_node = que_node_get_parent(loop_node);
261
262
	return(thr);
263
}
264
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
265
/**********************************************************************//**
266
Performs an execution step of a return-statement node.
267
@return	query thread to run next or NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
268
UNIV_INTERN
269
que_thr_t*
270
return_step(
271
/*========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
272
	que_thr_t*	thr)	/*!< in: query thread */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
273
{
274
	return_node_t*	node;
275
	que_node_t*	parent;
276
277
	ut_ad(thr);
278
279
	node = thr->run_node;
280
281
	ut_ad(que_node_get_type(node) == QUE_NODE_RETURN);
282
283
	parent = node;
284
285
	while (que_node_get_type(parent) != QUE_NODE_PROC) {
286
287
		parent = que_node_get_parent(parent);
288
	}
289
290
	ut_a(parent);
291
292
	thr->run_node = que_node_get_parent(parent);
293
294
	return(thr);
295
}