Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different charset support? #441

Closed
aca opened this issue Sep 13, 2023 · 6 comments
Closed

different charset support? #441

aca opened this issue Sep 13, 2023 · 6 comments
Labels

Comments

@aca
Copy link

aca commented Sep 13, 2023

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
Copy link
Owner

sijms commented Sep 18, 2023

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
Copy link
Owner

sijms commented Sep 19, 2023

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

@sijms sijms added the fixed label Sep 19, 2023
@sijms sijms closed this as completed Sep 20, 2023
@aca
Copy link
Author

aca commented Oct 24, 2023

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

//"KO16MSWIN949" : 846,

@sijms
Copy link
Owner

sijms commented Nov 11, 2023

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
Copy link
Author

aca commented Nov 22, 2023

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
Copy link
Owner

sijms commented Nov 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants