Permalink
Browse files

Fixed an improper conversion of DateTimeField to BooleanExpression ra…

…ther than DateExpression. Fixed #1048.
  • Loading branch information...
1 parent 1f99c25 commit 78c38d3951f7e663cd2581b6e63b6289d9aa2661 @davewhittaker davewhittaker committed Jun 17, 2011
@@ -111,7 +111,7 @@ trait RecordTypeMode extends PrimitiveTypeMode {
/** Conversion of mandatory Calendar fields to Squeryl Expressions. */
implicit def date2ScalarDate(f: MandatoryTypedField[Calendar]) = fieldReference match {
case Some(e) => new SelectElementReference[Timestamp](e)(createOutMapperTimestampType) with DateExpression[Timestamp] with SquerylRecordNonNumericalExpression[Timestamp]
- case None => new ConstantExpressionNode[Timestamp](new Timestamp(f.is.getTimeInMillis)) with BooleanExpression[Timestamp] with SquerylRecordNonNumericalExpression[Timestamp]
+ case None => new ConstantExpressionNode[Timestamp](new Timestamp(f.is.getTimeInMillis)) with DateExpression[Timestamp] with SquerylRecordNonNumericalExpression[Timestamp]
}
/** Conversion of optional Calendar fields to Squeryl Expressions. */
@@ -122,7 +122,7 @@ trait RecordTypeMode extends PrimitiveTypeMode {
case Some(calendar) => Some(new Timestamp(calendar.getTimeInMillis))
case None => None
}
- new ConstantExpressionNode[Option[Timestamp]](date) with BooleanExpression[Option[Timestamp]] with SquerylRecordNonNumericalExpression[Option[Timestamp]]
+ new ConstantExpressionNode[Option[Timestamp]](date) with DateExpression[Option[Timestamp]] with SquerylRecordNonNumericalExpression[Option[Timestamp]]
}
}
@@ -14,12 +14,19 @@
package net.liftweb
package squerylrecord
+import org.squeryl.Session
+import org.squeryl.dsl.ast.FunctionNode
+import org.squeryl.internals.OutMapper
+import org.squeryl.dsl.StringExpression
+import org.squeryl.dsl.DateExpression
import org.specs.Specification
import record.{BaseField, Record}
import record.field._
import RecordTypeMode._
import MySchema.{TestData => td, _}
import java.util.Calendar
+import java.sql.Timestamp
+import java.text.SimpleDateFormat
/**
@@ -337,8 +344,24 @@ object SquerylRecordSpec extends Specification("SquerylRecord Specification") {
companies.update(company) must throwAn[StaleUpdateException]
}
}
+
+ forExample("Allow custom functions") in {
+ inTransaction{
+ val created =
+ from(companies)(c =>
+ where(c.name === "First Company USA")
+ select(&(toChar(c.created,"EEE, d MMM yyyy")))
+ )
+ created.head must_== new SimpleDateFormat("EEE, d MMM yyyy").format(Calendar.getInstance().getTime())
+ }
+ }
}
+
+ class ToChar(d: DateExpression[Timestamp],e: StringExpression[String], m: OutMapper[String])
+ extends FunctionNode[String]("FORMATDATETIME",Some(m), Seq(d,e)) with StringExpression[String]
+
+ def toChar(d: DateExpression[Timestamp],e: StringExpression[String])(implicit m: OutMapper[String]) = new ToChar(d,e,m)
class TransactionRollbackException extends RuntimeException

0 comments on commit 78c38d3

Please sign in to comment.