Changeset: bbe7f874d29b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bbe7f874d29b
Modified Files:
sql/src/backends/monet5/sql_scenario.mx
sql/src/server/rel_select.mx
sql/src/server/sql_parser.mx
sql/src/sql/createdb.mx
Branch: default
Log Message:
fixing SQLstatementIntern
diffs (235 lines):
diff -r b4a7028a803d -r bbe7f874d29b sql/src/backends/monet5/sql_scenario.mx
--- a/sql/src/backends/monet5/sql_scenario.mx Fri May 14 15:57:49 2010 +0200
+++ b/sql/src/backends/monet5/sql_scenario.mx Sat May 15 22:45:44 2010 +0200
@@ -571,15 +571,16 @@
static str
SQLstatementIntern(Client c, str *expr, str nme, int execute, bit output)
{
- int pstatus = 0;
+ int status = 0;
int err = 0;
mvc *o, *m;
int ac, sizevars, topvars;
sql_var *vars;
buffer *b;
char *n;
+ stream *buf;
str msg = MAL_SUCCEED;
- backend *sql = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ backend *be, *sql = ((backend *) c->state[MAL_SCENARIO_PARSER]);
size_t len = strlen(*expr);
#ifdef _SQL_COMPILE
@@ -595,15 +596,16 @@
initSQLreferences();
m = sql->mvc;
ac = m->session->auto_commit;
- SQLtrans(m);
- pstatus = m->session->status;
-
o = NEW(mvc);
if (!o)
throw(SQL, "SQLstatement", "Out of memory");
*o = *m;
+ SQLtrans(m);
+ status = m->session->status;
+
m->type= Q_PARSE;
+ be = sql;
sql = backend_create(m, c);
m->qc = NULL;
m->prepare_qc = NULL;
@@ -617,9 +619,8 @@
n[len+1] = 0;
len++;
buffer_init(b, n, len);
- scanner_init( &m->scanner,
- bstream_create(buffer_rastream(b, "sqlstatement"), b->len),
- NULL);
+ buf = buffer_rastream(b, "sqlstatement");
+ scanner_init( &m->scanner, bstream_create(buf , b->len), NULL);
m->scanner.mode = LINE_N;
bstream_next(m->scanner.rs);
@@ -627,11 +628,15 @@
m->argc = 0;
m->session->auto_commit = 0;
+ /* create private allocator */
+ m->sa = sa_create();
+
@-
System has been prepared to parse it and generate code.
Scan the complete string for SQL statements, stop at the first error.
@c
- for( ;; ){
+ c->state[MAL_SCENARIO_PARSER] = sql;
+ while( m->scanner.rs->pos < m->scanner.rs->len ){
if (!m->sa)
m->sa = sa_create();
m->sym = NULL;
@@ -640,12 +645,12 @@
(mvc_status(m) && m->type != Q_TRANS) || !m->sym) {
if (!err)
err = mvc_status(m);
- if( m->errstr)
+ if (m->errstr && *m->errstr)
msg = createException(PARSE, "SQLparser", "%s",
m->errstr);
- else
- msg = createException(PARSE, "SQLparser",
"Parser errors");
*m->errstr = 0;
sqlcleanup(m, err);
+ if (!err)
+ continue;
goto endofcompile;
}
@-
@@ -656,7 +661,8 @@
We don;t search the cache for a previous incarnation yet.
@c
{
- Symbol oldsym= c->curprg;
+ int oldvtop = c->curprg->def->vtop;
+ int oldstop = c->curprg->def->stop;
stmt *s = sql_symbol2stmt(m, m->sym);
#ifdef _SQL_COMPILE
@@ -665,14 +671,13 @@
scanner_query_processed(&(m->scanner));
MSinitClientPrg(c,"user",nme);
if (s==0 || (err = mvc_status(m))) {
- if ( m->errstr && *m->errstr)
- msg = createException(PARSE,
"SQLparser", "%s", m->errstr);
- else msg = MAL_SUCCEED; /* assume end of
parse */
- handle_error(m, c->fdout, pstatus);
+ msg = createException(PARSE, "SQLparser", "%s",
m->errstr?m->errstr:"");
+ handle_error(m, c->fdout, status);
sqlcleanup(m, err);
/* restore the state */
- freeSymbol(c->curprg);
- c->curprg= oldsym;
+ resetMalBlk(c->curprg->def, oldstop);
+ freeVariables(c,c->curprg->def, c->glb,
oldvtop);
+ c->curprg->def->errors = 0;
goto endofcompile;
}
/* generate MAL code */
@@ -681,8 +686,9 @@
if( c->curprg->def->errors){
/* restore the state */
- freeSymbol(c->curprg);
- c->curprg= oldsym;
+ resetMalBlk(c->curprg->def, oldstop);
+ freeVariables(c,c->curprg->def, c->glb,
oldvtop);
+ c->curprg->def->errors = 0;
goto endofcompile;
}
@@ -692,15 +698,13 @@
#endif
if ( execute) {
- backend *be = c->state[MAL_SCENARIO_PARSER];
if (!output)
sql->out = NULL; /* no output */
- c->state[MAL_SCENARIO_PARSER] = sql;
msg = (str) runMAL(c, c->curprg->def, 1, 0, 0,
0);
- c->state[MAL_SCENARIO_PARSER] = be;
- MSresetInstructions(c->curprg->def, 1);
- freeVariables(c,c->curprg->def, 0, 0);
- c->curprg= oldsym;
+ //MSresetInstructions(c->curprg->def, 1);
+ resetMalBlk(c->curprg->def, oldstop);
+ //freeVariables(c,c->curprg->def, 0, 0);
+ freeVariables(c,c->curprg->def, c->glb,
oldvtop);
}
sqlcleanup(m, 0);
}
@@ -712,11 +716,19 @@
We are done; a MAL procedure recides in the cache.
@c
endofcompile:
+ MSresetInstructions(c->curprg->def, 1);
+
+ c->state[MAL_SCENARIO_PARSER] = be;
backend_destroy(sql);
GDKfree(n);
GDKfree(b);
bstream_destroy(m->scanner.rs);
+ stream_destroy(buf);
+ if (m->sa)
+ sa_destroy(m->sa);
+ m->sym = NULL;
/* variable stack maybe resized, ie we need to keep the new stack */
+ status = m->session->status;
sizevars = m->sizevars;
topvars = m->topvars;
vars = m->vars;
@@ -725,7 +737,9 @@
m->sizevars = sizevars;
m->topvars = topvars;
m->vars = vars;
+ m->session->status = status;
m->session->auto_commit = ac;
+ m->last = NULL;
return msg;
}
diff -r b4a7028a803d -r bbe7f874d29b sql/src/server/rel_select.mx
--- a/sql/src/server/rel_select.mx Fri May 14 15:57:49 2010 +0200
+++ b/sql/src/server/rel_select.mx Sat May 15 22:45:44 2010 +0200
@@ -4091,7 +4091,7 @@
}
case SQL_TABLE: {
/* turn a subquery into a tabular result */
- *rel = rel_subquery(sql, *rel, se->data.sym, ek);
+ *rel = rel_selects(sql, se->data.sym);// *rel, se->data.sym,
ek);
if (*rel)
return rel_find_lastexp(*rel);
return NULL;
diff -r b4a7028a803d -r bbe7f874d29b sql/src/server/sql_parser.mx
--- a/sql/src/server/sql_parser.mx Fri May 14 15:57:49 2010 +0200
+++ b/sql/src/server/sql_parser.mx Sat May 15 22:45:44 2010 +0200
@@ -2911,11 +2911,20 @@
select_no_parens_orderby:
select_no_parens opt_order_by_clause opt_limit opt_offset
- { SelectNode *s = (SelectNode*)$1;
+ {
$$ = $1;
- s -> orderby = $2;
- s -> limit = $3;
- s -> offset = $4;
+ if ($2 || $3 != -1 || $4 != -1) {
+ if ($1 != NULL && $1->token == SQL_SELECT) {
+ SelectNode *s = (SelectNode*)$1;
+
+ s -> orderby = $2;
+ s -> limit = $3;
+ s -> offset = $4;
+ } else {
+ yyerror("ORDER BY: missing select operator");
+ YYABORT;
+ }
+ }
}
;
diff -r b4a7028a803d -r bbe7f874d29b sql/src/sql/createdb.mx
--- a/sql/src/sql/createdb.mx Fri May 14 15:57:49 2010 +0200
+++ b/sql/src/sql/createdb.mx Sat May 15 22:45:44 2010 +0200
@@ -24,6 +24,7 @@
is needed to run the tests.
This MX script merely pulls the files together.
@sql
+start transaction;
@include math.sql
@include times.sql
@include url.sql
@@ -83,3 +84,4 @@
parts.sql -- testing only
replication.sql -- testing only
@sql
+commit;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list