Contiki-NG
Loading...
Searching...
No Matches
aql.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, Swedish Institute of Computer Science
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \file
35 * Definitions and declarations for AQL, the Antelope Query Language.
36 * \author
37 * Nicolas Tsiftes <nvt@sics.se>
38 */
39
40#ifndef AQL_H
41#define AQL_H
42
43#include "db-options.h"
44#include "index.h"
45#include "relation.h"
46#include "result.h"
47
48enum aql_status {
49 OK = 2,
50 SYNTAX_ERROR = 3,
51 INVALID_TOKEN = 9,
52 PLE_ERROR = 12
53};
54typedef enum aql_status aql_status_t;
55#define AQL_ERROR(x) ((x) >= 3)
56
57enum token {
58 END = 0,
59 LEFT_PAREN = 1,
60 RIGHT_PAREN = 2,
61 COMMA = 3,
62 EQUAL = 4,
63 GT = 5,
64 LT = 6,
65 DOT = 7,
66 ADD = 8,
67 SUB = 9,
68 MUL = 10,
69 DIV = 11,
70 COMMENT = 12,
71 GEQ = 13,
72 LEQ = 14,
73 NOT_EQUAL = 15,
74 ASSIGN = 16,
75 OR = 17,
76 IS = 18,
77 ON = 19,
78 IN = 20,
79 AND = 21,
80 NOT = 22,
81 SUM = 23,
82 MAX = 24,
83 MIN = 25,
84 INT = 26,
85 INTO = 27,
86 FROM = 28,
87 MEAN = 29,
88 JOIN = 30,
89 LONG = 31,
90 TYPE = 32,
91 WHERE = 33,
92 COUNT = 34,
93 INDEX = 35,
94 INSERT = 36,
95 SELECT = 37,
96 REMOVE = 38,
97 CREATE = 39,
98 MEDIAN = 40,
99 DOMAIN = 41,
100 STRING = 42,
101 INLINE = 43,
102 PROJECT = 44,
103 MAXHEAP = 45,
104 MEMHASH = 46,
105 RELATION = 47,
106 ATTRIBUTE = 48,
107
108 INTEGER_VALUE = 251,
109 FLOAT_VALUE = 252,
110 STRING_VALUE = 253,
111 IDENTIFIER = 254,
112 NONE = 255
113};
114
115typedef enum token token_t;
116
117typedef char value_t[DB_MAX_ELEMENT_SIZE];
118
119struct lexer {
120 const char *input;
121 const char *prev_pos;
122 token_t *token;
123 value_t *value;
124};
125
126typedef struct lexer lexer_t;
127
128enum aql_aggregator {
129 AQL_NONE = 0,
130 AQL_COUNT = 1,
131 AQL_SUM = 2,
132 AQL_MIN = 3,
133 AQL_MAX = 4,
134 AQL_MEAN = 5,
135 AQL_MEDIAN = 6
136};
137
138typedef enum aql_aggregator aql_aggregator_t;
139
140struct aql_attribute {
141 domain_t domain;
142 uint8_t element_size;
143 uint8_t flags;
144 char name[ATTRIBUTE_NAME_LENGTH + 1];
145};
146typedef struct aql_attribute aql_attribute_t;
147
148struct aql_adt {
149 char relations[AQL_RELATION_LIMIT][RELATION_NAME_LENGTH + 1];
150 aql_attribute_t attributes[AQL_ATTRIBUTE_LIMIT];
151 aql_aggregator_t aggregators[AQL_ATTRIBUTE_LIMIT];
152 attribute_value_t values[AQL_ATTRIBUTE_LIMIT];
153 index_type_t index_type;
154 uint8_t relation_count;
155 uint8_t attribute_count;
156 uint8_t value_count;
157 uint8_t optype;
158 uint8_t flags;
159 void *lvm_instance;
160};
161typedef struct aql_adt aql_adt_t;
162
163#define AQL_TYPE_NONE 0
164#define AQL_TYPE_SELECT 1
165#define AQL_TYPE_INSERT 2
166#define AQL_TYPE_UPDATE 3
167#define AQL_TYPE_DROP 4
168#define AQL_TYPE_DELETE 5
169#define AQL_TYPE_RENAME 6
170#define AQL_TYPE_CREATE_ATTRIBUTE 7
171#define AQL_TYPE_CREATE_INDEX 8
172#define AQL_TYPE_CREATE_RELATION 9
173#define AQL_TYPE_REMOVE_ATTRIBUTE 10
174#define AQL_TYPE_REMOVE_INDEX 11
175#define AQL_TYPE_REMOVE_RELATION 12
176#define AQL_TYPE_REMOVE_TUPLES 13
177#define AQL_TYPE_JOIN 14
178
179#define AQL_FLAG_AGGREGATE 1
180#define AQL_FLAG_ASSIGN 2
181#define AQL_FLAG_INVERSE_LOGIC 4
182
183#define AQL_CLEAR(adt) aql_clear(adt)
184#define AQL_SET_TYPE(adt, type) (((adt))->optype = (type))
185#define AQL_GET_TYPE(adt) ((adt)->optype)
186#define AQL_SET_INDEX_TYPE(adt, type) ((adt)->index_type = (type))
187#define AQL_GET_INDEX_TYPE(adt) ((adt)->index_type)
188
189#define AQL_SET_FLAG(adt, flag) (((adt)->flags) |= (flag))
190#define AQL_GET_FLAGS(adt) ((adt)->flags)
191#define AQL_RELATION_COUNT(adt) ((adt)->relation_count)
192#define AQL_ADD_RELATION(adt, name) \
193 aql_add_relation(adt, name)
194#define AQL_ADD_ATTRIBUTE(adt, attr, dom, size) \
195 aql_add_attribute(adt, attr, dom, size, 0)
196#define AQL_ADD_PROCESSING_ATTRIBUTE(adt, attr) \
197 aql_add_attribute((adt), (attr), DOMAIN_UNSPECIFIED, 0, 1)
198#define AQL_ADD_AGGREGATE(adt, function, attr) \
199 do { \
200 (adt)->aggregators[(adt)->attribute_count] = (function); \
201 aql_add_attribute((adt), (attr), DOMAIN_UNSPECIFIED, 0, 0); \
202 } while(0)
203#define AQL_ATTRIBUTE_COUNT(adt) ((adt)->attribute_count)
204#define AQL_SET_CONDITION(adt, cond) ((adt)->lvm_instance = (cond))
205#define AQL_ADD_VALUE(adt, domain, value) \
206 aql_add_value((adt), (domain), (value))
207
208int lexer_start(lexer_t *, char *, token_t *, value_t *);
209int lexer_next(lexer_t *);
210void lexer_rewind(lexer_t *);
211
212void aql_clear(aql_adt_t *adt);
213aql_status_t aql_parse(aql_adt_t *adt, char *query_string);
214db_result_t aql_add_relation(aql_adt_t *adt, const char *name);
215db_result_t aql_add_attribute(aql_adt_t *adt, char *name,
216 domain_t domain, unsigned element_size,
217 int processed_only);
218db_result_t aql_add_value(aql_adt_t *adt, domain_t domain, void *value);
219db_result_t db_query(db_handle_t *handle, const char *format, ...);
220db_result_t db_process(db_handle_t *handle);
221
222#endif /* !AQL_H */
Database configuration options.
Declarations for the result acquisition API.