Changeset: af82b4caabd3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=af82b4caabd3
Modified Files:
        clients/Tests/exports.stable.out
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_gencode.h
        sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:

Code cleanup
split callinline from dumpproc


diffs (190 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1562,7 +1562,6 @@ int OPTmacroImplementation(Client cntxt,
 int OPTmatpackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 int OPTmergetableImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 int OPTmitosisImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
-int OPTmitosisPlanOverdue(Client cntxt, str fname);
 int OPTmultiplexImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 str OPTmultiplexSimple(Client cntxt, MalBlkPtr mb);
 str OPTorcam(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -197,10 +197,11 @@ SQLstatementIntern(Client c, str *expr, 
                        goto endofcompile;
                }
                /* generate MAL code */
-               if (backend_callinline(sql, c, s, 1) == 0)
+               if( backend_callinline(be, c) < 0 ||
+                       backend_dumpstmt(be, c->curprg->def, s, 1, 1) < 0)
+                       err = 1;
+               else
                        addQueryToCache(c);
-               else
-                       err = 1;
 
                if (err ||c->curprg->def->errors) {
                        /* restore the state */
@@ -514,11 +515,14 @@ RAstatement(Client cntxt, MalBlkPtr mb, 
 
                MSinitClientPrg(cntxt, "user", "test");
 
-               /* generate MAL code */
-               backend_callinline(b, cntxt, s, 1);
-               addQueryToCache(cntxt);
-
-               msg = (str) runMAL(cntxt, cntxt->curprg->def, 0, 0);
+               /* generate MAL code, ignoring any code generation error */
+               if(  backend_callinline(b, cntxt) < 0 ||
+                        backend_dumpstmt(b, cntxt->curprg->def, s, 1, 1) < 0)
+                       msg = createException(SQL,"RAstatement","Program 
contains errors");
+               else {
+                       addQueryToCache(cntxt);
+                       msg = (str) runMAL(cntxt, cntxt->curprg->def, 0, 0);
+               }
                if (!msg) {
                        resetMalBlk(cntxt->curprg->def, oldstop);
                        freeVariables(cntxt, cntxt->curprg->def, NULL, oldvtop);
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -46,7 +46,6 @@
 #include <rel_remote.h>
 
 static int _dumpstmt(backend *sql, MalBlkPtr mb, stmt *s);
-static int backend_dumpstmt(backend *be, MalBlkPtr mb, stmt *s, int top, int 
addend);
 
 /*
  * @+ MAL code support
@@ -2756,7 +2755,7 @@ static int
  * by using the SQLstatment.
  */
 
-static int
+int
 backend_dumpstmt(backend *be, MalBlkPtr mb, stmt *s, int top, int add_end)
 {
        mvc *c = be->mvc;
@@ -2799,15 +2798,14 @@ backend_dumpstmt(backend *be, MalBlkPtr 
        return 0;
 }
 
+/* Generate the assignments of the query arguments to the query template*/
 int
-backend_callinline(backend *be, Client c, stmt *s, int add_end)
+backend_callinline(backend *be, Client c)
 {
        mvc *m = be->mvc;
        InstrPtr curInstr = 0;
        MalBlkPtr curBlk = c->curprg->def;
 
-       curInstr = getInstrPtr(curBlk, 0);
-
        if (m->argc) {  
                int argc = 0;
 
@@ -2832,8 +2830,6 @@ backend_callinline(backend *be, Client c
                        }
                }
        }
-       if (backend_dumpstmt(be, curBlk, s, 1, add_end) < 0)
-               return -1;
        c->curprg->def = curBlk;
        return 0;
 }
diff --git a/sql/backends/monet5/sql_gencode.h 
b/sql/backends/monet5/sql_gencode.h
--- a/sql/backends/monet5/sql_gencode.h
+++ b/sql/backends/monet5/sql_gencode.h
@@ -18,7 +18,8 @@
 #include <mal_function.h>
 
 sql5_export Symbol backend_dumpproc(backend *be, Client c, cq *q, stmt *s);
-sql5_export int backend_callinline(backend *be, Client c, stmt *s, int 
add_end);
+sql5_export int backend_callinline(backend *be, Client c);
+sql5_export int backend_dumpstmt(backend *be, MalBlkPtr mb, stmt *s, int top, 
int addend);
 sql5_export void backend_call(backend *be, Client c, cq *q);
 sql5_export void initSQLreferences(void);
 sql5_export int monet5_resolve_function(ptr M, sql_func *f);
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -7,19 +7,11 @@
  */
 
 /*
- * @f sql_scenario
- * @t SQL catwalk management
- * @a N. Nes, M.L. Kersten
- * @+ SQL scenario
+ * (authors) N. Nes, M.L. Kersten
  * The SQL scenario implementation is a derivative of the MAL session scenario.
  *
- * It is also the first version that uses state records attached to
- * the client record. They are initialized as part of the initialization
- * phase of the scenario.
- *
  */
 /*
- * @+ Scenario routines
  * Before we are can process SQL statements the global catalog
  * should be initialized. Thereafter, each time a client enters
  * we update its context descriptor to denote an SQL scenario.
@@ -1226,18 +1218,22 @@ SQLparser(Client c)
                }
                assert(s);
 
-               /* generate the MAL prelude codea in the query wrapper */
+               /* generate the MAL prelude code in the query wrapper */
                SQLsetTrace(c, m, TRUE);
                SQLsetDebugger(c, m, TRUE);
 
                if (!caching(m) || !cachable(m, s)) {
+                       /* Query template should not be cached */
                        scanner_query_processed(&(m->scanner));
-                       if (backend_callinline(be, c, s, 0) == 0) {
-                               opt = 1;
-                       } else {
+                       err = 0;
+                       if( backend_callinline(be, c) < 0 ||
+                               backend_dumpstmt(be, c->curprg->def, s, 1, 0) < 
0)
                                err = 1;
-                       }
+                       else opt = 1;
                } else {
+                       /* Add the query tree to the SQL query cache
+                        * and bake a MAL program for it.
+                        */
                        char *q = query_cleaned(QUERY(m->scanner));
                        be->q = qc_insert(m->qc, m->sa, /* the allocator */
                                          r,    /* keep relational query */
@@ -1266,7 +1262,7 @@ SQLparser(Client c)
        if (err)
                m->session->status = -10;
        if (err == 0) {
-               /* no parsing error encountered */
+               /* no parsing error encountered, finalize the code of the query 
wrapper */
                if (be->q) {
                        if (m->emode == m_prepare)
                                /* For prepared queries, return a table with 
result set structure*/
@@ -1282,16 +1278,11 @@ SQLparser(Client c)
                /* In the final phase we add any debugging control */
                SQLsetTrace(c, m, FALSE);
                SQLsetDebugger(c, m, FALSE);
-
-               /*
-                * During the execution of the query exceptions can be raised.
-                * The default action is to print them out at the end of the
-                * query block.
-                */
                pushEndInstruction(c->curprg->def);
 
-               chkTypes(c->fdout, c->nspace, c->curprg->def, TRUE);    /* 
resolve types */
-               if (opt) {
+               /* check the query wrapper for errors */
+               chkTypes(c->fdout, c->nspace, c->curprg->def, TRUE);
+               if (opt && !c->curprg->def->errors ) {
                        str msg = optimizeQuery(c);
 
                        if (msg != MAL_SUCCEED) {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to