Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 22f69d7f5d06d54c61b338cb0252719f79fa3e3a 1 parent 03c95bc
Derek Chen-Becker dchenbecker authored
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] {
495 495 by match {
496 496 case Nil => curPos
497 497 case Cmp(field, _, Full(value), _, _) :: xs =>
498   - setPreparedStatementValue(conn, st, curPos, field, field.targetSQLType, value.asInstanceOf[AnyRef], objectSetterFor(field))
  498 + setPreparedStatementValue(conn, st, curPos, field, field.targetSQLType, field.convertToJDBCFriendly(value), objectSetterFor(field))
499 499 setStatementFields(st, xs, curPos + 1, conn)
500 500
501 501 case ByList(field, orgVals) :: xs => {
502 502 val vals = Set(orgVals :_*).toList
503 503 var newPos = curPos
504 504 vals.foreach(v => {
505   - setPreparedStatementValue(conn, st, newPos, field, field.targetSQLType, v.asInstanceOf[AnyRef], objectSetterFor(field))
  505 + setPreparedStatementValue(conn, st, newPos, field, field.targetSQLType, field.convertToJDBCFriendly(v), objectSetterFor(field))
506 506 newPos = newPos + 1
507 507 })
508 508
@@ -596,7 +596,6 @@ trait MetaMapper[A<:Mapper[A]] extends BaseMetaMapper with Mapper[A] {
596 596 val indVal = indexedField(toDelete)
597 597 indVal.map{indVal =>
598 598 setPreparedStatementValue(conn, st, 1, indVal, im, objectSetterFor(indVal))
599   -
600 599 st.executeUpdate == 1
601 600 } openOr false
602 601 }
2  persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpec.scala
@@ -82,6 +82,8 @@ object MapperSpec extends Specification("Mapper Specification") {
82 82 archer.moose.is must_== Empty
83 83 notNull.moose.is must_== Full(99L)
84 84
  85 + val disabled = SampleModel.find(By(SampleModel.status, SampleStatus.Disabled))
  86 +
85 87 val meow = SampleTag.find(By(SampleTag.tag, "Meow")).open_!
86 88
87 89 meow.tag.is must_== "Meow"
8 persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpecsModel.scala
@@ -106,6 +106,9 @@ class SampleTag extends LongKeyedMapper[SampleTag] with IdPK {
106 106 }
107 107 }
108 108
  109 +object SampleStatus extends Enumeration {
  110 + val Active, Disabled, Hiatus = Value
  111 +}
109 112
110 113 object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
111 114 override def dbAddTable = Full(populate _)
@@ -117,12 +120,11 @@ object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
117 120 private def populate {
118 121 create.firstName("Elwood").save
119 122 create.firstName("Madeline").save
120   - create.firstName("Archer").save
  123 + create.firstName("Archer").status(SampleStatus.Disabled).save
121 124 create.firstName("NotNull").moose(Full(99L)).save
122 125 }
123 126 }
124 127
125   -
126 128 class SampleModel extends KeyedMapper[Long, SampleModel] {
127 129 def getSingleton = SampleModel
128 130
@@ -139,6 +141,8 @@ class SampleModel extends KeyedMapper[Long, SampleModel] {
139 141 override def dbNotNull_? = true
140 142 }
141 143
  144 + object status extends MappedEnum(this, SampleStatus)
  145 +
142 146 def encodeAsJson(): JsonAST.JObject = SampleModel.encodeAsJson(this)
143 147 }
144 148

0 comments on commit 22f69d7

Please sign in to comment.
Something went wrong with that request. Please try again.