|
| 1 | +package com.github.mauricio.async.db.postgresql |
| 2 | + |
| 3 | +import org.specs2.mutable.Specification |
| 4 | + |
| 5 | +class NumericSpec extends Specification with DatabaseTestHelper { |
| 6 | + |
| 7 | + "when processing numeric columns" should { |
| 8 | + |
| 9 | + "support first update of num column with floating" in { |
| 10 | + |
| 11 | + withHandler { |
| 12 | + handler => |
| 13 | + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") |
| 14 | + |
| 15 | + val id = executePreparedStatement(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") |
| 16 | + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) |
| 17 | + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](1234, id)) |
| 18 | + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) |
| 19 | + |
| 20 | + id === 1 |
| 21 | + } |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + "support first update of num column with integer (fails currently)" in { |
| 26 | + |
| 27 | + withHandler { |
| 28 | + handler => |
| 29 | + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") |
| 30 | + |
| 31 | + val id = executePreparedStatement(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") |
| 32 | + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](1234, id)) |
| 33 | + executePreparedStatement(handler, "UPDATE numeric_test SET numcol = ? WHERE id = ?", Array[Any](123.123, id)) |
| 34 | + |
| 35 | + id === 1 |
| 36 | + } |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + "support using first update with queries instead of prepared statements" in { |
| 41 | + |
| 42 | + withHandler { |
| 43 | + handler => |
| 44 | + executeDdl(handler, "CREATE TEMP TABLE numeric_test (id BIGSERIAL, numcol NUMERIC)") |
| 45 | + |
| 46 | + val id = executeQuery(handler, "INSERT INTO numeric_test DEFAULT VALUES RETURNING id").rows.get(0)("id") |
| 47 | + executeQuery(handler, s"UPDATE numeric_test SET numcol = 1234 WHERE id = $id") |
| 48 | + executeQuery(handler, s"UPDATE numeric_test SET numcol = 123.123 WHERE id = $id") |
| 49 | + |
| 50 | + id === 1 |
| 51 | + } |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments