Drizzled Public API Documentation

pars0sym.cc
1 /*****************************************************************************
2 
3 Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
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
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #include "pars0sym.h"
27 
28 #ifdef UNIV_NONINL
29 #include "pars0sym.ic"
30 #endif
31 
32 #include "mem0mem.h"
33 #include "data0type.h"
34 #include "data0data.h"
35 #ifndef PARS0GRM_H
36 # define PARS0GRM_H
37 # include "pars0grm.hh"
38 #endif
39 #include "pars0pars.h"
40 #include "que0que.h"
41 #include "eval0eval.h"
42 #include "row0sel.h"
43 
44 /******************************************************************/
47 UNIV_INTERN
48 sym_tab_t*
50 /*===========*/
51  mem_heap_t* heap)
52 {
53  sym_tab_t* sym_tab;
54 
55  sym_tab = static_cast<sym_tab_t *>(mem_heap_alloc(heap, sizeof(sym_tab_t)));
56 
57  UT_LIST_INIT(sym_tab->sym_list);
58  UT_LIST_INIT(sym_tab->func_node_list);
59 
60  sym_tab->heap = heap;
61 
62  return(sym_tab);
63 }
64 
65 /******************************************************************/
69 UNIV_INTERN
70 void
72 /*=================*/
73  sym_tab_t* sym_tab)
74 {
75  sym_node_t* sym;
76  func_node_t* func;
77 
78  sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
79 
80  while (sym) {
81  eval_node_free_val_buf(sym);
82 
83  if (sym->prefetch_buf) {
85  }
86 
87  if (sym->cursor_def) {
89  }
90 
91  sym = UT_LIST_GET_NEXT(sym_list, sym);
92  }
93 
94  func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
95 
96  while (func) {
97  eval_node_free_val_buf(func);
98 
99  func = UT_LIST_GET_NEXT(func_node_list, func);
100  }
101 }
102 
103 /******************************************************************/
106 #ifdef __cplusplus
107 extern "C"
108 #endif
109 UNIV_INTERN
110 sym_node_t*
112 /*================*/
113  sym_tab_t* sym_tab,
114  ulint val)
115 {
116  sym_node_t* node;
117  byte* data;
118 
119  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
120 
121  node->common.type = QUE_NODE_SYMBOL;
122 
123  node->resolved = TRUE;
124  node->token_type = SYM_LIT;
125 
126  node->indirection = NULL;
127 
128  dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
129 
130  data = static_cast<byte *>(mem_heap_alloc(sym_tab->heap, 4));
131  mach_write_to_4(data, val);
132 
133  dfield_set_data(&(node->common.val), data, 4);
134 
135  node->common.val_buf_size = 0;
136  node->prefetch_buf = NULL;
137  node->cursor_def = NULL;
138 
139  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
140 
141  node->sym_table = sym_tab;
142 
143  return(node);
144 }
145 
146 /******************************************************************/
149 #ifdef __cplusplus
150 extern "C"
151 #endif
152 UNIV_INTERN
153 sym_node_t*
155 /*================*/
156  sym_tab_t* sym_tab,
157  byte* str,
159  ulint len)
160 {
161  sym_node_t* node;
162  byte* data;
163 
164  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
165 
166  node->common.type = QUE_NODE_SYMBOL;
167 
168  node->resolved = TRUE;
169  node->token_type = SYM_LIT;
170 
171  node->indirection = NULL;
172 
173  dtype_set(dfield_get_type(&node->common.val),
174  DATA_VARCHAR, DATA_ENGLISH, 0);
175 
176  if (len) {
177  data = static_cast<byte *>(mem_heap_alloc(sym_tab->heap, len));
178  ut_memcpy(data, str, len);
179  } else {
180  data = NULL;
181  }
182 
183  dfield_set_data(&(node->common.val), data, len);
184 
185  node->common.val_buf_size = 0;
186  node->prefetch_buf = NULL;
187  node->cursor_def = NULL;
188 
189  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
190 
191  node->sym_table = sym_tab;
192 
193  return(node);
194 }
195 
196 /******************************************************************/
199 #ifdef __cplusplus
200 extern "C"
201 #endif
202 UNIV_INTERN
203 sym_node_t*
205 /*==================*/
206  sym_tab_t* sym_tab,
207  const char* name,
208  ulint* lit_type)
209 {
210  sym_node_t* node;
211  pars_bound_lit_t* blit;
212  ulint len = 0;
213 
214  blit = pars_info_get_bound_lit(sym_tab->info, name);
215  ut_a(blit);
216 
217  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
218 
219  node->common.type = QUE_NODE_SYMBOL;
220 
221  node->resolved = TRUE;
222  node->token_type = SYM_LIT;
223 
224  node->indirection = NULL;
225 
226  switch (blit->type) {
227  case DATA_FIXBINARY:
228  len = blit->length;
229  *lit_type = PARS_FIXBINARY_LIT;
230  break;
231 
232  case DATA_BLOB:
233  *lit_type = PARS_BLOB_LIT;
234  break;
235 
236  case DATA_VARCHAR:
237  *lit_type = PARS_STR_LIT;
238  break;
239 
240  case DATA_CHAR:
241  ut_a(blit->length > 0);
242 
243  len = blit->length;
244  *lit_type = PARS_STR_LIT;
245  break;
246 
247  case DATA_INT:
248  ut_a(blit->length > 0);
249  ut_a(blit->length <= 8);
250 
251  len = blit->length;
252  *lit_type = PARS_INT_LIT;
253  break;
254 
255  default:
256  ut_error;
257  }
258 
259  dtype_set(dfield_get_type(&node->common.val),
260  blit->type, blit->prtype, len);
261 
262  dfield_set_data(&(node->common.val), blit->address, blit->length);
263 
264  node->common.val_buf_size = 0;
265  node->prefetch_buf = NULL;
266  node->cursor_def = NULL;
267 
268  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
269 
270  node->sym_table = sym_tab;
271 
272  return(node);
273 }
274 
275 /******************************************************************/
278 #ifdef __cplusplus
279 extern "C"
280 #endif
281 UNIV_INTERN
282 sym_node_t*
284 /*=================*/
285  sym_tab_t* sym_tab)
286 {
287  sym_node_t* node;
288 
289  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
290 
291  node->common.type = QUE_NODE_SYMBOL;
292 
293  node->resolved = TRUE;
294  node->token_type = SYM_LIT;
295 
296  node->indirection = NULL;
297 
298  dfield_get_type(&node->common.val)->mtype = DATA_ERROR;
299 
300  dfield_set_null(&node->common.val);
301 
302  node->common.val_buf_size = 0;
303  node->prefetch_buf = NULL;
304  node->cursor_def = NULL;
305 
306  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
307 
308  node->sym_table = sym_tab;
309 
310  return(node);
311 }
312 
313 /******************************************************************/
316 #ifdef __cplusplus
317 extern "C"
318 #endif
319 UNIV_INTERN
320 sym_node_t*
322 /*===========*/
323  sym_tab_t* sym_tab,
324  byte* name,
325  ulint len)
326 {
327  sym_node_t* node;
328 
329  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
330 
331  node->common.type = QUE_NODE_SYMBOL;
332 
333  node->resolved = FALSE;
334  node->indirection = NULL;
335 
336  node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len);
337  node->name_len = len;
338 
339  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
340 
341  dfield_set_null(&node->common.val);
342 
343  node->common.val_buf_size = 0;
344  node->prefetch_buf = NULL;
345  node->cursor_def = NULL;
346 
347  node->sym_table = sym_tab;
348 
349  return(node);
350 }
351 
352 /******************************************************************/
355 #ifdef __cplusplus
356 extern "C"
357 #endif
358 UNIV_INTERN
359 sym_node_t*
361 /*===========*/
362  sym_tab_t* sym_tab,
363  const char* name)
364 {
365  sym_node_t* node;
366  pars_bound_id_t* bid;
367 
368  bid = pars_info_get_bound_id(sym_tab->info, name);
369  ut_a(bid);
370 
371  node = static_cast<sym_node_t *>(mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t)));
372 
373  node->common.type = QUE_NODE_SYMBOL;
374 
375  node->resolved = FALSE;
376  node->indirection = NULL;
377 
378  node->name = mem_heap_strdup(sym_tab->heap, bid->id);
379  node->name_len = strlen(node->name);
380 
381  UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
382 
383  dfield_set_null(&node->common.val);
384 
385  node->common.val_buf_size = 0;
386  node->prefetch_buf = NULL;
387  node->cursor_def = NULL;
388 
389  node->sym_table = sym_tab;
390 
391  return(node);
392 }