1
/******************************************************
2
SQL evaluator: evaluates simple data structures, like expressions, in
7
Created 12/29/1997 Heikki Tuuri
8
*******************************************************/
14
# include "pars0grm.h"
17
/*********************************************************************
18
Evaluates a function node. */
23
func_node_t* func_node); /* in: function node */
24
/*********************************************************************
25
Allocate a buffer from global dynamic memory for a value of a que_node.
26
NOTE that this memory must be explicitly freed when the query graph is
27
freed. If the node already has allocated buffer, that buffer is freed
28
here. NOTE that this is the only function where dynamic memory should be
29
allocated for a query node val field. */
32
eval_node_alloc_val_buf(
33
/*====================*/
34
/* out: pointer to allocated buffer */
35
que_node_t* node, /* in: query graph node; sets the val field
36
data field to point to the new buffer, and
37
len field equal to size */
38
ulint size); /* in: buffer size */
41
/*********************************************************************
42
Allocates a new buffer if needed. */
45
eval_node_ensure_val_buf(
46
/*=====================*/
47
/* out: pointer to buffer */
48
que_node_t* node, /* in: query graph node; sets the val field
49
data field to point to the new buffer, and
50
len field equal to size */
51
ulint size) /* in: buffer size */
56
dfield = que_node_get_val(node);
57
dfield_set_len(dfield, size);
59
data = dfield_get_data(dfield);
61
if (!data || que_node_get_val_buf_size(node) < size) {
63
data = eval_node_alloc_val_buf(node, size);
69
/*********************************************************************
70
Evaluates a symbol table symbol. */
75
sym_node_t* sym_node) /* in: symbol table node */
78
ut_ad(que_node_get_type(sym_node) == QUE_NODE_SYMBOL);
80
if (sym_node->indirection) {
81
/* The symbol table node is an alias for a variable or a
84
dfield_copy_data(que_node_get_val(sym_node),
85
que_node_get_val(sym_node->indirection));
89
/*********************************************************************
90
Evaluates an expression. */
95
que_node_t* exp_node) /* in: expression */
97
if (que_node_get_type(exp_node) == QUE_NODE_SYMBOL) {
99
eval_sym((sym_node_t*)exp_node);
107
/*********************************************************************
108
Sets an integer value as the value of an expression node. */
111
eval_node_set_int_val(
112
/*==================*/
113
que_node_t* node, /* in: expression node */
114
lint val) /* in: value to set */
119
dfield = que_node_get_val(node);
121
data = dfield_get_data(dfield);
124
data = eval_node_alloc_val_buf(node, 4);
127
ut_ad(dfield_get_len(dfield) == 4);
129
mach_write_to_4(data, (ulint)val);
132
/*********************************************************************
133
Gets an integer non-SQL null value from an expression node. */
136
eval_node_get_int_val(
137
/*==================*/
138
/* out: integer value */
139
que_node_t* node) /* in: expression node */
143
dfield = que_node_get_val(node);
145
ut_ad(dfield_get_len(dfield) == 4);
147
return((int)mach_read_from_4(dfield_get_data(dfield)));
150
/*********************************************************************
151
Gets a iboolean value from a query node. */
154
eval_node_get_ibool_val(
155
/*====================*/
156
/* out: iboolean value */
157
que_node_t* node) /* in: query graph node */
162
dfield = que_node_get_val(node);
164
data = dfield_get_data(dfield);
168
return(mach_read_from_1(data));
171
/*********************************************************************
172
Sets a iboolean value as the value of a function node. */
175
eval_node_set_ibool_val(
176
/*====================*/
177
func_node_t* func_node, /* in: function node */
178
ibool val) /* in: value to set */
183
dfield = que_node_get_val(func_node);
185
data = dfield_get_data(dfield);
188
/* Allocate 1 byte to hold the value */
190
data = eval_node_alloc_val_buf(func_node, 1);
193
ut_ad(dfield_get_len(dfield) == 1);
195
mach_write_to_1(data, val);
198
/*********************************************************************
199
Copies a binary string value as the value of a query graph node. Allocates a
200
new buffer if necessary. */
203
eval_node_copy_and_alloc_val(
204
/*=========================*/
205
que_node_t* node, /* in: query graph node */
206
const byte* str, /* in: binary string */
207
ulint len) /* in: string length or UNIV_SQL_NULL */
211
if (len == UNIV_SQL_NULL) {
212
dfield_set_len(que_node_get_val(node), len);
217
data = eval_node_ensure_val_buf(node, len);
219
ut_memcpy(data, str, len);
222
/*********************************************************************
223
Copies a query node value to another node. */
228
que_node_t* node1, /* in: node to copy to */
229
que_node_t* node2) /* in: node to copy from */
233
dfield2 = que_node_get_val(node2);
235
eval_node_copy_and_alloc_val(node1, dfield_get_data(dfield2),
236
dfield_get_len(dfield2));