Skip to content

GBK CHARSET Database char include chinese error slice bounds out of range #126

@travelliu

Description

@travelliu
  • os Version: macOS 11.2
  • cli-driver Version: 11.5
  • Db2 Server Version: v11.5.4.0
  • go Version:
go env Output:
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/travel/Library/Caches/go-build"
GOENV="/Users/travel/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/travel/Documents/Code/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/travel/Documents/Code/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/travel/Documents/Code/Enmotech/cloudAssistant/mtk/go.mod"
CGO_CFLAGS="-I/Users/travel/Oracle_tools/db2client/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/Users/travel/Oracle_tools/db2client/lib"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k1/vqmqkz_s4gg5c0775rlv4g000000gn/T/go-build488589789=/tmp/go-build -gno-record-gcc-switches -fno-common"

Steps to Reproduce:

  1. install gbk charset and create gbk database
docker run -itd --name  db2_11 --privileged=true -p 50000:50000 \
-e LICENSE=accept -e DB2INST1_PASSWORD=db2@123 \
-e SAMPLEDB=true \
-e DBNAME=testdb  \
ibmcom/db2

docker exec -it db2_11 bash
-- install gdk charset
yum install -y kde-l10n-Chinese
localedef -c -f GBK -i zh_CN zh_CN.GBK
locale -a | grep CN
--  create gbb database 
su - db2inst1
db2 create database testdb1 using codeset GBK territory cn



 db2 get db cfg for testdb1 |grep code
 Database code page                                      = 1386
 Database code set                                       = GBK
 Database country/region code                            = 86
  1. create table
create table t_char(name char(20)) ;
insert into t_char values('中国');
  1. test
		rows, err := db.Query("select name from db2inst1.t_char")
		if err != nil {
			t.Error(err)
		}
		for rows.Next() {
			var (
				a1 []byte
			)
			if err := rows.Scan(&a1); err != nil {
				t.Error(err)
				return
			}
			fmt.Printf("%s\n", a1)
		}
		if err := rows.Err(); err != nil {
			t.Error(err)
		}
  1. error
panic: runtime error: slice bounds out of range [:22] with capacity 21 [recovered]
	panic: runtime error: slice bounds out of range [:22] with capacity 21

goroutine 20 [running]:
testing.tRunner.func1.1(0x4447b80, 0xc000150ba0)
	/usr/local/Cellar/go/1.15.2/libexec/src/testing/testing.go:1076 +0x30d
testing.tRunner.func1(0xc00010ea80)
	/usr/local/Cellar/go/1.15.2/libexec/src/testing/testing.go:1079 +0x41a
panic(0x4447b80, 0xc000150ba0)
	/usr/local/Cellar/go/1.15.2/libexec/src/runtime/panic.go:969 +0x175
github.com/ibmdb/go_ibm_db.(*BindableColumn).Value(0xc00011f140, 0xc000010001, 0x0, 0xc000209db8, 0x405028c, 0x10, 0x440be00)
	/Users/travel/Documents/Code/go/pkg/mod/github.com/ibmdb/[email protected]/column.go:286 +0x2b5
github.com/ibmdb/go_ibm_db.(*Rows).Next(0xc00010a118, 0xc000101f00, 0x1, 0x1, 0x0, 0xc000184360)
	/Users/travel/Documents/Code/go/pkg/mod/github.com/ibmdb/[email protected]/rows.go:116 +0xcc

utf8 database no issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions