39 #define DEBUG DEBUG_NONE
48 db_get_value(attribute_value_t *value, db_handle_t *handle,
unsigned col)
53 if(col >= handle->ncolumns) {
54 PRINTF(
"DB: Requested value (%d) is out of bounds; max = (%d)\n",
55 col, handle->ncolumns);
56 return DB_LIMIT_ERROR;
61 for(attr =
list_head(handle->result_rel->attributes); attr !=
NULL; attr = attr->next) {
62 if(attr->flags & ATTRIBUTE_FLAG_NO_STORE) {
66 PRINTF(
"Found attribute %s in the result. The element size is %d\n",
67 attr->name, attr->element_size);
72 buf += attr->element_size;
79 return db_phy_to_value(value, attr, buf);
85 db_phy_to_value(attribute_value_t *value, attribute_t *attr,
91 value->domain = attr->domain;
93 switch(attr->domain) {
95 ptr[attr->element_size - 1] =
'\0';
96 VALUE_STRING(value) = ptr;
97 PRINTF(
"DB: %s = %s\n", attr->name, ptr);
100 int_value = (ptr[0] << 8) | ((
unsigned)ptr[1] & 0xff);
101 VALUE_INT(value) = int_value;
102 PRINTF(
"DB: %s = %d\n", attr->name, int_value);
105 long_value = (long)ptr[0] << 24 | (
long)ptr[1] << 16 |
106 (long)ptr[2] << 8 | (
long)ptr[3];
107 VALUE_LONG(value) = long_value;
108 PRINTF(
"DB: %s = %ld\n", attr->name, long_value);
111 return DB_TYPE_ERROR;
120 db_value_to_phy(
unsigned char *ptr, attribute_t *attr,
121 attribute_value_t *value)
126 switch(attr->domain) {
128 memcpy(ptr, VALUE_STRING(value), attr->element_size);
129 ptr[attr->element_size - 1] =
'\0';
132 int_value = VALUE_INT(value);
133 ptr[0] = int_value >> 8;
134 ptr[1] = int_value & 0xff;
137 long_value = VALUE_LONG(value);
138 ptr[0] = long_value >> 24;
139 ptr[1] = long_value >> 16;
140 ptr[2] = long_value >> 8;
141 ptr[3] = long_value & 0xff;
144 return DB_TYPE_ERROR;
153 db_value_to_long(attribute_value_t *value)
155 switch(value->domain) {
157 return (
long)VALUE_INT(value);
159 return (
long)VALUE_LONG(value);
167 db_free(db_handle_t *handle)
169 if(handle->rel !=
NULL) {
170 relation_release(handle->rel);
172 if(handle->result_rel !=
NULL) {
173 relation_release(handle->result_rel);
175 if(handle->left_rel !=
NULL) {
176 relation_release(handle->left_rel);
178 if(handle->right_rel !=
NULL) {
179 relation_release(handle->right_rel);
The storage interface used by the database.
Declarations for the result acquisition API.
#define NULL
The null pointer.
void * list_head(list_t list)
Get a pointer to the first element of a list.
A set of debugging macros.