sijms / go-ora

Pure go oracle client
MIT License
786 stars 174 forks source link

different charset support? #441

Closed aca closed 11 months ago

aca commented 12 months ago
panic: the server use charset with id: 846 which is not supported by the driver

Hi, I'm having issue with godror and replace it with go-ora. cgo dependancies really annoying in our environment. But our old legacy oracle db uses different charset. Is it possible to support different charset?

sijms commented 11 months ago

there is a way to define custom encode and decode through implement IStringConveter interface and pass this value to connection after connect now I am upgrading this to be used directly with database/sql package. also i will try to add support for charset 846 to the package

sijms commented 11 months ago

v2.7.18 add support for charset ID 846 and also update code to use SetStringConverter

aca commented 10 months ago

Thanks, but still panics. Should I omit charset ID in DSN?

panic: charset KO16MSWIN949 is not supported by the driver

goroutine 1 [running]:
main.main()
        ---/ledger/example/go-ora/main.go:36 +0x23f
exit status 2

https://github.com/sijms/go-ora/blob/47c72957312fce73efac1a4cb51d322a651880b1/v2/connection_string.go#L272

sijms commented 10 months ago

yes don't use charset in dsn as you are using the same charset of the server if there is panic would you please share an example code

aca commented 9 months ago

Oh, I tried with SetStringConverter and it worked.

But I'm just not sure it is correct implementation. Can you correct me if I'm wrong?

Now I think I can replace go-ora, which I had to change encoding every message manually. Thanks!

import (
    "context"
    "database/sql"
    "encoding/base64"

    "github.com/davecgh/go-spew/spew"
    go_ora "github.com/sijms/go-ora/v2"
    "github.com/sijms/go-ora/v2/converters"
    "golang.org/x/text/encoding/korean"
)

// Server configuration
// NLS_NCHAR_CHARACTERSET ,AL16UTF16
// NLS_CHARACTERSET       ,KO16MSWIN949

type KO16MSWIN949Converter struct {}
func (KO16MSWIN949Converter) Encode(in string) []byte {
    v, err := korean.EUCKR.NewEncoder().String(in)
    if err != nil {
        panic(err)
    }
    return []byte(v)
}

func (KO16MSWIN949Converter) Clone() converters.IStringConverter {
    return KO16MSWIN949Converter{}
}

func (KO16MSWIN949Converter) GetLangID() int {
    return 846
}

func (KO16MSWIN949Converter) Decode(in []byte) string {
    v, err := korean.EUCKR.NewDecoder().Bytes(in)
    if err != nil {
        panic(err)
    }
    return string(v)
}

go_ora.SetStringConverter(db, KO16MSWIN949Converter{}, nil)
sijms commented 9 months ago

the implementation is correct also test my update if it is working or not i update connection_string.go and un-comment the line