0

I am trying to use squeryl and update a column with another value concatenated with a string. So at first I tried this (simplified/contrived example):

update(songs)(s =>
where(s.name isNull)
set(s.year_str := Some(s.default_year + " AD"))

This results in the query:

update `songs` set
`year_str` = (`songs`.`default_year`)
Where `songs`.`name` is null

Notice the concatenation is gone!

I read the squeryl documentation and tried with:

update(songs)(s =>
where(s.name isNull)
set(s.year_str := Some(&(s.default_year || " AD")))

this resulted in a NullPointerException

Caused by: java.lang.NullPointerException: null
at org.squeryl.internals.FieldReferenceLinker$.pushExpressionOrCollectValue(FieldReferenceLinker.scala:36) ~[squeryl_2.10-0.9.6-M1.jar:0.9.6-M1]
at org.squeryl.dsl.QueryDsl$class.$amp(QueryDsl.scala:204) ~[squeryl_2.10-0.9.6-M1.jar:0.9.6-M1]
...

What is the squeryl way to generate the following query:

update `songs` set
`year_str` = concat(`songs`.`default_year`, 'AD')
Where `songs`.`name` is null
calvinkrishy
  • 3,798
  • 8
  • 30
  • 45
  • This looks like a bug to me. Probably related to the differences between how Squeryl track field access in selects vs updates. Would you mind posting about this at https://groups.google.com/forum/#!forum/squeryl? I think it's something Max should take a look at. – Dave Whittaker Nov 14 '13 at 21:13

1 Answers1

0

You need to use the .~ operator, to convert the field "s.default_year" into an AST node, try this :

update(songs)(s =>
  where(s.name isNull)
  set(s.year_str := s.default_year.~ || " AD")
)

If you're using a pre 0.9.6 version of Squeryl you might have to do this instead :

set(s.year_str := s.default_year.~ || Some(" AD"))
Max L.
  • 9,774
  • 15
  • 56
  • 86