42 #if defined(__cplusplus) 46 #include "../dictionary/dictionary_types.h" 47 #include "../dictionary/ion_master_table.h" 62 #define IINQ_NEW_PROCESSOR_FUNC(name) \ 63 void name(ion_iinq_result_t *result, void* state) 70 #define IINQ_QUERY_PROCESSOR(execute, state) ((ion_iinq_query_processor_t){ execute, state }) 94 char *schema_file_name,
102 char *schema_file_name,
109 char *schema_file_name,
116 char *schema_file_name,
123 char *schema_file_name,
129 char *schema_file_name
132 #define CREATE_DICTIONARY(schema_name, key_type, key_size, value_size) \ 133 iinq_create_source(#schema_name ".inq", key_type, key_size, value_size) 135 #define INSERT(schema_name, key, value) \ 136 iinq_insert(#schema_name ".inq", key, value) 138 #define UPDATE(schema_name, key, value) \ 139 iinq_insert(#schema_name ".inq", key, value) 141 #define DELETE_FROM(schema_name, key) \ 142 iinq_delete(#schema_name ".inq", key) 144 #define DROP(schema_name)\ 145 iinq_drop(#schema_name ".inq") 148 ion_iinq_result_size_t result_loc = 0; \ 149 ion_iinq_cleanup_t *copyer = first; \ 150 while (NULL != copyer) { \ 151 memcpy(result.data+(result_loc), copyer->reference->key, copyer->reference->dictionary.instance->record.key_size); \ 152 result_loc += copyer->reference->dictionary.instance->record.key_size; \ 153 memcpy(result.data+(result_loc), copyer->reference->value, copyer->reference->dictionary.instance->record.value_size); \ 154 result_loc += copyer->reference->dictionary.instance->record.value_size; \ 155 copyer = copyer->next; \ 158 #define _FROM_SOURCE_SINGLE(source) \ 159 ion_iinq_source_t source; \ 160 source.cleanup.next = NULL; \ 161 source.cleanup.last = last; \ 162 source.cleanup.reference = &source; \ 163 if (NULL == first) { \ 164 first = &source.cleanup; \ 166 if (NULL != last) { \ 167 last->next = &source.cleanup; \ 169 last = &source.cleanup; \ 170 source.cleanup.next = NULL; \ 171 source.dictionary.handler = &source.handler; \ 172 error = iinq_open_source(#source ".inq", &(source.dictionary), &(source.handler)); \ 173 if (err_ok != error) { \ 176 source.key = alloca(source.dictionary.instance->record.key_size); \ 177 source.value = alloca(source.dictionary.instance->record.value_size); \ 178 source.ion_record.key = source.key; \ 179 source.ion_record.value = source.value; \ 180 result.num_bytes += source.dictionary.instance->record.key_size; \ 181 result.num_bytes += source.dictionary.instance->record.value_size; \ 182 error = dictionary_build_predicate(&(source.predicate), predicate_all_records); \ 183 if (err_ok != error) { \ 186 dictionary_find(&source.dictionary, &source.predicate, &source.cursor); 188 #define _FROM_CHECK_CURSOR_SINGLE(source) \ 189 (cs_cursor_active == (source.cursor_status = source.cursor->next(source.cursor, &source.ion_record)) || cs_cursor_initialized == source.cursor_status) 191 #define _FROM_ADVANCE_CURSORS \ 192 if (NULL == ref_cursor) { \ 195 last_cursor = ref_cursor; \ 197 while (NULL != ref_cursor && (cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \ 198 ref_cursor->reference->cursor->destroy(&ref_cursor->reference->cursor); \ 199 dictionary_find(&ref_cursor->reference->dictionary, &ref_cursor->reference->predicate, &ref_cursor->reference->cursor); \ 200 if ((cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \ 201 goto IINQ_QUERY_CLEANUP; \ 203 ref_cursor = ref_cursor->last; \ 205 if (NULL == ref_cursor) { \ 208 else if (last_cursor != ref_cursor) { \ 213 #define _FROM_SOURCE_1(_1) _FROM_SOURCE_SINGLE(_1) 214 #define _FROM_SOURCE_2(_1, _2) _FROM_SOURCE_1(_1) _FROM_SOURCE_1(_2) 215 #define _FROM_SOURCE_3(_1, _2, _3) _FROM_SOURCE_2(_1, _2) _FROM_SOURCE_1(_3) 216 #define _FROM_SOURCE_4(_1, _2, _3, _4) _FROM_SOURCE_3(_1, _2, _3) _FROM_SOURCE_1(_4) 217 #define _FROM_SOURCE_5(_1, _2, _3, _4, _5) _FROM_SOURCE_4(_1, _2, _3, _4) _FROM_SOURCE_1(_5) 218 #define _FROM_SOURCE_6(_1, _2, _3, _4, _5, _6) _FROM_SOURCE_5(_1, _2, _3, _4, _5) _FROM_SOURCE_1(_6) 219 #define _FROM_SOURCE_7(_1, _2, _3, _4, _5, _6, _7) _FROM_SOURCE_6(_1, _2, _3, _4, _5, _6) _FROM_SOURCE_1(_7) 220 #define _FROM_SOURCE_8(_1, _2, _3, _4, _5, _6, _7, _8) _FROM_SOURCE_7(_1, _2, _3, _4, _5, _6, _7) _FROM_SOURCE_1(_8) 224 #define _FROM_SOURCE_GET_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, MACRO, ...) MACRO 231 #define _FROM_SOURCES(...) _FROM_SOURCE_GET_OVERRIDE(__VA_ARGS__, _FROM_SOURCE_8, _FROM_SOURCE_7, _FROM_SOURCE_6, _FROM_SOURCE_5, _FROM_SOURCE_4, _FROM_SOURCE_3, _FROM_SOURCE_2, _FROM_SOURCE_1, THEBLACKWHOLE)(__VA_ARGS__) 233 #define _FROM_CHECK_CURSOR(sources) \ 234 _FROM_CHECK_CURSOR_SINGLE(sources) 237 ion_iinq_cleanup_t *first; \ 238 ion_iinq_cleanup_t *last; \ 239 ion_iinq_cleanup_t *ref_cursor; \ 240 ion_iinq_cleanup_t *last_cursor; \ 244 last_cursor = NULL; \ 245 _FROM_SOURCES(__VA_ARGS__) \ 246 result.data = alloca(result.num_bytes); \ 247 ref_cursor = first; \ 249 while (ref_cursor != last) { \ 250 if (NULL == ref_cursor || (cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \ 253 ref_cursor = ref_cursor->next; \ 257 _FROM_ADVANCE_CURSORS 262 #define WHERE(condition) (condition) 264 #define QUERY(select, from, where, groupby, having, orderby, limit, when, p) \ 267 ion_iinq_result_t result; \ 268 result.num_bytes = 0; \ 274 (p)->execute(&result, (p)->state); \ 276 IINQ_QUERY_CLEANUP: \ 277 while (NULL != first) { \ 278 first->reference->cursor->destroy(&first->reference->cursor); \ 279 ion_close_dictionary(&first->reference->dictionary); \ 280 first = first->next; \ 284 #if defined(__cplusplus)
enum ION_KEY_TYPE ion_key_type_t
This is the available key types for ION_DB. All types will be based on system defines.
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
int ion_value_size_t
The size (length) of a dictionary value in bytes.
ion_dict_cursor_t * cursor
Struct used to maintain key and value.
struct iinq_cleanup ion_iinq_cleanup_t
ion_iinq_result_size_t num_bytes
char ion_err_t
The error type used to store error codes.
void * ion_key_t
A dictionary key.
void * ion_value_t
A dictionary value.
void(* ion_iinq_query_processor_func_t)(ion_iinq_result_t *, void *)
Function pointer type for processing not data modifying IINQ queries.
ion_iinq_source_t * reference
ion_predicate_t predicate
A dictionary contains information regarding an instance of the storage element and the associated han...
A supertype for dictionary cursor objects.
struct iinq_cleanup * next
A supertype for cursor predicate objects.
ion_status_t iinq_insert(char *schema_file_name, ion_key_t key, ion_value_t value)
ion_iinq_cleanup_t cleanup
ion_status_t iinq_update(char *schema_file_name, ion_key_t key, ion_value_t value)
ion_err_t iinq_drop(char *schema_file_name)
ion_iinq_query_processor_func_t execute
int ion_key_size_t
The size (length) of a dictionary key in bytes.
unsigned int ion_iinq_result_size_t
ion_err_t iinq_create_source(char *schema_file_name, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size)
ion_dictionary_t dictionary
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
ion_cursor_status_t cursor_status
ion_status_t iinq_delete(char *schema_file_name, ion_key_t key)
char ion_cursor_status_t
A type for the status of a cursor.
ion_dictionary_handler_t handler
struct iinq_cleanup * last
A status object that describes the result of a dictionary operation.