Contiki-NG
relation.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
30/**
31 * \file relation.h
32 * \author
33 * Nicolas Tsiftes <nvt@sics.se>
34 */
35
36#ifndef RELATION_H
37#define RELATION_H
38
39#include <stdint.h>
40#include <stdlib.h>
41
42#include "lib/list.h"
43
44#include "attribute.h"
45#include "db-options.h"
46#include "db-types.h"
47
48typedef uint32_t tuple_id_t;
49#define INVALID_TUPLE (tuple_id_t)-1
50
51typedef enum db_direction {
52 DB_MEMORY = 0,
53 DB_STORAGE = 1
54} db_direction_t;
55
56#define RELATION_HAS_TUPLES(rel) ((rel)->tuple_storage >= 0)
57
58/*
59 * A relation consists of a name, a set of domains, a set of indexes,
60 * and a set of keys. Each relation must have a primary key.
61 */
62struct relation {
63 struct relation *next;
64 LIST_STRUCT(attributes);
65 attribute_t *primary_key;
66 size_t row_length;
67 attribute_id_t attribute_count;
68 tuple_id_t cardinality;
69 tuple_id_t next_row;
70 db_storage_id_t tuple_storage;
71 db_direction_t dir;
72 uint8_t references;
73 char name[RELATION_NAME_LENGTH + 1];
74 char tuple_filename[RELATION_NAME_LENGTH + 1];
75};
76
77typedef struct relation relation_t;
78
79/* API for relations. */
80db_result_t relation_init(void);
81db_result_t relation_process_remove(void *);
82db_result_t relation_process_select(void *);
83db_result_t relation_process_join(void *);
84relation_t *relation_load(char *);
85db_result_t relation_release(relation_t *);
86relation_t *relation_create(char *, db_direction_t);
87db_result_t relation_rename(char *, char *);
88attribute_t *relation_attribute_add(relation_t *, db_direction_t, char *,
89 domain_t, size_t);
90attribute_t *relation_attribute_get(relation_t *, char *);
91db_result_t relation_get_value(relation_t *, attribute_t *,
92 unsigned char *, attribute_value_t *);
93db_result_t relation_attribute_remove(relation_t *, char *);
94db_result_t relation_set_primary_key(relation_t *, char *);
95db_result_t relation_remove(char *, int);
96db_result_t relation_insert(relation_t *, attribute_value_t *);
97db_result_t relation_select(void *, relation_t *, void *);
98db_result_t relation_join(void *, void *);
99tuple_id_t relation_cardinality(relation_t *);
100
101#endif /* RELATION_H */
Definitions for attributes.
Database configuration options.
#define LIST_STRUCT(name)
Declare a linked list inside a structure declaraction.
Definition: list.h:111
Linked list manipulation routines.