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 | #include "monetdb_config.h" |
10 | #include "sql_relation.h" |
11 | #include "rel_prop.h" |
12 | |
13 | prop * |
14 | prop_create( sql_allocator *sa, rel_prop kind, prop *pre ) |
15 | { |
16 | prop *p = SA_NEW(sa, prop); |
17 | |
18 | p->kind = kind; |
19 | p->value = 0; |
20 | p->p = pre; |
21 | return p; |
22 | } |
23 | |
24 | prop * |
25 | prop_copy( sql_allocator *sa, prop *p ) |
26 | { |
27 | prop *np = NULL; |
28 | |
29 | for(; p; p = p->p) { |
30 | np = prop_create(sa, p->kind, np); |
31 | np->value = p->value; |
32 | } |
33 | return np; |
34 | } |
35 | |
36 | prop * |
37 | prop_remove( prop *plist, prop *p ) |
38 | { |
39 | prop *op = plist; |
40 | |
41 | if (plist == p) |
42 | return p->p; |
43 | for(; op; op = op->p) { |
44 | if (op->p == p) { |
45 | op->p = p->p; |
46 | break; |
47 | } |
48 | } |
49 | return plist; |
50 | } |
51 | |
52 | prop * |
53 | find_prop( prop *p, rel_prop kind) |
54 | { |
55 | while(p) { |
56 | if (p->kind == kind) |
57 | return p; |
58 | p = p->p; |
59 | } |
60 | return p; |
61 | } |
62 | |
63 | const char * |
64 | propkind2string( prop *p) |
65 | { |
66 | switch(p->kind) { |
67 | #define PT(TYPE) case PROP_##TYPE : return #TYPE |
68 | PT(COUNT); |
69 | PT(JOINIDX); |
70 | PT(HASHIDX); |
71 | PT(SORTIDX); |
72 | PT(HASHCOL); |
73 | PT(FETCH); |
74 | PT(REMOTE); |
75 | PT(USED); |
76 | PT(DISTRIBUTE); |
77 | } |
78 | return "UNKNOWN" ; |
79 | } |
80 | |
81 | char * |
82 | propvalue2string( prop *p) |
83 | { |
84 | char buf [BUFSIZ]; |
85 | |
86 | if (p->value) { |
87 | switch(p->kind) { |
88 | case PROP_JOINIDX: { |
89 | sql_idx *i = p->value; |
90 | |
91 | snprintf(buf, BUFSIZ, "%s.%s.%s" , i->t->s->base.name, i->t->base.name, i->base.name); |
92 | return _STRDUP(buf); |
93 | } |
94 | case PROP_REMOTE: { |
95 | char *uri = p->value; |
96 | |
97 | return _STRDUP(uri); |
98 | } |
99 | default: |
100 | break; |
101 | } |
102 | } |
103 | return _STRDUP("" ); |
104 | } |
105 | |