Tizen RT Public API  v1.0 D5
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 
61 #ifndef __ARASTORAGE_ARA_STORAGE_H
62 #define __ARASTORAGE_ARA_STORAGE_H
63 
64 /****************************************************************************
65  * Included Files
66  ****************************************************************************/
67 #include <stdbool.h>
68 #include <stdio.h>
69 /****************************************************************************
70 * Pre-processor Definitions
71 ****************************************************************************/
72 #define INVALID_TUPLE (tuple_id_t)-1
73 #define INVALID_CURSOR_VALUE -1
74 
75 #define DB_ERROR(result_code) ((result_code) < DB_OK)
76 #define DB_SUCCESS(result_code) !DB_ERROR(result_code)
77 
78 /* We only accept value in the range of [DB_XXX_MIN + 1, MAX] */
79 #define DB_INT_MAX INT_MAX
80 #define DB_INT_MIN INT_MIN + 1
81 
82 #define DB_LONG_MAX LONG_MAX
83 #define DB_LONG_MIN LONG_MIN + 1
84 
85 #ifdef CONFIG_HAVE_DOUBLE
86 #define DB_DOUBLE_MAX DBL_MAX
87 #define DB_DOUBLE_MIN DBL_MIN + 1
88 #else
89 #define DB_DOUBLE_MAX FLT_MAX
90 #define DB_DOUBLE_MIN FLT_MIN + 1
91 #endif
92 
93 /* We consider that the least value in the range of each type is invalid */
94 #define DB_INT_ERROR INT_MIN
95 #define DB_LONG_ERROR LONG_MIN
96 #ifdef CONFIG_HAVE_DOUBLE
97 #define DB_DOUBLE_ERROR DBL_MIN
98 #else
99 #define DB_DOUBLE_ERROR FLT_MIN
100 #endif
101 
102 /****************************************************************************
103 * Public Type Definitions
104 ****************************************************************************/
105 #define DB_FINISHED_MSG "Iteration finished"
106 #define DB_OK_MSG "Operation succeeded"
107 #define DB_LIMIT_ERROR_MSG "Limit reached"
108 #define DB_ALLOCATION_ERROR_MSG "Allocation error"
109 #define DB_STORAGE_ERROR_MSG "Storage error"
110 #define DB_PARSING_ERROR_MSG "Parsing error"
111 #define DB_NAME_ERROR_MSG "Invalid name"
112 #define DB_RELATIONAL_ERROR_MSG "Semantic error"
113 #define DB_TYPE_ERROR_MSG "Type error"
114 #define DB_IMPLEMENTATION_ERROR_MSG "Implementation error"
115 #define DB_INDEX_ERROR_MSG "Index error"
116 #define DB_BUSY_ERROR_MSG "Busy with processing"
117 #define DB_INCONSISTENCY_ERROR_MSG "Inconsistent handle"
118 #define DB_ARGUMENT_ERROR_MSG "Invalid argument"
119 #define DB_FULL_ERROR_MSG "Tuple limit reached"
120 #define DB_CURSOR_ERROR_MSG "Cursor Error"
121 #define DB_UNKNOWN_ERROR_MSG "Unknown result code"
122 #define DB_EMPTY_CURSOR_ERROR_MSG "Empty Cursor"
123 
124 enum db_result_e {
125  DB_FINISHED = 3,
126  DB_GOT_ROW = 2,
127  DB_OK = 1,
128  DB_LIMIT_ERROR = -1,
129  DB_ALLOCATION_ERROR = -2,
130  DB_STORAGE_ERROR = -3,
131  DB_PARSING_ERROR = -4,
132  DB_NAME_ERROR = -5,
133  DB_RELATIONAL_ERROR = -6,
134  DB_TYPE_ERROR = -7,
135  DB_IMPLEMENTATION_ERROR = -8,
136  DB_INDEX_ERROR = -9,
137  DB_BUSY_ERROR = -10,
138  DB_INCONSISTENCY_ERROR = -11,
139  DB_ARGUMENT_ERROR = -12,
140  DB_FULL_ERROR = -13,
141  DB_CURSOR_ERROR = -14,
142  DB_EMPTY_CURSOR_ERROR = -15
143 };
144 
145 typedef enum db_result_e db_result_t;
146 
147 enum domain_e {
148  DOMAIN_UNSPECIFIED = 0,
149  DOMAIN_INT = 1,
150  DOMAIN_LONG = 2,
151  DOMAIN_STRING = 3,
152  DOMAIN_DOUBLE = 4
153 };
154 
155 typedef enum domain_e domain_t;
156 
157 
158 struct _db_handle_s;
159 typedef struct _db_handle_s db_handle_t;
160 
161 struct _db_cursor_s;
162 typedef struct _db_cursor_s db_cursor_t;
163 
164 typedef int db_storage_id_t;
165 
166 typedef uint32_t cursor_row_t;
167 
168 typedef uint32_t tuple_id_t;
169 
170 typedef uint8_t attribute_id_t;
171 
172 /****************************************************************************
173 * Public Variables
174 ****************************************************************************/
175 typedef int (*db_output_function_t)(const char *, ...);
176 
177 static db_output_function_t output = printf;
178 
179 /****************************************************************************
180 * Global Function Prototypes
181 ****************************************************************************/
182 
189 db_result_t db_init(void);
190 
197 db_result_t db_deinit(void);
198 
199 
209 db_result_t db_exec(char *format);
210 
219 db_cursor_t *db_query(char *format);
220 
221 
229 db_result_t db_cursor_free(db_cursor_t *cursor);
230 
238 const char *db_get_result_message(db_result_t code);
239 
240 
248 db_result_t db_print_header(db_cursor_t *cursor);
249 
250 
258 db_result_t db_print_tuple(db_cursor_t *cursor);
259 
260 
269 db_result_t db_print_value(db_cursor_t *cursor, int attr_index);
270 
271 
279 db_result_t cursor_move_first(db_cursor_t *cursor);
280 
281 
289 db_result_t cursor_move_last(db_cursor_t *cursor);
290 
291 
299 db_result_t cursor_move_next(db_cursor_t *cursor);
300 
301 
309 db_result_t cursor_move_prev(db_cursor_t *cursor);
310 
311 
319 db_result_t cursor_move_to(db_cursor_t *cursor, tuple_id_t row_id);
320 
321 
329 bool cursor_is_first_row(db_cursor_t *cursor);
330 
331 
339 bool cursor_is_last_row(db_cursor_t *cursor);
340 
348 cursor_row_t cursor_get_row(db_cursor_t *cursor);
349 
357 cursor_row_t cursor_get_count(db_cursor_t *cursor);
358 
359 
368 domain_t cursor_get_attr_type(db_cursor_t *cursor, int attr_index);
369 
370 
379 char *cursor_get_attr_name(db_cursor_t *cursor, int attr_index);
380 
381 
390 attribute_id_t cursor_get_attr_index(db_cursor_t *cursor, const char *attr_name);
391 
392 
402 int cursor_get_int_value(db_cursor_t *cursor, int attr_index);
403 
404 
414 long cursor_get_long_value(db_cursor_t *cursor, int attr_index);
415 
416 #ifdef CONFIG_ARCH_FLOAT_H
417 
426 double cursor_get_double_value(db_cursor_t *cursor, int attr_index);
427 #endif
428 
437 unsigned char *cursor_get_string_value(db_cursor_t *cursor, int attr_index);
438  // end of AraStorage group
440 
441 #endif /* __ARASTORAGE_ARA_STORAGE_H */
442 
db_result_t db_print_header(db_cursor_t *cursor)
Print the related information : relation, attribute name.
bool cursor_is_last_row(db_cursor_t *cursor)
Check current position of cursor is last row.
db_result_t cursor_move_last(db_cursor_t *cursor)
Move current position of cursor to last row.
db_result_t cursor_move_prev(db_cursor_t *cursor)
Move current position of cursor to previous row.
cursor_row_t cursor_get_row(db_cursor_t *cursor)
Get current position of cursor.
db_result_t cursor_move_first(db_cursor_t *cursor)
Move current position of cursor to first row.
db_result_t db_cursor_free(db_cursor_t *cursor)
free allocated cursor data. This should be called before application terminated.
domain_t cursor_get_attr_type(db_cursor_t *cursor, int attr_index)
get type of attribute of specific index in cursor
db_result_t db_print_value(db_cursor_t *cursor, int attr_index)
print current row&#39;s data where specific index
db_result_t cursor_move_next(db_cursor_t *cursor)
Move current position of cursor to next row.
char * cursor_get_attr_name(db_cursor_t *cursor, int attr_index)
get name of attribute of specific index in cursor
const char * db_get_result_message(db_result_t code)
get string of each API&#39;s result based on value of db_result_t
db_result_t db_print_tuple(db_cursor_t *cursor)
Print the tuple data.
int cursor_get_int_value(db_cursor_t *cursor, int attr_index)
Get value of current row&#39;s data where specific index if it is integer type.
db_result_t db_init(void)
initialize database&#39;s resouces, it must be called when user arastorage
db_cursor_t * db_query(char *format)
Arastorage basic query API.
cursor_row_t cursor_get_count(db_cursor_t *cursor)
get count of total row of cursor
db_result_t db_exec(char *format)
Create Component of Arastorage.
attribute_id_t cursor_get_attr_index(db_cursor_t *cursor, const char *attr_name)
Find index number where using specific attribute name.
db_result_t db_deinit(void)
de-initialize database&#39;s resouces, it must be called when terminate arastorage.
unsigned char * cursor_get_string_value(db_cursor_t *cursor, int attr_index)
Get value of current row&#39;s data where specific index if it is string type.
db_result_t cursor_move_to(db_cursor_t *cursor, tuple_id_t row_id)
Move current position of cursor to specific row.
long cursor_get_long_value(db_cursor_t *cursor, int attr_index)
Get value of current row&#39;s data where specific index if it is long type.
bool cursor_is_first_row(db_cursor_t *cursor)
Check current position of cursor is first row.