1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#ifndef _SQL_SEMANTIC_H_
10#define _SQL_SEMANTIC_H_
11
12#include "sql_list.h"
13#include "sql_symbol.h"
14#include "sql_parser.h"
15
16typedef struct exp_kind_t {
17 bte type;
18 bte card;
19 bit reduce;
20} exp_kind;
21
22extern sql_schema *cur_schema(mvc *sql);
23extern sql_schema *tmp_schema(mvc *sql);
24extern char *qname_schema(dlist *qname);
25extern char *qname_table(dlist *qname);
26extern char *qname_catalog(dlist *qname);
27#define qname_module(qname) qname_schema(qname)
28#define qname_fname(qname) qname_table(qname)
29
30extern sql_subtype *supertype(sql_subtype *super, sql_subtype *r, sql_subtype *i);
31
32typedef enum {
33 type_set, /* set operations have very limiting coersion rules */
34 type_equal,
35 type_equal_no_any,
36 type_cast /* also truncate */
37} check_type;
38
39/* literals in the parser are kept outside of the abstract syntax tree
40 in the arg array, this to allow for more reuse of cached queries */
41
42extern atom *sql_add_arg(mvc *sql, atom *v);
43extern atom *sql_set_arg(mvc *sql, int nr, atom *v);
44extern atom *sql_bind_arg(mvc *sql, int nr);
45extern void sql_destroy_args(mvc *sql); /* used in backend */
46
47/* SQL's parameters '?' (in prepare statements) and parameters of sql
48 * functions and procedures are kept in the param list. */
49
50extern void sql_add_param(mvc *sql, const char *name, sql_subtype *st);
51extern sql_arg *sql_bind_param(mvc *sql, const char *name);
52/* once the type of the '?' parameters is known it's set using the set_type
53 * function */
54extern int set_type_param(mvc *sql, sql_subtype *type, int nr);
55extern void sql_destroy_params(mvc *sql); /* used in backend */
56
57extern char *symbol2string(mvc *sql, symbol *s, int expression, char **err);
58extern char *dlist2string(mvc *sql, dlist *s, int expression, char **err);
59
60extern char * toUpperCopy(char *dest, const char *src);
61
62#endif /*_SQL_SEMANTIC_H_*/
63
64