mattn / go-oci8

Oracle driver for Go using database/sql
https://mattn.kaoriya.net/
MIT License
630 stars 212 forks source link

Float part lost #267

Closed 242617 closed 6 years ago

242617 commented 6 years ago

I've losing float part in sum(). Example:

package main

import (
    "database/sql"
    "fmt"

    _ "github.com/mattn/go-oci8" //oci8
    _ "gopkg.in/goracle.v2"      //goracle
    _ "gopkg.in/rana/ora.v4"     //ora
)

const query = `
    SELECT SUM(BALANCE)
    FROM ( SELECT 123.123 BALANCE FROM DUAL )
`

func main() {
    fmt.Printf("%s: %f\n", "oci8", db("oci8"))
    fmt.Printf("%s: %f\n", "goracle", db("goracle"))
    fmt.Printf("%s: %f\n", "ora", db("ora"))
}

func db(framework string) (number float64) {
    db, err := sql.Open(framework, "...")
    die(err)
    err = db.QueryRow(query).Scan(&number)
    die(err)
    return
}

func die(err error) {
    if err != nil {
        panic(err)
    }
}

The result is

oci8: 123.000000
goracle: 123.123000
ora: 123.123000

Oracle Database 11g Enterprise Edition 11.2.0.4.0 - 64bit Production.

MichaelS11 commented 6 years ago

This is an issue with number scale (type) for numbers. Have PR https://github.com/mattn/go-oci8/pull/268 open for it. Will see what @mattn thinks.

MichaelS11 commented 6 years ago

@242617 Please test

242617 commented 6 years ago

Works perfect. Thank you!

mattn commented 6 years ago

Thanks.