Skip to content

Commit

Permalink
In the test, decode the float64 and check the value #130
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Jul 11, 2021
1 parent 83a4740 commit 1d8ebc4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"database/sql"
"encoding/hex"
"fmt"
"github.com/shopspring/decimal"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestBasic(t *testing.T) {

for rows.Next() {
rows.Scan(&a, &b, &c, &d, &e, &f, &g, &h, &i, &j)
// fmt.Println(a, b, c, d, e, f, g, h, i, j)
// fmt.Println(a, b, c, d, e, f, g, h, i, j)
}

stmt, _ := conn.Prepare("select count(*) from foo where a=? and b=? and d=? and e=? and f=? and g=?")
Expand Down Expand Up @@ -402,20 +401,21 @@ func TestDecFloat(t *testing.T) {
return
}

sql := `
query := `
CREATE TABLE test_decfloat (
i integer,
d DECIMAL(20, 2),
df64 DECFLOAT(16),
df128 DECFLOAT(34)
df16 DECFLOAT(16),
df34 DECFLOAT(34),
s varchar(32)
)
`
conn.Exec(sql)
conn.Exec("insert into test_decfloat(i, d, df64, df128) values (1, 0.0, 0.0, 0.0)")
conn.Exec("insert into test_decfloat(i, d, df64, df128) values (2, 1.0, 1.0, 1.0)")
conn.Exec("insert into test_decfloat(i, d, df64, df128) values (3, 20.0, 20.0, 20.0)")
conn.Exec("insert into test_decfloat(i, d, df64, df128) values (4, -1.0, -1.0, -1.0)")
conn.Exec("insert into test_decfloat(i, d, df64, df128) values (5, -20.0, -20.0, -20.0)")
conn.Exec(query)
conn.Exec("insert into test_decfloat(i, d, df16, df34, s) values (1, 0.0, 0.0, 0.0, '0.0')")
conn.Exec("insert into test_decfloat(i, d, df16, df34, s) values (2, 1.1, 1.1, 1.1, '1.1')")
conn.Exec("insert into test_decfloat(i, d, df16, df34, s) values (3, 20.2, 20.2, 20.2, '20.2')")
conn.Exec("insert into test_decfloat(i, d, df16, df34, s) values (4, -1.1, -1.1, -1.1, '-1.1')")
conn.Exec("insert into test_decfloat(i, d, df16, df34, s) values (5, -20.2, -20.2, -20.2, '-20.2')")

var n int
err = conn.QueryRow("select count(*) cnt from test_decfloat").Scan(&n)
Expand All @@ -426,11 +426,19 @@ func TestDecFloat(t *testing.T) {
t.Fatalf("Error bad record count: %v", n)
}

rows, err := conn.Query("select d, df64, df128 from test_decfloat order by i")
rows, err := conn.Query("select df16, df34, s from test_decfloat order by i")

var d, df64, df128 decimal.Decimal
var df16, df34 sql.NullFloat64
var s string
for rows.Next() {
rows.Scan(&d, &df64, &df128)
rows.Scan(&df16, &df34, &s)
f, _ := strconv.ParseFloat(s, 64)
df16v, _ := df16.Value()
df34v, _ := df34.Value()

if df16v != f || df34v != f {
fmt.Printf("Error decfloat value : %v,%v,%v\n", df16v, df34v, f)
}
}

conn.Close()
Expand Down

0 comments on commit 1d8ebc4

Please sign in to comment.