1
/*****************************************************************************
3
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
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.
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.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/eval0eval.ic
1
/******************************************************
21
2
SQL evaluator: evaluates simple data structures, like expressions, in
24
7
Created 12/29/1997 Heikki Tuuri
25
8
*******************************************************/
31
14
# include "pars0grm.h"
34
/*****************************************************************//**
17
/*********************************************************************
35
18
Evaluates a function node. */
40
func_node_t* func_node); /*!< in: function node */
41
/*****************************************************************//**
23
func_node_t* func_node); /* in: function node */
24
/*********************************************************************
42
25
Allocate a buffer from global dynamic memory for a value of a que_node.
43
26
NOTE that this memory must be explicitly freed when the query graph is
44
27
freed. If the node already has allocated buffer, that buffer is freed
45
28
here. NOTE that this is the only function where dynamic memory should be
46
allocated for a query node val field.
47
@return pointer to allocated buffer */
29
allocated for a query node val field. */
50
32
eval_node_alloc_val_buf(
51
33
/*====================*/
52
que_node_t* node, /*!< in: query graph node; sets the val field
34
/* out: pointer to allocated buffer */
35
que_node_t* node, /* in: query graph node; sets the val field
53
36
data field to point to the new buffer, and
54
37
len field equal to size */
55
ulint size); /*!< in: buffer size */
58
/*****************************************************************//**
59
Allocates a new buffer if needed.
60
@return pointer to buffer */
38
ulint size); /* in: buffer size */
41
/*********************************************************************
42
Allocates a new buffer if needed. */
63
45
eval_node_ensure_val_buf(
64
46
/*=====================*/
65
que_node_t* node, /*!< in: query graph node; sets the val field
47
/* out: pointer to buffer */
48
que_node_t* node, /* in: query graph node; sets the val field
66
49
data field to point to the new buffer, and
67
50
len field equal to size */
68
ulint size) /*!< in: buffer size */
51
ulint size) /* in: buffer size */
86
/*****************************************************************//**
69
/*********************************************************************
87
70
Evaluates a symbol table symbol. */
92
sym_node_t* sym_node) /*!< in: symbol table node */
75
sym_node_t* sym_node) /* in: symbol table node */
95
78
ut_ad(que_node_get_type(sym_node) == QUE_NODE_SYMBOL);
106
/*****************************************************************//**
89
/*********************************************************************
107
90
Evaluates an expression. */
112
que_node_t* exp_node) /*!< in: expression */
95
que_node_t* exp_node) /* in: expression */
114
97
if (que_node_get_type(exp_node) == QUE_NODE_SYMBOL) {
121
104
eval_func(exp_node);
124
/*****************************************************************//**
107
/*********************************************************************
125
108
Sets an integer value as the value of an expression node. */
128
111
eval_node_set_int_val(
129
112
/*==================*/
130
que_node_t* node, /*!< in: expression node */
131
lint val) /*!< in: value to set */
113
que_node_t* node, /* in: expression node */
114
lint val) /* in: value to set */
133
116
dfield_t* dfield;
146
129
mach_write_to_4(data, (ulint)val);
149
/*****************************************************************//**
150
Gets an integer non-SQL null value from an expression node.
151
@return integer value */
132
/*********************************************************************
133
Gets an integer non-SQL null value from an expression node. */
154
136
eval_node_get_int_val(
155
137
/*==================*/
156
que_node_t* node) /*!< in: expression node */
138
/* out: integer value */
139
que_node_t* node) /* in: expression node */
158
141
dfield_t* dfield;
164
147
return((int)mach_read_from_4(dfield_get_data(dfield)));
167
/*****************************************************************//**
168
Gets a iboolean value from a query node.
169
@return iboolean value */
150
/*********************************************************************
151
Gets a iboolean value from a query node. */
172
154
eval_node_get_ibool_val(
173
155
/*====================*/
174
que_node_t* node) /*!< in: query graph node */
156
/* out: iboolean value */
157
que_node_t* node) /* in: query graph node */
176
159
dfield_t* dfield;
185
168
return(mach_read_from_1(data));
188
/*****************************************************************//**
171
/*********************************************************************
189
172
Sets a iboolean value as the value of a function node. */
192
175
eval_node_set_ibool_val(
193
176
/*====================*/
194
func_node_t* func_node, /*!< in: function node */
195
ibool val) /*!< in: value to set */
177
func_node_t* func_node, /* in: function node */
178
ibool val) /* in: value to set */
197
180
dfield_t* dfield;
212
195
mach_write_to_1(data, val);
215
/*****************************************************************//**
198
/*********************************************************************
216
199
Copies a binary string value as the value of a query graph node. Allocates a
217
200
new buffer if necessary. */
220
203
eval_node_copy_and_alloc_val(
221
204
/*=========================*/
222
que_node_t* node, /*!< in: query graph node */
223
const byte* str, /*!< in: binary string */
224
ulint len) /*!< in: string length or UNIV_SQL_NULL */
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 */
236
219
ut_memcpy(data, str, len);
239
/*****************************************************************//**
222
/*********************************************************************
240
223
Copies a query node value to another node. */
243
226
eval_node_copy_val(
244
227
/*===============*/
245
que_node_t* node1, /*!< in: node to copy to */
246
que_node_t* node2) /*!< in: node to copy from */
228
que_node_t* node1, /* in: node to copy to */
229
que_node_t* node2) /* in: node to copy from */
248
231
dfield_t* dfield2;