Tizen RT Public API  v1.1 D4
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 * Pre-processor Definitions
77 ****************************************************************************/
78 #define INVALID_TUPLE (tuple_id_t)-1
79 #define INVALID_CURSOR_VALUE -1
80 
81 #define DB_ERROR(result_code) ((result_code) < DB_OK)
82 #define DB_SUCCESS(result_code) !DB_ERROR(result_code)
83 
84 /* We only accept value in the range of [DB_XXX_MIN + 1, MAX] */
85 #define DB_INT_MAX INT_MAX
86 #define DB_INT_MIN INT_MIN + 1
87 
88 #define DB_LONG_MAX LONG_MAX
89 #define DB_LONG_MIN LONG_MIN + 1
90 
91 #ifdef CONFIG_HAVE_DOUBLE
92 #define DB_DOUBLE_MAX DBL_MAX
93 #define DB_DOUBLE_MIN DBL_MIN + 1
94 #else
95 #define DB_DOUBLE_MAX FLT_MAX
96 #define DB_DOUBLE_MIN FLT_MIN + 1
97 #endif
98 
99 /* We consider that the least value in the range of each type is invalid */
100 #define DB_INT_ERROR INT_MIN
101 #define DB_LONG_ERROR LONG_MIN
102 #ifdef CONFIG_HAVE_DOUBLE
103 #define DB_DOUBLE_ERROR DBL_MIN
104 #else
105 #define DB_DOUBLE_ERROR FLT_MIN
106 #endif
107 
108 /****************************************************************************
109 * Public Type Definitions
110 ****************************************************************************/
111 #define DB_FINISHED_MSG "Iteration finished"
112 #define DB_OK_MSG "Operation succeeded"
113 #define DB_LIMIT_ERROR_MSG "Limit reached"
114 #define DB_ALLOCATION_ERROR_MSG "Allocation error"
115 #define DB_STORAGE_ERROR_MSG "Storage error"
116 #define DB_PARSING_ERROR_MSG "Parsing error"
117 #define DB_NAME_ERROR_MSG "Invalid name"
118 #define DB_RELATIONAL_ERROR_MSG "Semantic error"
119 #define DB_TYPE_ERROR_MSG "Type error"
120 #define DB_IMPLEMENTATION_ERROR_MSG "Implementation error"
121 #define DB_INDEX_ERROR_MSG "Index error"
122 #define DB_BUSY_ERROR_MSG "Busy with processing"
123 #define DB_INCONSISTENCY_ERROR_MSG "Inconsistent handle"
124 #define DB_ARGUMENT_ERROR_MSG "Invalid argument"
125 #define DB_FULL_ERROR_MSG "Tuple limit reached"
126 #define DB_CURSOR_ERROR_MSG "Cursor Error"
127 #define DB_UNKNOWN_ERROR_MSG "Unknown result code"
128 #define DB_EMPTY_CURSOR_ERROR_MSG "Empty Cursor"
129 
130 enum db_result_e {
131  DB_FINISHED = 3,
132  DB_GOT_ROW = 2,
133  DB_OK = 1,
134  DB_LIMIT_ERROR = -1,
135  DB_ALLOCATION_ERROR = -2,
136  DB_STORAGE_ERROR = -3,
137  DB_PARSING_ERROR = -4,
138  DB_NAME_ERROR = -5,
139  DB_RELATIONAL_ERROR = -6,
140  DB_TYPE_ERROR = -7,
141  DB_IMPLEMENTATION_ERROR = -8,
142  DB_INDEX_ERROR = -9,
143  DB_BUSY_ERROR = -10,
144  DB_INCONSISTENCY_ERROR = -11,
145  DB_ARGUMENT_ERROR = -12,
146  DB_FULL_ERROR = -13,
147  DB_CURSOR_ERROR = -14,
148  DB_EMPTY_CURSOR_ERROR = -15
149 };
150 
151 typedef enum db_result_e db_result_t;
152 
153 enum domain_e {
154  DOMAIN_UNSPECIFIED = 0,
155  DOMAIN_INT = 1,
156  DOMAIN_LONG = 2,
157  DOMAIN_STRING = 3,
158  DOMAIN_DOUBLE = 4
159 };
160 
161 typedef enum domain_e domain_t;
162 
163 
164 struct _db_handle_s;
165 typedef struct _db_handle_s db_handle_t;
166 
167 struct _db_cursor_s;
168 typedef struct _db_cursor_s db_cursor_t;
169 
170 typedef int db_storage_id_t;
171 
172 typedef uint32_t cursor_row_t;
173 
174 typedef uint32_t tuple_id_t;
175 
176 typedef uint8_t attribute_id_t;
177 
178 /****************************************************************************
179 * Public Variables
180 ****************************************************************************/
181 typedef int (*db_output_function_t)(const char *, ...);
182 
183 static db_output_function_t output = printf;
184 
185 /****************************************************************************
186 * Global Function Prototypes
187 ****************************************************************************/
188 
197 db_result_t db_init(void);
198 
207 db_result_t db_deinit(void);
208 
218 db_result_t db_exec(char *format);
219 
228 db_cursor_t *db_query(char *format);
229 
238 db_result_t db_cursor_free(db_cursor_t *cursor);
239 
248 const char *db_get_result_message(db_result_t code);
249 
258 db_result_t db_print_header(db_cursor_t *cursor);
259 
268 db_result_t db_print_tuple(db_cursor_t *cursor);
269 
279 db_result_t db_print_value(db_cursor_t *cursor, int attr_index);
280 
289 db_result_t cursor_move_first(db_cursor_t *cursor);
290 
299 db_result_t cursor_move_last(db_cursor_t *cursor);
300 
309 db_result_t cursor_move_next(db_cursor_t *cursor);
310 
319 db_result_t cursor_move_prev(db_cursor_t *cursor);
320 
330 db_result_t cursor_move_to(db_cursor_t *cursor, tuple_id_t row_id);
331 
340 bool cursor_is_first_row(db_cursor_t *cursor);
341 
350 bool cursor_is_last_row(db_cursor_t *cursor);
351 
360 cursor_row_t cursor_get_row(db_cursor_t *cursor);
361 
370 cursor_row_t cursor_get_count(db_cursor_t *cursor);
371 
381 domain_t cursor_get_attr_type(db_cursor_t *cursor, int attr_index);
382 
392 char *cursor_get_attr_name(db_cursor_t *cursor, int attr_index);
393 
403 attribute_id_t cursor_get_attr_index(db_cursor_t *cursor, const char *attr_name);
404 
415 int cursor_get_int_value(db_cursor_t *cursor, int attr_index);
416 
427 long cursor_get_long_value(db_cursor_t *cursor, int attr_index);
428 
429 #ifdef CONFIG_ARCH_FLOAT_H
430 
440 double cursor_get_double_value(db_cursor_t *cursor, int attr_index);
441 #endif
442 
452 unsigned char *cursor_get_string_value(db_cursor_t *cursor, int attr_index);
453  // end of AraStorage group
455 
456 #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...