BooleanField always returns false in squeryl-record

22 views
Skip to first unread message

Rusho

unread,
Mar 4, 2011, 9:10:22 AM3/4/11
to Squeryl
Hi all,

I'm not sure if it's a Squeryl issue or Lift Squeryl-record issue.
However, I use Squeryl-record in my project, and if I have a
BooleanField defined, it always returns false, although in database
there's true.

From Squeryl logs it seems, that squeryl is correctly getting true
value, but I'm not sure at which level squeryl logs fetched data, so
it might be, that it's squeryl's problem too, not squeryl-record's

A friend of mine posted the issue on Lift's googlegroup, but nobody
answered so far: http://groups.google.com/group/liftweb/browse_thread/thread/5a9ff35bd647e04a#

It seems as a bug to me, so I'm posting it here too, as I'm not sure
where it belongs.

Thanks

Rusho

Maxime Lévesque

unread,
Mar 4, 2011, 10:40:37 AM3/4/11
to squ...@googlegroups.com

It has to be happening here :

https://github.com/lift/framework/blob/master/persistence/squeryl-record/src/main/scala/net/liftweb/squerylrecord/RecordMetaDataFactory.scala#L121


in this method :

      override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) =
        fieldFor(target).setFromAny(Box!!resultSetHandler(rs, index))

If you can trace what is happening, like this :

  override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) =
        fieldFor(target).setFromAny {
val r = resultSetHandler(rs, index)
println(r) // <-----
Box!! r
}

it will be very helpful

you can override RecordMetaDataFactory :
class YourRecordMetaDataFactory extends RecordMetaDataFactory {
....
override def build(parentMetaData: PosoMetaData[_], name: String,
            property: (Option[Field], Option[Method], Option[Method], Set[Annotation]),
            sampleInstance4OptionTypeDeduction: AnyRef, isOptimisticCounter: Boolean)
{
..... copy the code from the parent class, and override setFromResultSet
to be able to insert trace code....
}
}

and do this after bootstrapping :

FieldMetaData.factory = new YourRecordMetaDataFactory

to override the RecordMetaDataFactory set here :


I'm not setup to debug Lift right now, but in 15 minutes you should be able to
do the above investigation without the need to checkout the lift source code....

ML


Rusho

unread,
Mar 4, 2011, 12:39:08 PM3/4/11
to Squeryl
Thanks Maxime,

I did the trace you suggested, and it returned TRUE, which is correct.

Funny, it means that from Squeryl side everything is correct and even
Squeryl-record gets it correct at some point.

Rusho

On 4. Mar., 16:40 h., Maxime Lévesque <maxime.leves...@gmail.com>
wrote:
> It has to be happening here :
>
> https://github.com/lift/framework/blob/master/persistence/squeryl-rec...
>
> in this method :
>
>       override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) =
>         fieldFor(target).setFromAny(Box!!resultSetHandler(rs, index))
> *
> *
> *If you can trace what is happening, like this :*
>
>   override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) =
>         fieldFor(target).setFromAny* {*
> *            val r = resultSetHandler(rs, index)*
> *            println(r) // <-----*
>             Box!! r
>         }
>
> *it will be very helpful*
>
> you can override RecordMetaDataFactory :
> class YourRecordMetaDataFactory extends RecordMetaDataFactory {
> ....
>
> override def build(parentMetaData: PosoMetaData[_], name: String,
>             property: (Option[Field], Option[Method], Option[Method],
> Set[Annotation]),
>             sampleInstance4OptionTypeDeduction: AnyRef,
> isOptimisticCounter: Boolean)
>  {
> ..... copy the code from the parent class, and override setFromResultSet
> to be able to insert trace code....
> *}*
>
> *}*
> *
> *
> *and do this after bootstrapping :*
> *
> *
> *FieldMetaData.factory = new YourRecordMetaDataFactory*
>
> to override the *RecordMetaDataFactory set here :*
> *
> *https://github.com/lift/framework/blob/master/persistence/squeryl-rec...
>
> *I'm not setup to debug Lift right now, but in 15 minutes you should be able
> to *
> *do the above investigation without the need to checkout the lift source
> code....*
> *
> *
> *ML*
> *
> *
>
>
>
> On Fri, Mar 4, 2011 at 4:10 PM, Rusho <ras...@gmail.com> wrote:
> > Hi all,
>
> > I'm not sure if it's a Squeryl issue or Lift Squeryl-record issue.
> > However, I use Squeryl-record in my project, and if I have a
> > BooleanField defined, it always returns false, although in database
> > there's true.
>
> > From Squeryl logs it seems, that squeryl is correctly getting true
> > value, but I'm not sure at which level squeryl logs fetched data, so
> > it might be, that it's squeryl's problem too, not squeryl-record's
>
> > A friend of mine posted the issue on Lift's googlegroup, but nobody
> > answered so far:
> >http://groups.google.com/group/liftweb/browse_thread/thread/5a9ff35bd...

Maxime Lévesque

unread,
Mar 4, 2011, 3:08:48 PM3/4/11
to squ...@googlegroups.com
If you mean that :
println(r) // <-----

returns the correct result, in 

  override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) =
        fieldFor(target).setFromAny {
            val r = resultSetHandler(rs, index)
            println(r) // <-----
            Box!! r
        }

then the culprit has to be 
inside one of these call :

  fieldFor(target).setFromAny( v )

...
in Record code ...

Maxime Lévesque

unread,
Mar 4, 2011, 6:54:53 PM3/4/11
to squ...@googlegroups.com

Could try this : 
  override setFromAny(...) in you boolean field, dump the exact value that it is getting
?

Thanks

2011/3/4 Maxime Lévesque <maxime....@gmail.com>

Rusho

unread,
Mar 7, 2011, 7:41:18 AM3/7/11
to Squeryl
Ok, I think I got it, problem seems to be in Record. In
setFromAny(...), incoming parameter, that is passed to
genericSetFromAny(...) is Full(true), however genericSetFromAny
returns Full(false). In genericSetFromAny it doesn't match any of
cases there (possibly could match only 'case Full(value) if
m.erasure.isInstance(value)', but I don't understand that Manifest
stuff, so I don't know why it doesn't match it), so it falls back to:

case other => setFromString(String.valueOf(other))

as this 'other' is Full(true), String.valueOf(other) returns string
"Full(true)" that is passed to setFromString(...). And from such
string, FALSE is the only thing, that can come out.



On 5. Mar., 00:54 h., Maxime Lévesque <maxime.leves...@gmail.com>
wrote:
> Could try this :
>   override setFromAny(...) in you boolean field, dump the exact value that
> it is getting
> ?
>
> Thanks
>
> 2011/3/4 Maxime Lévesque <maxime.leves...@gmail.com>
Reply all
Reply to author
Forward
0 new messages