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

Select a BINTEXT column with rows panic #50

Closed
xhit opened this issue May 14, 2020 · 8 comments
Closed

Select a BINTEXT column with rows panic #50

xhit opened this issue May 14, 2020 · 8 comments
Labels

Comments

@xhit
Copy link

xhit commented May 14, 2020

Using v0.100.5

Querying a column type BINTEXT panic the app.

Connect to db and query rows:

rows, err := db.Query(`select bintext_column from tbl`)

Error:

panic: Missing FieldType for typeCode tcBintext

goroutine 11 [running]:
github.com/SAP/go-hdb/internal/protocol.typeCode.fieldType(...)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/typecode.go:214
github.com/SAP/go-hdb/internal/protocol.decodeRes(0xc00010e240, 0x35, 0x1, 0xc00003e980, 0x200, 0x8)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/fieldtype.go:174 +0x241
github.com/SAP/go-hdb/internal/protocol.(*resultset).decode(0xc00006cf60, 0xc00010e240, 0xc000012360, 0x4, 0xc000131dd0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/result.go:198 +0xf6
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).readPart(0xc00005ad20, 0x6fd300, 0xc00006cf60, 0xc0000481e0, 0xc00010e260)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/protocol.go:452 +0x6b
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).read(0xc00005ad20, 0x6fd300, 0xc00006cf60, 0x0, 0xc000131        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/protocol.go:368 +0x4e
github.com/SAP/go-hdb/internal/protocol.(*Session).QueryDirect.func1(0xc000012360)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/session.go:381 
+0x93
github.com/SAP/go-hdb/internal/protocol.(*protocolReader).iterateParts(0xc00005ad20, 0xc000131f10, 0x102, 0xc000131f00)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/protocol.go:518 +0x178
github.com/SAP/go-hdb/internal/protocol.(*Session).QueryDirect(0xc000048240, 0x6ab356, 0x15, 0x0, 0x0, 0x0, 0x0)   
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/session.go:372 
+0x216
github.com/SAP/go-hdb/driver.(*conn).QueryContext.func1(0xc00003e8d0, 0x6ab356, 0x15, 0xc00003e950, 0xc00003e960, 0x6fe000, 0xc000012018, 0xc00001c360)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/driver/connection.go:267 +0x4d   
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.100.5/driver/connection.go:266 +0x5e

A complete reproducible program is not possible because the driver cannot insert a value in BINTEXT column yet, see #41 (comment)

@stfnmllr stfnmllr added the bug label May 14, 2020
@stfnmllr
Copy link
Contributor

Did make it work (v0.100.6), so that the example you shared is giving results. Anyway, need to provide some tests to be sure that the Bintext support is completely implemented.
Please share your findings in further tests as well. I'll leave the ticket open for the time being.
Thanks and best regards

@xhit
Copy link
Author

xhit commented May 14, 2020

Tested v0.100.6

Inserting values when there are at least 2 lob columns insert (BLOB, TEXT, BINTEXT) and one is BINTEXT then this error is returned:

protocol error: invalid number of lob parameter ids 1 - expected 2

Example code:

package main

import (
	"bytes"
	"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 issue50`)

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

	// create the table
	_, err = db.Exec(`create table issue50 (a BLOB, b BINTEXT)`)
	if err != nil {
		log.Print(err)
		return
	}

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

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

	// begin transaction
	tx, err := db.Begin()

	stmt, err := tx.Prepare("insert into issue50 (a,b) values (?,?)")
	if err != nil {
		log.Print(err)
		return
	}

	defer stmt.Close()

	// create a lob reader for BLOB
	lobBLOB := new(driver.Lob)
	r := bytes.NewReader([]byte("0123456789"))
	lobBLOB.SetReader(r)

	// create a lob reader for BINTEXT
	lobBINTEXT := new(driver.Lob)
	r1 := bytes.NewReader([]byte("0123456789"))
	lobBINTEXT.SetReader(r1)

	_, err = stmt.Exec(lobBLOB, lobBINTEXT)
	if err != nil {
		log.Print(err)
		return
	}

	// commit transaction
	err = tx.Commit()
	if err != nil {
		log.Print(err)
		return
	}

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

This should be another issue because this was completed, but I think you said this issue will be open while BINTEXT is in alpha.

@stfnmllr
Copy link
Contributor

stfnmllr commented May 14, 2020

Thanks for testing!

This should be another issue because this was completed, but I think you said this issue will be
open while BINTEXT is in alpha.

Yes, that's fine - let's use this ticket until all issues with BINTEXT are ironed out.
Best regards

@stfnmllr
Copy link
Contributor

The example should work with v0.100.7 although full test of BINTEXT is not yet finalized.

@xhit
Copy link
Author

xhit commented May 15, 2020

Works.

For now the v0.100.7 works like expected in my tests. I will test all other new releases to check until BINTEXT is completed.

Thanks.

@stfnmllr
Copy link
Contributor

Thanks for your testing effort and confirming on the bug resolution.

@xhit
Copy link
Author

xhit commented Jun 26, 2020

Tested v0.100.10. Works.

@xhit
Copy link
Author

xhit commented Nov 2, 2020

Tested v0.102.2. Works.

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