Update of /cvsroot/monetdb/pathfinder/compiler/sql
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29502/sql
Modified Files:
lalg2sql.brg sql.c sqlprint.c
Log Message:
Use the DB2 specific `raise_error' function to throw errors durings runtime.
Index: sql.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/sql/sql.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- sql.c 24 Feb 2008 17:22:28 -0000 1.55
+++ sql.c 14 Mar 2008 12:57:26 -0000 1.56
@@ -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.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- lalg2sql.brg 10 Mar 2008 09:09:04 -0000 1.123
+++ lalg2sql.brg 14 Mar 2008 12:57:24 -0000 1.124
@@ -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.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- sqlprint.c 15 Feb 2008 12:37:41 -0000 1.47
+++ sqlprint.c 14 Mar 2008 12:57:26 -0000 1.48
@@ -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