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

Panic when select a column DECIMAL 18,2 #64

Closed
xhit opened this issue Oct 30, 2020 · 3 comments
Closed

Panic when select a column DECIMAL 18,2 #64

xhit opened this issue Oct 30, 2020 · 3 comments
Labels

Comments

@xhit
Copy link

xhit commented Oct 30, 2020

Using v0.100.14, I do a select with all datatypes supported for SAP HANA DB to support them in Dixer.

Currently, upgrading to version v0.102.1 of this driver, I receive a panic when I select when a column is DECIMAL.

I'm using version 2.00.040.00.1553674765 in testing environment.

I confirm this panic is triggered in versions v0.101.2+

panic: Missing FieldType for typeCode tcFixed8

goroutine 24 [running]:
github.com/SAP/go-hdb/internal/protocol.typeCode.fieldType(0x51, 0x200, 0xc00036fd00)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/typecode.go:232 +0x478
github.com/SAP/go-hdb/internal/protocol.decodeRes(0xc00041cfc0, 0x51, 0x20, 0xc000514000, 0x200, 0x8)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/fieldtype.go:140 +0x35
github.com/SAP/go-hdb/internal/protocol.(*resultset).decode(0xc0000702d0, 0xc00041cfc0, 0xc0003b0cf0, 0xc00036fe00, 0x60446e)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/result.go:182 +0xe5
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).readPart(0xc000338280, 0xe36240, 0xc0000702d0, 0xc000506360, 0xc00041cfe0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/protocol.go:569 +0x68
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).read(0xc000338280, 0xe36240, 0xc0000702d0, 0x0, 0xc00036fe78)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/protocol.go:485 +0x4e
github.com/SAP/go-hdb/internal/protocol.(*Session).QueryDirect.func1(0xc0003b0cf0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/session.go:180 +0x92
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).iterateParts(0xc000338280, 0xc00036ff28, 0x102, 0xc00036ff18)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/protocol.go:635 +0x17f
github.com/SAP/go-hdb/internal/protocol.(*Session).QueryDirect(0xc000070030, 0xc000325520, 0x1b, 0xd8f701, 0x1373c20, 0x0, 0x0, 0xc0000886b8)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/internal/protocol/session.go:171 +0x1c6
github.com/SAP/go-hdb/driver.(*Conn).QueryContext.func2(0xc00005e190, 0xc000325520, 0x1b, 0xc000088730, 0xc000088750, 0xc00045e180)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/driver/connection.go:503 +0x59
created by github.com/SAP/go-hdb/driver.(*Conn).QueryContext
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.102.1/driver/connection.go:502 +0x5c5
@stfnmllr
Copy link
Contributor

Please provide the example code selecting the DECIMAL, especially the Go variable definition for the Scan.

@xhit
Copy link
Author

xhit commented Oct 30, 2020

especially the Go variable definition for the Scan

The code panic before that.

A repro code:

package main

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

	_ "github.com/SAP/go-hdb/driver"
)

func main() {
	// create dsn
	dsn := fmt.Sprintf("hdb://%s:%s@%s:%d", "username", "password", "host", 39013)

	// open db
	db, err := sql.Open("hdb", dsn)
	if err != nil {
		log.Print(err)
		return
	}

	err = db.Ping()
	if err != nil {
		log.Print(err)
		return
	}

	defer db.Close()

	// drop table if exists
	db.Exec(`drop table issue64`)

	// drop table at end for cleaning
	defer db.Exec(`drop table issue64`)

	// create the table
	_, err = db.Exec(`create table issue64 (a DECIMAL(18,2))`)
	if err != nil {
		log.Print(err)
		return
	}

	// select column types
	rows, err := db.Query(`select a from issue64`)
	if err != nil {
		log.Print(err)
		return
	}

	types, err := rows.ColumnTypes()
	if err != nil {
		panic(err)
	}
	for _, v := range types {
		log.Printf("%s", v.DatabaseTypeName())
	}

	// print success
	log.Print("success")
}

@stfnmllr stfnmllr added the bug label Oct 30, 2020
@stfnmllr
Copy link
Contributor

Great - thanks a lot for the example!
The issue should be fixed with https://github.com/SAP/go-hdb/releases/tag/v0.102.2.

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