Skip to content

Error handling for batch SQL #2447

Merged
merged 1 commit into from Mar 7, 2014

2 participants

@cchantep
cchantep commented Mar 5, 2014
  • Error handling for batch SQL ('little bit' defensive considering current batch parameters types).
  • Related specifications.
@cchantep cchantep commented on the diff Mar 5, 2014
framework/src/anorm/src/main/scala/anorm/Anorm.scala
@@ -264,67 +264,6 @@ case class SimpleSql[T](sql: SqlQuery, params: Map[String, ParameterValue], defa
}
-case class BatchSql(sql: SqlQuery, params: Seq[Map[String, ParameterValue]]) {
@cchantep
cchantep added a note Mar 5, 2014

Moved in separate file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cchantep cchantep commented on the diff Mar 5, 2014
framework/src/anorm/src/main/scala/anorm/BatchSql.scala
@@ -0,0 +1,194 @@
+package anorm
+
+import java.sql.{ Connection, PreparedStatement }
+
+private[anorm] object BatchSqlErrors {
@cchantep
cchantep added a note Mar 5, 2014

Used later to scaladoc exceptions thrown at runtime for parameters 'type'/structural errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cchantep cchantep commented on the diff Mar 5, 2014
framework/src/anorm/src/main/scala/anorm/BatchSql.scala
+
+private[anorm] object BatchSqlErrors {
+ val HeterogeneousParameterMaps = "if each map hasn't same parameter names"
+ val ParameterNamesNotMatchingPlaceholders =
+ "if parameter names don't match query placeholders"
+ val UnexpectedParameterName = "if `args` contains unexpected parameter name"
+ val MissingParameter = "if `args` is missing some expected parameter names"
+}
+
+/** SQL batch */
+sealed trait BatchSql {
+ /** SQL query */
+ def sql: SqlQuery
+
+ /** Names of parameter expected for each parameter map */
+ def names: Set[String]
@cchantep
cchantep added a note Mar 5, 2014

!= sql.argsInitialOrder as there is only one map entry per parameter, even if parameter is required for several query placeholders (argsInitialOrder).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cchantep cchantep commented on the diff Mar 5, 2014
...k/src/anorm/src/main/scala/anorm/ParameterValue.scala
@@ -35,8 +35,12 @@ sealed trait ParameterValue {
* }}}
*/
object ParameterValue {
- def apply[A](value: A, s: ToSql[A], toStmt: ToStatement[A]) =
- new ParameterValue {
+ private[anorm] trait Wrapper[T] { def value: T }
@cchantep
cchantep added a note Mar 5, 2014

Private wrapper to get value without structural type inferrence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cchantep cchantep commented on the diff Mar 5, 2014
...k/src/anorm/src/main/scala/anorm/ParameterValue.scala
@@ -47,5 +51,13 @@ object ParameterValue {
}
def set(s: PreparedStatement, i: Int) = toStmt.set(s, i, value)
+
+ override lazy val toString = s"ParameterValue($value)"
+ override lazy val hashCode = value.hashCode
@cchantep
cchantep added a note Mar 5, 2014

hashCode/equals useful for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cchantep cchantep commented on the diff Mar 5, 2014
.../anorm/src/test/scala/anorm/StatementParserSpec.scala
@@ -21,12 +21,6 @@ object StatementParserSpec extends org.specs2.mutable.Specification {
SQL("SELECT name FROM t WHERE id = {id}").apply().
aka("query") must throwA[java.util.NoSuchElementException]
}
-
@cchantep
cchantep added a note Mar 5, 2014

Appropriate spec in Batch specs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jroper jroper merged commit f87ae8c into playframework:master Mar 7, 2014

1 check passed

Details default Merged build finished.
@cchantep cchantep deleted the cchantep:anorm-batchsql branch Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.