|Mapper: NULL in database column||Tobias Pfeiffer||5/11/12 2:55 AM|
I have a table in PostgreSQL that looks like
and I was checking for a row whether field has a non-empty value. However,
when I say
row.field.isEmpty (using the Mapper classes)
I get a NullPointerException if the field is not an empty string but is NULL
in the database. Is there a shorthand/failsafe notation for "field IS NULL OR
field = ''"?
|Re: [Lift] Mapper: NULL in database column||fmpwizard||5/11/12 9:28 PM|
>You can check if a value is null by using:
scala> var c = null
c: Null = null
res11: net.liftweb.common.Box[Null] = Empty
so you can use that and if you get a null value, the result is Empty
the other results would be:
scala> var c = ""
c: java.lang.String = ""
res12: net.liftweb.common.Box[java.lang.String] = ""
scala> var c = "s"
c: java.lang.String = s
res13: net.liftweb.common.Box[java.lang.String] = Full(s)
|This message has been hidden because it was flagged for abuse.|
|Re: [Lift] Mapper: NULL in database column||Tobias Pfeiffer||7/3/12 8:45 AM|
That doesn't seem to work at my place. I said
val dur = Box.legacyNullTest(film.duration)
with a NULL database field and then dur.toString shows
dur.map(d => [something with d])
still throws a NullPointerException...
|Re: [Lift] Mapper: NULL in database column||fmpwizard||7/3/12 8:51 AM|
can you post a sample app and I'll see what I can do.
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
|Re: [Lift] Mapper: NULL in database column||Tobias Pfeiffer||7/3/12 3:59 PM|
I forked lift_24_sbt and did a very small change that caused this
NullPointerException, please see
Thanks for your help
|Re: [Lift] Mapper: NULL in database column||fmpwizard||7/3/12 9:14 PM|
Ok, so the reason why legacyNullCheck is not doing what we expected is
that the value that comes from Mapper is NULL, but legacyNullCheck
expects null (lower case, which is the how scala names Null)
So this is why you get a Full(NULL) and the NPE. I'm now looking at
to see if we can just take something out of that class or if you will
have to implement your own fiels that are supposed to have Null
|Re: [Lift] Mapper: NULL in database column||fmpwizard||7/3/12 9:39 PM|
Ok, you were very close, you needed to add .is to get the columns value. Like:
println(u.duration) // NULL
val c = Box.legacyNullTest(u.duration.is)
// the following line will *not* throw a NullPointerException now :)
Hope that helps
|Re: [Lift] Mapper: NULL in database column||Jeppe Nejsum Madsen||7/4/12 1:07 AM|
Diego Medina <di...@fmpwizard.com> writes:And I think 2.5 gives a warning (that not using is/get will be
deprecated) for precisely the same reason
|Re: [Lift] Mapper: NULL in database column||fmpwizard||7/4/12 5:18 AM|
I thought that was there, thanks for the update!
|Re: [Lift] Mapper: NULL in database column||Tobias Pfeiffer||7/4/12 7:37 AM|
Very good, that works; thanks for pointing out!