TizenRT Public API  v2.0 M2
arastorage.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /*
19  * Copyright (c) 2010, Swedish Institute of Computer Science
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. Neither the name of the Institute nor the names of its contributors
31  * may be used to endorse or promote products derived from this software
32  * without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
35  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
38  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  */
46 
66 #ifndef __ARASTORAGE_ARA_STORAGE_H
67 #define __ARASTORAGE_ARA_STORAGE_H
68 
69 /****************************************************************************
70  * Included Files
71  ****************************************************************************/
72 #include <stdbool.h>
73 #include <stdio.h>
74 #include <float.h>
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif /* __cplusplus */
79 
80 /****************************************************************************
81 * Pre-processor Definitions
82 ****************************************************************************/
83 #define INVALID_TUPLE (tuple_id_t)-1
84 #define INVALID_CURSOR_VALUE -1
85 
86 #define DB_ERROR(result_code) ((result_code) < DB_OK)
87 #define DB_SUCCESS(result_code) !DB_ERROR(result_code)
88 
89 /* We only accept value in the range of [DB_XXX_MIN + 1, MAX] */
90 #define DB_INT_MAX INT_MAX
91 #define DB_INT_MIN INT_MIN + 1
92 
93 #define DB_LONG_MAX LONG_MAX
94 #define DB_LONG_MIN LONG_MIN + 1
95 
96 #ifdef CONFIG_HAVE_DOUBLE
97 #define DB_DOUBLE_MAX DBL_MAX
98 #define DB_DOUBLE_MIN DBL_MIN + 1
99 #else
100 #define DB_DOUBLE_MAX FLT_MAX
101 #define DB_DOUBLE_MIN FLT_MIN + 1
102 #endif
103 
104 /* We consider that the least value in the range of each type is invalid */
105 #define DB_INT_ERROR INT_MIN
106 #define DB_LONG_ERROR LONG_MIN
107 #ifdef CONFIG_HAVE_DOUBLE
108 #define DB_DOUBLE_ERROR DBL_MIN
109 #else
110 #define DB_DOUBLE_ERROR FLT_MIN
111 #endif
112 
113 /****************************************************************************
114 * Public Type Definitions
115 ****************************************************************************/
116 #define DB_FINISHED_MSG "Iteration finished"
117 #define DB_OK_MSG "Operation succeeded"
118 #define DB_LIMIT_ERROR_MSG "Limit reached"
119 #define DB_ALLOCATION_ERROR_MSG "Allocation error"
120 #define DB_STORAGE_ERROR_MSG "Storage error"
121 #define DB_PARSING_ERROR_MSG "Parsing error"
122 #define DB_NAME_ERROR_MSG "Invalid name"
123 #define DB_RELATIONAL_ERROR_MSG "Semantic error"
124 #define DB_TYPE_ERROR_MSG "Type error"
125 #define DB_IMPLEMENTATION_ERROR_MSG "Implementation error"
126 #define DB_INDEX_ERROR_MSG "Index error"
127 #define DB_BUSY_ERROR_MSG "Busy with processing"
128 #define DB_INCONSISTENCY_ERROR_MSG "Inconsistent handle"
129 #define DB_ARGUMENT_ERROR_MSG "Invalid argument"
130 #define DB_FULL_ERROR_MSG "Tuple limit reached"
131 #define DB_CURSOR_ERROR_MSG "Cursor Error"
132 #define DB_UNKNOWN_ERROR_MSG "Unknown result code"
133 #define DB_EMPTY_CURSOR_ERROR_MSG "Empty Cursor"
134 
135 enum db_result_e {
136  DB_FINISHED = 3,
137  DB_GOT_ROW = 2,
138  DB_OK = 1,
139  DB_LIMIT_ERROR = -1,
140  DB_ALLOCATION_ERROR = -2,
141  DB_STORAGE_ERROR = -3,
142  DB_PARSING_ERROR = -4,
143  DB_NAME_ERROR = -5,
144  DB_RELATIONAL_ERROR = -6,
145  DB_TYPE_ERROR = -7,
146  DB_IMPLEMENTATION_ERROR = -8,
147  DB_INDEX_ERROR = -9,
148  DB_BUSY_ERROR = -10,
149  DB_INCONSISTENCY_ERROR = -11,
150  DB_ARGUMENT_ERROR = -12,
151  DB_FULL_ERROR = -13,
152  DB_CURSOR_ERROR = -14,
153  DB_EMPTY_CURSOR_ERROR = -15
154 };
155 
156 typedef enum db_result_e db_result_t;
157 
158 enum domain_e {
159  DOMAIN_UNSPECIFIED = 0,
160  DOMAIN_INT = 1,
161  DOMAIN_LONG = 2,
162  DOMAIN_STRING = 3,
163  DOMAIN_DOUBLE = 4
164 };
165 
166 typedef enum domain_e domain_t;
167 
168 
169 struct _db_handle_s;
170 typedef struct _db_handle_s db_handle_t;
171 
172 struct _db_cursor_s;
173 typedef struct _db_cursor_s db_cursor_t;
174 
175 typedef int db_storage_id_t;
176 
177 typedef uint32_t cursor_row_t;
178 
179 typedef uint32_t tuple_id_t;
180 
181 typedef uint8_t attribute_id_t;
182 
183 /****************************************************************************
184 * Public Variables
185 ****************************************************************************/
186 typedef int (*db_output_function_t)(const char *, ...);
187 
188 static db_output_function_t output = printf;
189 
190 /****************************************************************************
191 * Global Function Prototypes
192 ****************************************************************************/
193 
202 db_result_t db_init(void);
203 
212 db_result_t db_deinit(void);
213 
223 db_result_t db_exec(char *format);
224 
233 db_cursor_t *db_query(char *format);
234 
243 db_result_t db_cursor_free(db_cursor_t *cursor);
244 
253 const char *db_get_result_message(db_result_t code);
254 
263 db_result_t db_print_header(db_cursor_t *cursor);
264 
273 db_result_t db_print_tuple(db_cursor_t *cursor);
274 
284 db_result_t db_print_value(db_cursor_t *cursor, int attr_index);
285 
294 db_result_t cursor_move_first(db_cursor_t *cursor);
295 
304 db_result_t cursor_move_last(db_cursor_t *cursor);
305 
314 db_result_t cursor_move_next(db_cursor_t *cursor);
315 
324 db_result_t cursor_move_prev(db_cursor_t *cursor);
325 
335 db_result_t cursor_move_to(db_cursor_t *cursor, tuple_id_t row_id);
336 
345 bool cursor_is_first_row(db_cursor_t *cursor);
346 
355 bool cursor_is_last_row(db_cursor_t *cursor);
356 
365 cursor_row_t cursor_get_row(db_cursor_t *cursor);
366 
375 cursor_row_t cursor_get_count(db_cursor_t *cursor);
376 
386 domain_t cursor_get_attr_type(db_cursor_t *cursor, int attr_index);
387 
397 char *cursor_get_attr_name(db_cursor_t *cursor, int attr_index);
398 
408 attribute_id_t cursor_get_attr_index(db_cursor_t *cursor, const char *attr_name);
409 
420 int cursor_get_int_value(db_cursor_t *cursor, int attr_index);
421 
432 long cursor_get_long_value(db_cursor_t *cursor, int attr_index);
433 
434 #ifdef CONFIG_ARCH_FLOAT_H
435 
445 double cursor_get_double_value(db_cursor_t *cursor, int attr_index);
446 #endif
447 
457 unsigned char *cursor_get_string_value(db_cursor_t *cursor, int attr_index);
458 
459 #ifdef __cplusplus
460 }
461 #endif /* __cplusplus */
462  // end of AraStorage group
464 
465 #endif /* __ARASTORAGE_ARA_STORAGE_H */
cursor_row_t cursor_get_count(db_cursor_t *cursor)
get the number of rows of cursor
domain_t cursor_get_attr_type(db_cursor_t *cursor, int attr_index)
get type of attribute with specific index in cursor
db_result_t db_exec(char *format)
create or remove relations, attributes and indexes in arastorage
db_result_t cursor_move_last(db_cursor_t *cursor)
move current position of cursor to last row
bool cursor_is_last_row(db_cursor_t *cursor)
check whether current position of cursor is last row
db_result_t db_deinit(void)
de-initialize database&#39;s resources, it must be called when terminating arastorage ...
db_result_t cursor_move_next(db_cursor_t *cursor)
move current position of cursor to next row
db_result_t cursor_move_first(db_cursor_t *cursor)
move current position of cursor to first row
bool cursor_is_first_row(db_cursor_t *cursor)
check whether current position of cursor is first row
const char * db_get_result_message(db_result_t code)
get string corresponding to each result value of API
cursor_row_t cursor_get_row(db_cursor_t *cursor)
get current position of cursor
char * cursor_get_attr_name(db_cursor_t *cursor, int attr_index)
get name of attribute with specific index in cursor
db_result_t cursor_move_prev(db_cursor_t *cursor)
move current position of cursor to previous row
db_result_t db_print_tuple(db_cursor_t *cursor)
print the tuple data
unsigned char * cursor_get_string_value(db_cursor_t *cursor, int attr_index)
get value of attribute of which the type is DOMAIN_STRING with specific index in current row...
db_result_t cursor_move_to(db_cursor_t *cursor, tuple_id_t row_id)
move current position of cursor to specific row
attribute_id_t cursor_get_attr_index(db_cursor_t *cursor, const char *attr_name)
get index of attribute corresponding name in cursor
db_cursor_t * db_query(char *format)
process query of arastorage
db_result_t db_print_header(db_cursor_t *cursor)
print the name of relation and attributes
db_result_t db_init(void)
initialize database&#39;s resources, it must be called for using arastorage
db_result_t db_print_value(db_cursor_t *cursor, int attr_index)
print current row&#39;s data with specific attribute index
db_result_t db_cursor_free(db_cursor_t *cursor)
free allocated cursor data, it should be called before application terminated
int cursor_get_int_value(db_cursor_t *cursor, int attr_index)
get value of attribute of which the type is DOMAIN_INT with specific index in current row...
long cursor_get_long_value(db_cursor_t *cursor, int attr_index)
get value of attribute of which the type is DOMAIN_LONG with specific index in current row...