Commit 93cf675f authored by Ryan Wisnesky's avatar Ryan Wisnesky
Browse files

one more for Fred

parent a14e75b5
Loading
Loading
Loading
Loading
+11 −5
Changes for src/catdata/aql/Query.java: 11 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -893,10 +893,10 @@ public final class Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> implements Sem
			} else if (eq.lhs.sk != null) {
				newLhs = "?";
				if (consts.containsKey(eq.lhs.sk)) {
					newLhs = quotePrim(consts.get(eq.lhs.sk).convert()).toString();
					newLhs = quotePrim(consts.get(eq.lhs.sk).convert()).toStringSql();
				}
			} else {
				newLhs = quotePrim(eq.lhs).toString();
				newLhs = quotePrim(eq.lhs).toStringSql();
			}
			String newRhs;
			if (eq.rhs.gen != null) {
@@ -904,10 +904,10 @@ public final class Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> implements Sem
			} else if (eq.rhs.sk != null) {
				newRhs = "?";
			if (consts.containsKey(eq.rhs.sk)) {
					newRhs = quotePrim(consts.get(eq.rhs.sk).convert()).toString();
					newRhs = quotePrim(consts.get(eq.rhs.sk).convert()).toStringSql();
				}
			} else {
				newRhs = quotePrim(eq.rhs).toString();
				newRhs = quotePrim(eq.rhs).toStringSql();
			}
			temp.add(newLhs + " = " + newRhs);
		}
@@ -916,7 +916,7 @@ public final class Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> implements Sem
	}

	private Term<Ty, En1, Sym, Fk1, Att1, Var, Var> quotePrim(Term<Ty, En1, Sym, Fk1, Att1, Var, Var> t) {
		if (t.var != null || t.gen != null) {
		if (t.var != null || t.gen != null || t.sk != null) {
			return t;
		} else if (t.sym != null && t.args.size() == 0) {
			return t;
@@ -926,6 +926,12 @@ public final class Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> implements Sem
			return Term.Att(t.att, quotePrim(t.arg));
		} else if (t.obj != null) {
			return Term.Obj("'" + t.obj + "'", t.ty);
		} else if (t.sym != null) {
			List<Term<Ty, En1, Sym, Fk1, Att1, Var, Var>> l = new LinkedList<>();
			for (Term<Ty, En1, Sym, Fk1, Att1, Var, Var> x : t.args) {
				l.add(quotePrim(x));
			}
			return Term.Sym(t.sym, l);
		} 
		return Util.anomaly();
	}
+23 −0
Changes for src/catdata/aql/Term.java: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -291,6 +291,29 @@ public final class Term<Ty, En, Sym, Fk, Att, Gen, Sk> {
		this.ty = ty;
	}
	
	public String toStringSql() {
		if (var != null) {
			return var.toString();
		} else if (sym != null) {
			if (args.isEmpty()) {
				return sym.toString();
			} else {
				return sym.toString() + "(" + Util.sep(args.stream().map(x -> x.toStringSql()).collect(Collectors.toList()), ", ") + ")";
			}
		} else if (att != null) {
			return arg.toStringSql() + "." + att.toString();
		} else if (fk != null) {
			return arg.toStringSql() + "." + fk.toString();
		} else if (gen != null) {
			return gen.toString(); 
		} else if (sk != null) {
			return sk.toString();
		} else if (obj != null) {
			return obj.toString(); // + "@" + ty;
		}
		throw new RuntimeException("Anomaly: please report");
	}

	//TODO: eventually, will want to quote, escape, etc
	public String toString(Function<Sk, String> sk_printer, Function<Gen, String> gen_printer) {
		if (var != null) {
+3 −2
Changes for src/catdata/aql/gui/AqlViewer.java: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -570,7 +570,7 @@ public final class AqlViewer implements SemanticsVisitor<Unit, JTabbedPane, Runt
			ret.add("SQL", comp); 
		} catch (Exception ex) {
			ex.printStackTrace();
			ret.add("SQL", new CodeTextPanel("Exception", ex.getMessage()));
			ret.add("SQL Exn", new CodeTextPanel("Exception", ex.getMessage()));
		}   
		return new Unit();
	}
@@ -580,7 +580,8 @@ public final class AqlViewer implements SemanticsVisitor<Unit, JTabbedPane, Runt
			List<String> l = q.toSQLViews("input", "output", "id", "varchar").first;
			return new CodeTextPanel("", Util.sep(l, ";\n\n"));
		} catch (Exception ex) {
			return new CodeTextPanel("", ex.getMessage());
			ex.printStackTrace();
			return new CodeTextPanel("SQL exn", ex.getMessage());
		}
	}