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