8000 GBK CHARSET Database char include chinese error slice bounds out of range · Issue #126 · ibmdb/go_ibm_db · GitHub
[go: up one dir, main page]

Skip to content

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

Closed

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/go_ibm_db@v0.4.0/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/go_ibm_db@v0.4.0/rows.go:116 +0xcc

utf8 database no issue

Activity

  1. akhilravuri1 commented on Mar 23, 2021

    @akhilravuri1
    Contributor

    Hi @travelliu

    You are able to insert data into the database but while retrieving the data you are facing this issue right?

    Thanks,
    Akhil

  2. travelliu commented on Mar 23, 2021

    @travelliu
    Author

    Hi @travelliu

    You are able to insert data into the database but while retrieving the data you are facing this issue right?

    Thanks,
    Akhil

    YES.

    func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) {
    	if !c.IsBound {
    		ret := c.Len.GetData(h, idx, c.CType, c.Buffer)
    		if IsError(ret) {
    			return nil, NewError("SQLGetData", h)
    		}
    	}
    	if c.Len.IsNull() {
    		// is NULL
    		return nil, nil
    	}
    	if !c.IsVariableWidth && int(c.Len) != c.Size {
    		panic(fmt.Errorf("wrong column #%d length %d returned, %d expected", idx, c.Len, c.Size))
    	}
    	return c.BaseColumn.Value(c.Buffer[:c.Len])  -->  slice bounds out of range
    }
    

    i will modify code

    func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error) {
    	if !c.IsBound {
    		ret := c.Len.GetData(h, idx, c.CType, c.Buffer)
    		if IsError(ret) {
    			return nil, NewError("SQLGetData", h)
    		}
    	}
    	if c.Len.IsNull() {
    		// is NULL
    		return nil, nil
    	}
    	if !c.IsVariableWidth && int(c.Len) != c.Size {
    		panic(fmt.Errorf("wrong column #%d length %d returned, %d expected", idx, c.Len, c.Size))
    	}
            // check buffer len
    	bufferLen := int(c.Len)
    	if len(c.Buffer) < bufferLen {
    		bufferLen = len(c.Buffer)
    	}
    
    	return c.BaseColumn.Value(c.Buffer[:bufferLen])
    }
    
  3. akhilravuri1 commented on Mar 23, 2021

    @akhilravuri1
    Contributor

    Can you declare variable a1 as string and try?

    Thanks,
    Akhil

  4. travelliu commented on Mar 23, 2021

    @travelliu
    Author

    Can you declare variable a1 as string and try?

    Thanks,
    Akhil

    bytes and string some issue. panic: runtime error: slice bounds out of range.

  5. akhilravuri1 commented on Mar 25, 2021

    @akhilravuri1
    Contributor

    Hi @travelliu

    I will run some test cases and I will make the changes. Thanks for the input.

    -Akhil

  6. added a commit that references this issue on May 28, 2021
  7. akhilravuri1 commented on May 28, 2021

    @akhilravuri1
    Contributor

    Hi @travelliu

    Sorry for the late response.
    I have pushed your changes.

    Thanks for the contribution.

    -Akhil

  8. travelliu commented on Jun 16, 2021

    @travelliu
    Author

    Hi @travelliu

    Sorry for the late response.
    I have pushed your changes.

    Thanks for the contribution.

    -Akhil

    Publish a new version?v0.4.1 not include this

  9. added a commit that references this issue on Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      0