Changeset: a811325bc8a8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a811325bc8a8
Modified Files:
        sql/include/sql_catalog.h
        sql/server/rel_schema.c
        sql/storage/store.c
Branch: arrays
Log Message:

min, max,step, default all made atoms.
A new table named _ranges stores the detailed info about all the above


diffs (229 lines):

diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -452,6 +452,8 @@ typedef struct sql_column {
        void *data;
 } sql_column;
 
+typedef struct atom atom;
+
 typedef struct sql_dimension {
        sql_base base;
        sql_subtype type;
@@ -462,15 +464,10 @@ typedef struct sql_dimension {
        bit unbounded_min;
        bit unbounded_max;
 
-       //the range of the dimension
-       //It is void to store any type of dimensions
-       //the exact type is found through the type field of the struct
-       //Niels said to use atom. In this case do I need the information about 
the type?
-       //maybe I need to to check that the values when inserting a new cell 
are of the correct type
-       char *min;
-       char *step;
-       char *max;
-       char *def; //default value
+       atom *min;
+       atom *step;
+       atom *max;
+       atom *def; //default value
 
        lng lvl1_repeatsNum; //number of times each value of the dimension is 
repeated before being increased
        lng lvl2_repeatsNum; //number of times all values of the dimension are 
repeated as a group (including the duplicated values defined by repeatNum)
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -434,11 +434,11 @@ column_options(mvc *sql, dlist *opt_list
 }
 
 static int dimension_range(mvc *sql, sql_subtype *dtype, symbol *range, 
sql_dimension* dim) {
-       char *err = NULL;
-       char *r = NULL;
+//     char *err = NULL;
+//     char *r = NULL;
        dnode *range_value;
+       list *range_lst = sa_list(sql->sa);
 
-//check if this is necessary. Find a type that cannot be casted
        //check the types of the ranges
        for(range_value = range->data.lval->h ; range_value ; range_value = 
range_value->next) {
                atom *val = NULL;
@@ -450,9 +450,10 @@ static int dimension_range(mvc *sql, sql
                //I do not do any casting here, just making sure that the types 
are compatible
                if(!rel_check_type(sql, dtype, exp_atom(sql->sa, val), 
type_cast))
                        return SQL_ERR;
+               list_append(range_lst, val);
        }
 
-       switch(dlist_length(range->data.lval)) {
+       switch(list_length(range_lst)) {
     case 0:
         dim->unbounded_min = 1;
         dim->unbounded_max = 1;
@@ -462,62 +463,24 @@ static int dimension_range(mvc *sql, sql
         dim->max = NULL;
         break;  
     case 1: {
-               char *min = "0";
-               char *step = "1";
-        dim->min = min;
-        dim->step = step;
-        r = symbol2string(sql, range->data.lval->h->data.sym, &err); 
-               if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect max value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else {
-                       int m = atoi(r) - 1;
-                       sprintf(r, "%d", m);
-                       dim->max = r;
-               }
+               sql_subtype valuesType = ((atom*)range_lst->h->data)->tpe;
+        dim->min = atom_int(sql->sa, &valuesType, 0);
+        dim->step = atom_int(sql->sa, &valuesType, 1);
+               dim->max = range_lst->h->data; 
+        dim->max->data.val.ival--;//the upper limit is one smaller than the 
total size (0 starting arrays)
+        dim->max->d--; //I have no idea what this is
                break;
        }  
     case 2:
-        dim->unbounded_max = 1;
-        r = symbol2string(sql, range->data.lval->h->data.sym, &err);
-        if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect min value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else
-                       dim->min = r;
-               r = symbol2string(sql, range->data.lval->h->next->data.sym, 
&err);
-        if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect step value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else
-                       dim->step = r;
-               dim->max = NULL;
+               dim->unbounded_max = 1;
+        dim->min = range_lst->h->data;
+        dim->step = range_lst->h->next->data;
+        dim->max = NULL;
         break;  
     case 3:
-        r = symbol2string(sql, range->data.lval->h->data.sym, &err);
-        if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect min value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else
-                       dim->min = r;
-               r = symbol2string(sql, range->data.lval->h->next->data.sym, 
&err);
-        if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect step value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else
-                       dim->step = r;
-        r = symbol2string(sql, range->data.lval->h->next->next->data.sym, 
&err);
-        if (!r) {
-                       (void) sql_error(sql, 02, "42000!incorrect max value 
'%s'\n", err?err:"");
-           if (err) _DELETE(err);
-                   return SQL_ERR;
-        } else
-                       dim->max = r;
+               dim->min = range_lst->h->data;
+        dim->step = range_lst->h->next->data;
+        dim->max = range_lst->h->next->next->data;
                break;  
     }
 #if 0
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1532,10 +1532,6 @@ store_init(int debug, store_type store, 
                bootstrap_create_column(tr, t, "type_digits", "int", 32);
                bootstrap_create_column(tr, t, "type_scale", "int", 32);
                bootstrap_create_column(tr, t, "table_id", "int", 32);
-               bootstrap_create_column(tr, t, "default", "varchar", 2048);
-        bootstrap_create_column(tr, t, "min", "varchar", 2048);
-        bootstrap_create_column(tr, t, "step", "varchar", 2048);
-        bootstrap_create_column(tr, t, "max", "varchar", 2048);
         bootstrap_create_column(tr, t, "dimnr", "int", 32);
                bootstrap_create_column(tr, t, "repeats1", "int", 32);
                bootstrap_create_column(tr, t, "repeats2", "int", 32);
@@ -1543,6 +1539,15 @@ store_init(int debug, store_type store, 
                bootstrap_create_column(tr, t, "umax", "boolean", 1);
                bootstrap_create_column(tr, t, "storage", "varchar", 2048);
 
+               t = bootstrap_create_table(tr, s, "_ranges");
+               bootstrap_create_column(tr, t, "name", "varchar", 1024);
+               bootstrap_create_column(tr, t, "type", "varchar", 1024);
+               bootstrap_create_column(tr, t, "type_digits", "int", 32);
+               bootstrap_create_column(tr, t, "type_scale", "int", 32);
+               bootstrap_create_column(tr, t, "table_id", "int", 32);
+        bootstrap_create_column(tr, t, "column_id", "int", 32);
+               bootstrap_create_column(tr, t, "value", "varchar", 2048);
+
                t = bootstrap_create_table(tr, s, "keys");
                bootstrap_create_column(tr, t, "id", "int", 32);
                bootstrap_create_column(tr, t, "table_id", "int", 32);
@@ -2165,24 +2170,17 @@ sql_trans_copy_dimension( sql_trans *tr,
 {
        sql_schema *syss = find_sql_schema(tr, isGlobal(t)?"sys":"tmp");
        sql_table *syscolumn = find_sql_table(syss, "_dimensions");
+       sql_table *syscolumn2 = find_sql_table(syss, "_ranges");
        sql_dimension *col = SA_ZNEW(tr->sa, sql_dimension);
 
        if (sql_trans_name_conflict(tr, t->s->base.name, t->base.name, 
dim->base.name))
                return NULL;
        base_init(tr->sa, &col->base, dim->base.id, TR_NEW, dim->base.name);
        col->type = dim->type;
-       col->def = NULL;
-       if (dim->def)
-               col->def = sa_strdup(tr->sa, dim->def);
-       col->min = NULL;
-       if (dim->min)
-               col->min = sa_strdup(tr->sa, dim->min);
-       col->step = NULL;
-       if (dim->step)
-               col->step = sa_strdup(tr->sa, dim->step);
-       col->max = NULL;
-       if (dim->max)
-               col->max = sa_strdup(tr->sa, dim->max);
+       col->def = dim->def;
+       col->min = dim->min;
+       col->step = dim->step;
+       col->max = dim->max;
        col->dimnr = dim->dimnr;
        col->lvl1_repeatsNum = dim->lvl1_repeatsNum;
        col->lvl2_repeatsNum = dim->lvl2_repeatsNum;
@@ -2202,7 +2200,29 @@ sql_trans_copy_dimension( sql_trans *tr,
                                return NULL;
 */
        if (!isDeclaredArray(t)) {
-               table_funcs.table_insert(tr, syscolumn, &col->base.id, 
col->base.name, col->type.type->sqlname, &col->type.digits, &col->type.scale, 
&t->base.id, (col->def) ? col->def : ATOMnilptr(TYPE_str), col->min, col->step, 
col->max, &col->dimnr, &col->lvl1_repeatsNum, &col->lvl2_repeatsNum, 
&col->unbounded_min, &col->unbounded_max, (col->storage_type) ? 
col->storage_type : ATOMnilptr(TYPE_str));
+               table_funcs.table_insert(tr, syscolumn, &col->base.id, 
col->base.name, col->type.type->sqlname, &col->type.digits, &col->type.scale, 
&t->base.id, &col->dimnr, &col->lvl1_repeatsNum, &col->lvl2_repeatsNum, 
&col->unbounded_min, &col->unbounded_max, (col->storage_type) ? 
col->storage_type : ATOMnilptr(TYPE_str));
+
+               //store the info about the range
+               if(col->min) {
+                       char *name = "min";
+                       table_funcs.table_insert(tr, syscolumn2, name, 
col->min->tpe.type->sqlname, &col->min->tpe.digits, &col->min->tpe.scale, 
&t->base.id, &col->base.id, atom2string(tr->sa, col->min));
+               }
+
+               if(col->step) {
+                       char *name = "step";
+                       table_funcs.table_insert(tr, syscolumn2, name, 
col->step->tpe.type->sqlname, &col->step->tpe.digits, &col->step->tpe.scale, 
&t->base.id, &col->base.id, atom2string(tr->sa, col->step));
+               }
+
+               if(col->max) {
+                       char *name = "max";
+                       table_funcs.table_insert(tr, syscolumn2, name, 
col->max->tpe.type->sqlname, &col->max->tpe.digits, &col->max->tpe.scale, 
&t->base.id, &col->base.id, atom2string(tr->sa, col->max));
+               }
+
+               if(col->def) {
+                       char *name = "def";
+                       table_funcs.table_insert(tr, syscolumn2, name, 
col->def->tpe.type->sqlname, &col->def->tpe.digits, &col->def->tpe.scale, 
&t->base.id, &col->base.id, atom2string(tr->sa, col->def));
+               }
+
        }
        col->base.wtime = t->base.wtime = t->s->base.wtime = tr->wtime = 
tr->wstime;
        if (isGlobal(t)) 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to