sijms / go-ora

Pure go oracle client
MIT License
771 stars 169 forks source link

Wrong values with characterset KO16MSWIN949 #486

Closed nenadnoveljic closed 7 months ago

nenadnoveljic commented 7 months ago
package main

import (
    "database/sql"
    "fmt"
    "log"

    go_ora "github.com/sijms/go-ora/v2"
)

const HOST = "..."
const PORT = 1521
const SERVICE_NAME = "dbkor1"
const USER = "..."
const PASSWORD = "..."

func main() {
    databaseUrl := go_ora.BuildUrl(HOST, PORT, SERVICE_NAME, USER, PASSWORD, map[string]string{})
    db, err := sql.Open("oracle", databaseUrl)

    if err != nil {
        log.Fatalf("failed to connect %s", err)
    }

    q := "SELECT 'AAA' FROM dual"

    var value string
    row := db.QueryRow(q)
    err = row.Scan(&value)
    if err != nil {
        log.Fatalf("failed to query v$instance: %s", err)
    }
    fmt.Printf("fetched value: %s\n", value)

}

Output: fetched value: ??? instead of fetched value: AAA

sijms commented 7 months ago

OK i fix it but i need some example string to test also

nenadnoveljic commented 7 months ago

Thanks. What do you mean by example string? The test case select AAA.

aca commented 7 months ago

Glad to find someone using same characterset #441. Can I ask you how you are using it for now?

I'm currently using godror, but I'm not sure I'm using it correctly (https://github.com/godror/godror/issues/313)

Thinking of migrating to go-ora but not sure.

nenadnoveljic commented 7 months ago

Can i ask you how you are using it for now?

godror works correctly. Would like to go back to go-ora if it gets fixed.

aca commented 7 months ago

Do you set charset in DSN? godror maintainer says that I should not use it. But It doesn't work. The only way I could make it work was set charset in DSN, encode string to euckr manually.

nenadnoveljic commented 7 months ago

Do you set charset in DSN?

I'm not setting charset in DSN. This thread isn't the best place for discussing godror.

aca commented 7 months ago

I'm sorry. But thanks for the response.

sijms commented 7 months ago

fixed v2.8.1

aca commented 7 months ago

Is it fixed? WIthout setstringconverter, code above stills output "???"

Tested with 2.8.4 and oracle db

docker run -d -p 1521:1521 -e ORACLE_PASSWORD=toor acadx0/oracle-xe:18.4.0-faststart-KO16MSWIN949

https://github.com/aca/oci-oracle-xe

sijms commented 7 months ago

you can use this for testing:

package main

import (
    "fmt"
    "github.com/sijms/go-ora/v2/converters"
)

func print(conv converters.IStringConverter, value string) {
    encoded := conv.Encode(value)
    fmt.Println(encoded)
    decoded := conv.Decode(encoded)
    fmt.Println(decoded)
}
func main() {
    fmt.Println("Use charset id: 846")
    conv := converters.NewStringConverter(846)
    print(conv, "안녕하세요")
    print(conv, "AAA")

    fmt.Println("")
    fmt.Println("Use charset id: 833")
    conv = converters.NewStringConverter(833)
    print(conv, "お会計お願いしますABCD")

    fmt.Println("")
    fmt.Println("Use charset id: 834")
    conv = converters.NewStringConverter(834)
    print(conv, "お会計お願いしますABCD")

    fmt.Println("")
    fmt.Println("Use charset id: 838")
    conv = converters.NewStringConverter(838)
    print(conv, "お会計お願いしますABCD")

    fmt.Println("")
    fmt.Println("Use charset id: 852")
    conv = converters.NewStringConverter(852)
    print(conv, "这是我年轻时候住的房子")
}
sijms commented 6 months ago

I use your docker image + code above result:

fetched value: AAA