--- a/src/main/scala/SQL.scala Thu Jan 07 12:32:15 2010 -0500
+++ b/src/main/scala/SQL.scala Thu Jan 07 19:16:51 2010 -0500
@@ -16,7 +16,7 @@
sealed abstract class RelationORSubselect
case class Subselect(sel:SelectORUnion) extends RelationORSubselect {
- override def toString = "(\n" + sel + "\n )"
+ override def toString = "(\n " + sel.toString.replace("\n", "\n ") + "\n )"
}
sealed abstract class SelectORUnion
case class Select(attributelist:AttributeList, tablelist:TableList, expression:Option[Expression]) extends SelectORUnion {
@@ -29,11 +29,11 @@
override def toString = n.s /* "'" + n.s + "'" */
}
case class Union(disjoints:Set[Select]) extends SelectORUnion {
- override def toString = "\n" + (disjoints mkString ("\nUNION\n")) + "\n)"
+ override def toString = " " + (disjoints.toList.map(s => s.toString.replace("\n", "\n ")).mkString("\nUNION\n "))
}
case class AttributeList(attributes:Set[NamedAttribute]) {
// foo, bar
- override def toString = "SELECT "+(attributes mkString (",\n "))
+ override def toString = "SELECT "+(attributes.toList.sortWith((l, r) => l.attralias.toString < r.attralias.toString).mkString(", "))
}
case class NamedAttribute(value:RelAliasAttributeORExpression, attralias:AttrAlias) {
override def toString = value + " AS " + attralias
@@ -78,7 +78,7 @@
}
sealed abstract class Expression extends RelAliasAttributeORExpression
case class ExprConjunction(exprs:Set[Expression]) extends Expression {
- override def toString = "(" + (exprs mkString (")\n AND (")) + ")"
+ override def toString = "(" + (exprs.toList.sortWith((l, r) => l.toString < r.toString).mkString (")\n AND (")) + ")"
}
case class ExprDisjunction(exprs:Set[Expression]) extends Expression {
override def toString = "(" + (exprs mkString (") OR (")) + ")"
@@ -86,6 +86,29 @@
sealed abstract class RelationalExpression extends Expression
case class RelationalExpressionEq(l:Expression, r:Expression) extends RelationalExpression {
override def toString = l + "=" + r
+ /* safer operator== , but doesn't quite work yet. */
+ // override def hashCode = 41 * l.hashCode + r.hashCode
+ // override def equals(other: Any) = other match {
+ // case that: RelationalExpressionEq =>
+ // (that canEqual this) &&
+ // ( ( (this.l == that.l) && (this.r == that.r) ||
+ // (this.l == that.r) && (this.r == that.l) ) )
+ // case _ =>
+ // false
+ // }
+ // override def canEqual(other: Any) =
+ // other.isInstanceOf[RelationalExpressionEq]
+
+ override def equals(that:Any) =
+ that match {
+ case RelationalExpressionEq(l1, r1) => (l == l1 && r == r1) || (r == l1 && l == r1)
+ case _ => false
+ }
+ override def hashCode =
+ if (r.hashCode < l.hashCode)
+ r.hashCode + l.hashCode
+ else
+ l.hashCode + r.hashCode
}
case class RelationalExpressionNe(l:Expression, r:Expression) extends RelationalExpression {
override def toString = l + "!=" + r
@@ -104,7 +127,11 @@
override def toString = "" + fqattribute
}
case class PrimaryExpressionTyped(datatype:Datatype, i:Name) extends PrimaryExpression {
- override def toString = i.s /* "'" + i.s + "'" */ /* + datatype */
+ override def toString = /* "'" + i.s + "'" */ /* + datatype */
+ datatype match {
+ case Datatype("Int") => i.s
+ case _ => "\"" + i.s + "\""
+ }
}
case class ConstNULL() extends PrimaryExpression {
override def toString = "NULL"