Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RowParser for Optional Long #53

Open
krjackso opened this issue Sep 21, 2017 · 0 comments
Open

RowParser for Optional Long #53

krjackso opened this issue Sep 21, 2017 · 0 comments
Labels

Comments

@krjackso
Copy link

I was doing a query like this:

sql"""SELECT SUM(x) as c FROM table WHERE ...""".as[Option[Long]]

and trying to parse with this

implicit val sumParser: RowParser[Long] = RowParser(RowParser.long("c"))

It works fine until SUM(x) is NULL which happens when there are no rows (due to where clause). I get this exception:

Caused by: java.util.NoSuchElementException: None.get
	at scala.None$.get(Option.scala:347)
	at scala.None$.get(Option.scala:345)
	at com.lucidchart.relate.SqlRow.long(SqlRow.scala:116)
	at com.lucidchart.relate.RowParser$$anonfun$long$1.apply(RowParser.scala:19)
	at com.lucidchart.relate.RowParser$$anonfun$long$1.apply(RowParser.scala:19)
	at com.lucidchart.relate.RowParser$$anon$1.parse(RowParser.scala:13)
	at com.lucidchart.relate.RowParser$$anonfun$limitedCollection$1$$anonfun$apply$1.apply(RowParser.scala:31)
	at com.lucidchart.relate.RowParser$$anonfun$limitedCollection$1$$anonfun$apply$1.apply(RowParser.scala:29)
	at com.lucidchart.relate.ResultSetWrapper$class.withResultSet(ResultSetWrapper.scala:18)
	at com.lucidchart.relate.SqlRow.withResultSet(SqlRow.scala:16)

I was able to work around it by changing my query but it should be fixed:
sql"""SELECT COALESCE(SUM(x), 0) as c FROM table WHERE ...""".as[Option[Long]]

@krjackso krjackso added the bug label Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant