From b96aaf163e6ce757e722e95763a9dbc6f90211d5 Mon Sep 17 00:00:00 2001 From: Joern Bernhardt Date: Thu, 28 Jan 2016 01:48:42 +0100 Subject: [PATCH] Add test to show issue with numeric columns Signed-off-by: Joern Bernhardt --- .../async/db/postgresql/NumericSpec.scala | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/NumericSpec.scala diff --git a/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/NumericSpec.scala b/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/NumericSpec.scala new file mode 100644 index 00000000..26c13f4d --- /dev/null +++ b/postgresql-async/src/test/scala/com/github/mauricio/async/db/postgresql/NumericSpec.scala @@ -0,0 +1,57 @@ +package com.github.mauricio.async.db.postgresql + +import org.specs2.mutable.Specification + +class NumericSpec extends Specification with DatabaseTestHelper { + + "when processing numeric columns" should { + + "support first update of num column with floating" in { + + withHandler { + handler => + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") + + val id = executePreparedStatement(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](1234, id)) + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) + + id === 1 + } + + } + + "support first update of num column with integer (fails currently)" in { + + withHandler { + handler => + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") + + val id = executePreparedStatement(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](1234, id)) + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) + + id === 1 + } + + } + + "support using first update with queries instead of prepared statements" in { + + withHandler { + handler => + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") + + val id = executeQuery(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") + executeQuery(handler, s"UPDATE numeric_test SET numcol = 1234 WHERE id = $id") + executeQuery(handler, s"UPDATE numeric_test SET numcol = 123.123 WHERE id = $id") + + id === 1 + } + + } + + } + +}