Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for a bug introduced by #965 (DB2 support)

Refs #965

Missed two calls to convertToJDBCFriendly when refactoring. This
caused JDBC drivers to throw exceptions or otherwise fail
when doing "By" queries against certain Mapper fields. In addition
to fixing the issue, I've added a small bit to the MapperSpec to
detect the condition using MappedEnum
  • Loading branch information...
commit 1a57d8e14f4649b2e60933efb72c2ccd3bfaf184 1 parent 2ecb4d1
@dchenbecker dchenbecker authored
View
5 persistence/mapper/src/main/scala/net/liftweb/mapper/MetaMapper.scala
@@ -495,14 +495,14 @@ trait MetaMapper[A<:Mapper[A]] extends BaseMetaMapper with Mapper[A] {
by match {
case Nil => curPos
case Cmp(field, _, Full(value), _, _) :: xs =>
- setPreparedStatementValue(conn, st, curPos, field, field.targetSQLType, value.asInstanceOf[AnyRef], objectSetterFor(field))
+ setPreparedStatementValue(conn, st, curPos, field, field.targetSQLType, field.convertToJDBCFriendly(value), objectSetterFor(field))
setStatementFields(st, xs, curPos + 1, conn)
case ByList(field, orgVals) :: xs => {
val vals = Set(orgVals :_*).toList
var newPos = curPos
vals.foreach(v => {
- setPreparedStatementValue(conn, st, newPos, field, field.targetSQLType, v.asInstanceOf[AnyRef], objectSetterFor(field))
+ setPreparedStatementValue(conn, st, newPos, field, field.targetSQLType, field.convertToJDBCFriendly(v), objectSetterFor(field))
newPos = newPos + 1
})
@@ -596,7 +596,6 @@ trait MetaMapper[A<:Mapper[A]] extends BaseMetaMapper with Mapper[A] {
val indVal = indexedField(toDelete)
indVal.map{indVal =>
setPreparedStatementValue(conn, st, 1, indVal, im, objectSetterFor(indVal))
-
st.executeUpdate == 1
} openOr false
}
View
2  persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpec.scala
@@ -82,6 +82,8 @@ object MapperSpec extends Specification("Mapper Specification") {
archer.moose.is must_== Empty
notNull.moose.is must_== Full(99L)
+ val disabled = SampleModel.find(By(SampleModel.status, SampleStatus.Disabled))
+
val meow = SampleTag.find(By(SampleTag.tag, "Meow")).open_!
meow.tag.is must_== "Meow"
View
8 persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpecsModel.scala
@@ -106,6 +106,9 @@ class SampleTag extends LongKeyedMapper[SampleTag] with IdPK {
}
}
+object SampleStatus extends Enumeration {
+ val Active, Disabled, Hiatus = Value
+}
object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
override def dbAddTable = Full(populate _)
@@ -117,12 +120,11 @@ object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
private def populate {
create.firstName("Elwood").save
create.firstName("Madeline").save
- create.firstName("Archer").save
+ create.firstName("Archer").status(SampleStatus.Disabled).save
create.firstName("NotNull").moose(Full(99L)).save
}
}
-
class SampleModel extends KeyedMapper[Long, SampleModel] {
def getSingleton = SampleModel
@@ -139,6 +141,8 @@ class SampleModel extends KeyedMapper[Long, SampleModel] {
override def dbNotNull_? = true
}
+ object status extends MappedEnum(this, SampleStatus)
+
def encodeAsJson(): JsonAST.JObject = SampleModel.encodeAsJson(this)
}
Please sign in to comment.
Something went wrong with that request. Please try again.