Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13827/compiler/sql
Modified Files:
Tag: xquery-decomposition
lalg2sql.brg sql.c sqlprint.c
Log Message:
propagated changes of Monday Mar 10 2008 - Monday Mar 17 2008
from the development trunk to the xquery-decomposition branch
===================================================================
2008/03/11 - mayrm: tests/BugsViaSourgeforce/Tests/All,1.37
Add test for Bug 1908622 from Sourceforge.
===================================================================
2008/03/14 - mayrm: compiler/include/sql.h,1.47
compiler/include/sql_mnemonic.h,1.38 compiler/sql/lalg2sql.brg,1.124
compiler/sql/sql.c,1.56 compiler/sql/sqlprint.c,1.48
Use the DB2 specific `raise_error' function to throw errors durings runtime.
===================================================================
2008/03/17 - sjoerd: runtime/pathfinder.mx,1.406
propagated changes of Friday Mar 07 2008 - Monday Mar 17 2008
from the XQuery_0-22 branch to the development trunk
===================================================================
2008/03/14 - nielsnes: runtime/pathfinder.mx,1.399.2.6
sum now returns NULL for empty bats
so, introduced an old_sum which has the old semantics
===================================================================
===================================================================
Index: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.47.2.6
retrieving revision 1.47.2.7
diff -u -d -r1.47.2.6 -r1.47.2.7
--- sql.c 24 Feb 2008 20:19:59 -0000 1.47.2.6
+++ sql.c 17 Mar 2008 14:32:53 -0000 1.47.2.7
@@ -1166,6 +1166,18 @@
}
/**
+ * Create a DB2 runtime error
+ */
+PFsql_t * PFsql_raise_error (PFsql_t *state, PFsql_t *message)
+{
+ assert (state->kind == sql_lit_str &&
+ message->kind == sql_lit_str);
+
+ return wire2 (sql_db2_raise_error, state, message);
+}
+
+
+/**
* Duplicate a given SQL tree.
*/
PFsql_t *
@@ -1349,6 +1361,7 @@
case sql_col_pos: return "pos";
case sql_col_guide: return "guide";
case sql_col_max: return "max";
+ case sql_col_err: return "err";
case sql_col_dist:
assert (name->ty < 100);
res = (char *) PFmalloc (7);
Index: lalg2sql.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/lalg2sql.brg,v
retrieving revision 1.102.2.9
retrieving revision 1.102.2.10
diff -u -d -r1.102.2.9 -r1.102.2.10
--- lalg2sql.brg 10 Mar 2008 10:48:55 -0000 1.102.2.9
+++ lalg2sql.brg 17 Mar 2008 14:32:50 -0000 1.102.2.10
@@ -470,6 +470,7 @@
#define POS_ column_name (special_col (sql_col_pos))
#define MAX_ column_name (special_col (sql_col_max))
#define DIST_ column_name (special_col (sql_col_dist))
+#define ERR_ column_name (special_col (sql_col_err))
#define PRE(n) ext_column_name (n, special_col (sql_col_pre))
#define SIZE(n) ext_column_name (n, special_col (sql_col_size))
@@ -4580,12 +4581,73 @@
break;
/* Rel: cond_err (Rel, Rel) */
- case 99:
+
+ /********************************************************/
+ /* cond_err */
+ /* / \ */
+ /* / \ */
+ /* /\ /\ */
+ /* /q1\ /q2\ */
+ /* ------ ------ */
+ /* We will translate this plan into the following */
+ /* SQL query. */
+ /* */
+ /* SELECT q.* */
+ /* FROM q1 AS q, (SELECT CASE */
+ /* WHEN MIN(CASE */
+ /* WHEN att THEN 1 */
+ /* ELSE 0 */
+ /* END) < 1 */
+ /* THEN raise_error */
+ /* ELSE 1 END */
+ /* FROM q2 AS err) AS foo; */
+ /********************************************************/
+ case 99: {
+#define ERR_SQLSTATE "70001"
+ assert (kids[0] && nts[0]);
+ assert (kids[1] && nts[1]);
+
+ PFsql_t *expr = NULL,
+ *n = NULL;
+ PFalg_simple_type_t ty;
+ char *msg = p->sem.err.str;
+
reduce (kids[0], nts[0]);
/* copy all existing column, from, and where lists */
copy_cols_from_where (p, L(p));
- break;
+
+ reduce (kids[1], nts[1]);
+
+ ty = type_of (R(p), p->sem.err.att);
+ assert (monomorphic (ty) && ty == aat_bln);
+ expr = col_env_lookup (COLMAP(R(p)),
+ p->sem.err.att,
+ ty);
+
+ n = expr;
+
+ /* if the underlying relation containing is bound,
+ * we can directly using the column */
+ n = (n->kind == sql_column_name ||
+ n->kind == sql_lit_int)
+ ? n
+ : case_ (when (n, TRUE_INT), else_ (FALSE_INT));
+
+ n = case_ (when (gt (TRUE_INT, min_ (n)),
+ raise_error (lit_str (ERR_SQLSTATE),
+ lit_str (msg))),
+ else_ (TRUE_INT));
+
+ PFsql_aident_t nalias = new_alias ();
+
+ from_list_add (FROMLIST (p),
+ select (
+ column_assign (n, ERR_),
+ transform_frommap (R(p)),
+ transform_wheremap (R(p))
+ ), alias (nalias));
+ } break;
/* Rel: trace (Rel, Msg) */
case 100:
Index: sqlprint.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sqlprint.c,v
retrieving revision 1.44.2.2
retrieving revision 1.44.2.3
diff -u -d -r1.44.2.2 -r1.44.2.3
--- sqlprint.c 16 Feb 2008 01:02:20 -0000 1.44.2.2
+++ sqlprint.c 17 Mar 2008 14:32:54 -0000 1.44.2.3
@@ -545,6 +545,20 @@
}
static void
+print_raise_error (PFsql_t *n)
+{
+ assert (n);
+ assert (L(n) && R(n));
+ assert (n->kind == sql_db2_raise_error);
+
+ PFprettyprintf ("raise_error (");
+ print_literal (L(n));
+ PFprettyprintf (",");
+ print_literal (R(n));
+ PFprettyprintf (")");
+}
+
+static void
print_case (PFsql_t *n)
{
assert (n);
@@ -559,12 +573,18 @@
PFprettyprintf ("WHEN ");
print_condition (L(n));
PFprettyprintf (" THEN ");
- print_statement (R(n));
+ if (R(n)->kind != sql_db2_raise_error)
+ print_statement (R(n));
+ else
+ print_raise_error (R(n));
break;
case sql_else:
PFprettyprintf (" ELSE ");
- print_statement (L(n));
+ if (L(n)->kind != sql_db2_raise_error)
+ print_statement (L(n));
+ else
+ print_raise_error (L(n));
break;
case sql_nil:
@@ -862,7 +882,7 @@
case sql_tbl_name:
print_tablereference (f, n, i);
break;
-
+
case sql_on:
print_join (f, n, i);
break;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins