Skip to content

Commit

Permalink
apd: fix TestSQL
Browse files Browse the repository at this point in the history
Pass `Decimal` by value to `DB.Exec`.

Also use new build tag directive format.
  • Loading branch information
nvanbenschoten committed Sep 9, 2022
1 parent 06ef971 commit 5a335e3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// implied. See the License for the specific language governing
// permissions and limitations under the License.

//go:build sql
// +build sql

package apd
Expand All @@ -34,8 +35,8 @@ func TestSQL(t *testing.T) {
if err != nil {
t.Fatal(err)
}
a, _, err := NewFromString("1234.567e5")
if err != nil {
var a Decimal
if _, _, err = a.SetString("1234.567e5"); err != nil {
t.Fatal(err)
}
if _, err := db.Exec("drop table if exists d"); err != nil {
Expand All @@ -52,14 +53,14 @@ func TestSQL(t *testing.T) {
}
var b, c, d Decimal
var nd NullDecimal
if err := db.QueryRow("select v, v::text, v::int, v::float, v from d").Scan(a, &b, &c, &d, &nd); err != nil {
if err := db.QueryRow("select v, v::text, v::int, v::float, v from d").Scan(&a, &b, &c, &d, &nd); err != nil {
t.Fatal(err)
}
want, _, err := NewFromString("123556700")
if err != nil {
t.Fatal(err)
}
for i, v := range []*Decimal{a, &b, &c, &d, &nd.Decimal} {
for i, v := range []*Decimal{&a, &b, &c, &d, &nd.Decimal} {
if v.Cmp(want) != 0 {
t.Fatalf("%d: unexpected: %s, want: %s", i, v.String(), want.String())
}
Expand Down

0 comments on commit 5a335e3

Please sign in to comment.