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_TYPES_H
10#define SQL_TYPES_H
11
12#include "sql_mem.h"
13#include "sql_list.h"
14#include "sql_string.h"
15#include "sql_catalog.h"
16#include "sql_storage.h"
17#include "stream.h"
18
19extern list *aliases;
20extern list *types;
21extern list *aggrs;
22extern list *funcs;
23
24extern int bits2digits(int b);
25extern int digits2bits(int d);
26
27extern int sql_type_convert(int form, int to); /* return 1, convert possible but it's a down cast, 2 convert possible can be done savely */
28extern bool is_commutative(const char *fnm); /* return true if commutative */
29
30extern char *sql_bind_alias(const char *alias);
31
32extern int sql_find_subtype(sql_subtype *res, const char *name, unsigned int digits, unsigned int scale);
33extern sql_subtype *sql_find_numeric(sql_subtype *r, int localtype, unsigned int digits);
34
35extern sql_subtype *sql_bind_subtype(sql_allocator *sa, const char *name, unsigned int digits, unsigned int scale);
36extern sql_subtype *sql_bind_localtype(const char *name);
37extern sql_subtype *sql_create_subtype(sql_allocator *sa, sql_type *t, unsigned int s, unsigned int d);
38extern void sql_init_subtype(sql_subtype *res, sql_type *t, unsigned int digits, unsigned int scale);
39extern char *sql_subtype_string(sql_subtype *t);
40
41extern int type_cmp(sql_type *t1, sql_type *t2);
42extern int subtype_cmp(sql_subtype *t1, sql_subtype *t2);
43extern int arg_subtype_cmp(sql_arg *a, sql_subtype *t);
44extern int is_subtype(sql_subtype *t1, sql_subtype *t2);
45extern char *subtype2string(sql_subtype *t);
46extern char *subtype2string2(sql_subtype *tpe);
47
48extern sql_arg *sql_create_arg(sql_allocator *sa, const char *name, sql_subtype *t, char inout);
49extern sql_arg *arg_dup(sql_allocator *sa, sql_arg *a);
50
51extern sql_subaggr *sql_bind_aggr(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *type);
52extern sql_subaggr *sql_bind_aggr_(sql_allocator *sa, sql_schema *s, const char *name, list *types);
53extern sql_subaggr *sql_bind_member_aggr(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp, int nrargs);
54extern sql_subaggr *sql_find_aggr(sql_allocator *sa, sql_schema *s, const char *name);
55extern int subaggr_cmp( sql_subaggr *a1, sql_subaggr *a2);
56
57extern int subfunc_cmp( sql_subfunc *f1, sql_subfunc *f2);
58extern sql_subfunc *sql_find_func_by_name(sql_allocator *sa, sql_schema *s, const char *name, int nrargs, sql_ftype type);
59extern sql_subfunc *sql_find_func(sql_allocator *sa, sql_schema *s, const char *name, int nrargs, sql_ftype type, sql_subfunc *prev);
60extern list *sql_find_funcs(sql_allocator *sa, sql_schema *s, const char *name, int nrargs, sql_ftype type);
61extern sql_subfunc *sql_bind_member(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp, int nrargs, sql_subfunc *prev);
62extern sql_subfunc *sql_bind_func(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp1, sql_subtype *tp2, sql_ftype type);
63extern sql_subfunc *sql_bind_func3(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp1, sql_subtype *tp2, sql_subtype *tp3, sql_ftype type);
64extern sql_subfunc *sql_bind_func_result(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp1, sql_subtype *tp2, sql_subtype *res);
65extern sql_subfunc *sql_bind_func_result3(sql_allocator *sa, sql_schema *s, const char *name, sql_subtype *tp1, sql_subtype *tp2, sql_subtype *tp3, sql_subtype *res);
66
67extern sql_subfunc *sql_bind_func_(sql_allocator *sa, sql_schema *s, const char *name, list *ops, sql_ftype type);
68
69extern sql_subfunc* sql_dup_subfunc(sql_allocator *sa, sql_func *f, list *ops, sql_subtype *member);
70
71extern char *sql_func_imp(sql_func *f);
72extern char *sql_func_mod(sql_func *f);
73extern int is_sqlfunc(sql_func *f);
74
75extern void types_init(sql_allocator *sa, int debug);
76
77#endif /* SQL_TYPES_H */
78