Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Error using NUMERIC columns with PreparedStatements in PostgreSQL #164

Merged
merged 1 commit into from
Mar 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
}

}

}

}