Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32040/src/server

Modified Files:
      Tag: SQL_2-24
        sql_mvc.mx sql_psm.mx sql_schema.mx sql_semantic.mx 
        sql_statement.mx sql_updates.mx 
Log Message:
changed handling of declared tables to fix the schema_from_declared_table
bug.


U sql_semantic.mx
Index: sql_semantic.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_semantic.mx,v
retrieving revision 1.181
retrieving revision 1.181.2.1
diff -u -d -r1.181 -r1.181.2.1
--- sql_semantic.mx     1 Apr 2008 17:05:01 -0000       1.181
+++ sql_semantic.mx     4 Jun 2008 20:19:17 -0000       1.181.2.1
@@ -397,12 +397,22 @@
 tvar *
 scope_add_temp_table(scope *scp, sql_table *t, stmt *temp_table, char *tname)
 {
-       node *m, *n;
+       node *n;
        tvar *tv = scope_add_table(scp, stmt_dup(temp_table), tname, NULL);
 
-       assert(temp_table->type == st_list);
+       assert(t->persistence == SQL_DECLARED_TABLE);
+       for (n = t->columns.set->h; n; n = n->next) {
+               sql_column *c = n->data;
+               stmt *sc = stmt_bat(c, stmt_dup(temp_table), RDONLY);
+
+               table_add_column(tv, sc, NULL, c->base.name);
+       }
+
+       //node *m, *n;
+       //assert(temp_table->type == st_list);
 
        /* foreach column add column name */
+/*
        for (m = t->columns.set->h, n = temp_table->op1.lval->h; m && n; 
                        m = m->next, n = n->next) {
                sql_column *c = m->data;
@@ -413,6 +423,7 @@
                sc = stmt_column(sc, stmt_dup(temp_table), NULL);
                table_add_column(tv, sc, NULL, cname);
        }
+*/
        return tv;
 }
 
@@ -688,7 +699,29 @@
        }
        tab = s->op1.stval;
        temp = s->flag;
-       if (tab->type == st_list) {
+       if (tab->type == st_var) {
+               stmt *base = stack_find_var(sql, tab->op1.sval);
+               sql_table *tbl = tail_type(tab)->comp_type;
+               node *n, *m;
+               list *l = create_stmt_list();
+               for (n = ct->columns.set->h, m = tbl->columns.set->h; 
+                       n && m; n = n->next, m = m->next) 
+               {
+                       sql_column *c = n->data;
+                       sql_column *dtc = m->data;
+                       stmt *dtcs = stmt_bat(dtc, stmt_dup(base), RDONLY);
+                       stmt *r = check_types(sql, &c->type, dtcs, tpe);
+                       if (!r) {
+                               list_destroy(l);
+                               stmt_destroy(s);
+                               return NULL;
+                       }
+                       r = stmt_alias(r, _strdup(tbl->base.name), 
_strdup(c->base.name));
+                       list_append(l, r);
+               }
+               stmt_destroy(s);
+               return stmt_table(stmt_list(l), temp);
+       } else if (tab->type == st_list) {
                node *n, *m;
                list *l = create_stmt_list();
                for (n = ct->columns.set->h, m = tab->op1.lval->h; 

U sql_updates.mx
Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.138
retrieving revision 1.138.2.1
diff -u -d -r1.138 -r1.138.2.1
--- sql_updates.mx      14 May 2008 20:18:28 -0000      1.138
+++ sql_updates.mx      4 Jun 2008 20:19:18 -0000       1.138.2.1
@@ -1210,11 +1210,8 @@
        if (!t && !sname) {
                s = tmp_schema(sql);
                t = mvc_bind_table(sql, s, tname);
-               if (!t) {
-                       sql_subtype *tpe = stack_find_type(sql, tname);
-                       if (tpe)
-                               t = tpe->comp_type;
-               }
+               if (!t) 
+                       t = mvc_bind_table(sql, NULL, tname);
        }
        if (!t) {
                return sql_error(sql, 02, "INSERT INTO: no such table '%s'", 
tname);

U sql_schema.mx
Index: sql_schema.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_schema.mx,v
retrieving revision 1.140
retrieving revision 1.140.2.1
diff -u -d -r1.140 -r1.140.2.1
--- sql_schema.mx       1 Apr 2008 17:04:59 -0000       1.140
+++ sql_schema.mx       4 Jun 2008 20:19:16 -0000       1.140.2.1
@@ -1601,10 +1601,12 @@
        if (temp != SQL_PERSIST && commit_action == CA_COMMIT)
                commit_action = CA_DELETE;
        
-       if (temp != SQL_PERSIST) {
-               s = mvc_bind_schema(sql, "tmp");
-       } else if (s == NULL) {
-               s = ss;
+       if (temp != SQL_DECLARED_TABLE) {
+               if (temp != SQL_PERSIST) {
+                       s = mvc_bind_schema(sql, "tmp");
+               } else if (s == NULL) {
+                       s = ss;
+               }
        }
 
        if (mvc_bind_table(sql, s, name)) {

U sql_statement.mx
Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.165
retrieving revision 1.165.2.1
diff -u -d -r1.165 -r1.165.2.1
--- sql_statement.mx    14 May 2008 20:18:27 -0000      1.165
+++ sql_statement.mx    4 Jun 2008 20:19:17 -0000       1.165.2.1
@@ -1165,34 +1165,10 @@
        return s;
 }
 
-static stmt *
-find_column(sql_column *c, stmt *basetable) 
-{
-       node *n;
-
-       assert(basetable->type == st_list);
-       for(n=basetable->op1.lval->h; n; n = n->next) {
-               char *cn = NULL;
-               stmt *cs = n->data;
-
-               if (strcmp(cn=column_name(cs), c->base.name) == 0) {
-                       _DELETE(cn);
-                       return stmt_dup(cs);
-               }
-               _DELETE(cn);
-       }
-       return NULL;
-}
-
 stmt *
 stmt_bat(sql_column *c, stmt *basetable, int access )
 {
-       stmt *s;
-
-       if (c->t->persistence == SQL_DECLARED_TABLE)
-               return find_column(c, basetable);
-
-       s = stmt_create(st_bat);
+       stmt *s = stmt_create(st_bat);
 
        s->op1.cval = c;
        s->nrcols = 1;

U sql_mvc.mx
Index: sql_mvc.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_mvc.mx,v
retrieving revision 1.201
retrieving revision 1.201.2.1
diff -u -d -r1.201 -r1.201.2.1
--- sql_mvc.mx  1 Apr 2008 17:04:57 -0000       1.201
+++ sql_mvc.mx  4 Jun 2008 20:19:15 -0000       1.201.2.1
@@ -774,11 +774,20 @@
 {
        sql_table *t;
 
-       if (m->last && m->last->t->s == s &&
-               strcmp(m->last->t->base.name, tname) == 0)
+       if (!s) { /* Declared tables during query compilation have no schema */
+               sql_subtype *tpe = stack_find_type(m, tname);
+               if (tpe) { 
+                       t = tpe->comp_type;
+               } else { /* during exection they are in the '%dt%' schema */
+                       s = mvc_bind_schema(m, "%dt%");
+                       return mvc_bind_table(m, s, tname);
+               }
+       } else if (m->last && m->last->t->s == s &&
+               strcmp(m->last->t->base.name, tname) == 0) {
                t = m->last->t;
-       else 
+       } else {
                t = find_sql_table(s, tname);
+       }
        if (!t)
                return NULL;
        if (mvc_debug)
@@ -1107,7 +1116,7 @@
        if (mvc_debug)
                fprintf(stderr, "mvc_create_table %s %s %d %d %d\n", 
s->base.name, name, system, persistence, commit_action);
 
-       if (persistence == SQL_DECLARED_TABLE)
+       if (!s && persistence == SQL_DECLARED_TABLE)
                /* declared tables should not end up in the catalog */
                t = create_sql_table(name, tt_table, system, persistence, 
commit_action);
        else
@@ -1178,7 +1187,7 @@
        if (mvc_debug)
                fprintf(stderr, "mvc_create_column %s %s %s\n", t->base.name, 
name, tpe->type->sqlname);
        m->type = Q_SCHEMA;
-       if (t->persistence == SQL_DECLARED_TABLE)
+       if (!t->s && t->persistence == SQL_DECLARED_TABLE)
                /* declared tables should not end up in the catalog */
                return create_sql_column(t, name, tpe);
        else

U sql_psm.mx
Index: sql_psm.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_psm.mx,v
retrieving revision 1.53
retrieving revision 1.53.2.1
diff -u -d -r1.53 -r1.53.2.1
--- sql_psm.mx  1 Apr 2008 17:04:59 -0000       1.53
+++ sql_psm.mx  4 Jun 2008 20:19:16 -0000       1.53.2.1
@@ -143,13 +143,11 @@
 static stmt *
 psm_declare_table(mvc *sql, scope *scp, dnode *n)
 {
-       node *m;
        dlist *qname = n->next->data.lval;
        char *name = qname_table(qname);
        char *sname = qname_schema(qname);
        stmt *ret, *r;
        sql_subtype ctype = *sql_bind_localtype("bat");
-       list *l;
 
        (void)scp;
        if (sname)  /* not allowed here */
@@ -165,15 +163,7 @@
 
        ctype.comp_type = find_basetable(ret); 
 
-       l = create_stmt_list();
-       for (m=ctype.comp_type->columns.set->h; m; m = m->next) {
-               sql_column *c = m->data;
-               stmt *cs = stmt_temp(&c->type);
-               char *tname = _strdup(c->t->base.name);
-               cs = stmt_alias(cs, tname, _strdup(c->base.name));
-               list_append(l, cs);
-       }
-       r = stmt_list(l);
+       r = stmt_var(_strdup(name), &ctype, 1, sql->frame );
        stack_push_var(sql, name, r, &ctype);
        stmt_destroy(ret);
        return r;


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to