playframework/playframework — pull request #1988 by cchantep (2013-11-06 11:24:02+00:00)
Title: SqlQueryResult with statement warning

When using Anorm with result from old school stored proc, current way to check warning (that proc may raise) can be improved.

Currently something like:
```scala
val rs: java.sql.ResultSet = SQL("EXEC some_stored_proc")

rs.getStatement.getWarnings match {
case null ⇒ // No warning, can go one
Sql.resultSetToStream(rs).headOption/* get back to Anorm types */
case warn ⇒
warn.printStackTrace()
None
}
```

`java.sql.ResultSet` rs instance need to be used as `Sql.resultSet()` prepare and execute statement each time:
```scala
val sql = SQL("EXEC stored_proc")

sql.resultSet.getStatement.getWarnings match { // 1st query execution to get 1st resultset instance
case null ⇒ sql.as(...) // 2nd query execution
// ...
}
```
Letting appart efficiency of executing it twice, in this way warning from `getWarnings` may not be the one accurate from statement of data mapped with `sql.as(...)` (as each are related to different execution).

I think adding a case class like `SqlQueryResult` in this PR would help to execute once, be able to work with execution context (there getting warning from executed statement), and go on with Anorm mapping/parsing features against resultSet in the same execution:

```scala
val res = SQL("EXEC stored_proc").executeQuery() // executeQuery added to trait Sql

res.statementWarning match {
case null ⇒ res.as(...) // go on with any parsing-mapping functions similar to those in trait Sql
case warn ⇒ warn.printStackTrace(); ...
}
```