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

lobexample_test.go fails if column is data type TEXT and BINTEXT for insert #41

Closed
xhit opened this issue Feb 11, 2020 · 6 comments
Closed
Labels

Comments

@xhit
Copy link

xhit commented Feb 11, 2020

A column with data type TEXT or BINTEXT is returned like a NCLOB with this query:

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

So, for insert, I treated this like a Lob with lobexample_test.go and this error is returned:

sql: converting argument $1 type: convert named value datatype error: 0 - DtUnknown

While debugging I found that the function DataType() in typecode.go returns DtUnknown because the TypeCode is 32 corresponding to tcNlocator

I did changes to treat this TypeCode like a Lob but this error was returned from hxe:

SQL Error 1033 - error while parsing protocol: no such data type: type_code=32, index=1

@stfnmllr
Copy link
Contributor

Please provide the complete example, especially how the table is created and queried - thanks!

@xhit
Copy link
Author

xhit commented Apr 27, 2020

Sure! This is a test code:

package main

import (
	"bytes"
	"database/sql"
	"fmt"
	"log"
	"net/url"
	"strings"

	"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.Fatal(err)
	}

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

	defer db.Close()

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

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

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

	// select column types
	rows, err := db.Query(`select * from issue41`)

	// the types are BLOB and NCLOB, supported like specified in lobexample_test.go
	types, _ := rows.ColumnTypes()
	for _, v := range types {
		log.Printf("%s", v.DatabaseTypeName())
	}

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

	// for BLOB column
	// stmt, err := tx.Prepare("insert into issue41 (a) values (?)")

	// for TEXT column (this is causing error)
	stmt, err := tx.Prepare("insert into issue41 (b) values (?)")
	if err != nil {
		log.Print(err)
		return
	}

	defer stmt.Close()

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

	// insert the lob, here is returning the error for TEXT and BINTEXT column. Both returned with type NCLOB
	_, err = stmt.Exec(lob)
	if err != nil {
		log.Print(err)
		return
	}

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

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

@xhit
Copy link
Author

xhit commented May 5, 2020

Update with result driver v0.99.1

Whit this driver version, TEXT is returned with datatype TEXT and BINTEXT like NCLOB
The same code but different error output:

Inserting in a TEXT column: SQL Error 1033 - error while parsing protocol: no such data type: type_code=51, index=22

inserting in BINTEXT column:

panic: Missing FieldType for typeCode tcBlocator

goroutine 5 [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.99.1/internal/protocol/typecode.go:217
github.com/SAP/go-hdb/internal/protocol.(*parameterField).Converter(0xc0000044c0, 0xcfbb00, 0xc00004ce10)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.99.1/internal/protocol/parameter.go:102 +0x142
github.com/SAP/go-hdb/driver.convertNamedValue(0xc00002c080, 0xc000017848, 0x0, 0x0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.99.1/driver/convert.go:34 +0x7f
github.com/SAP/go-hdb/driver.(*stmt).CheckNamedValue(0xc0000580a0, 0xc000017848, 0x0, 0x0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.99.1/driver/connection.go:531 +0x83
database/sql.driverArgsConnLocked(0xf24560, 0xc00004cd10, 0xc00002c0c0, 0xc000434000, 0x16, 0x16, 0xc0006860b0, 0x0, 0x0, 0xc0000ee0f0, ...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/convert.go:177 +0x19b
database/sql.resultFromStatement(0xf26fe0, 0xc0000a0110, 0xf24560, 0xc00004cd10, 0xc00002c0c0, 0xc000434000, 0x16, 0x16, 0x0, 0x0, ...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2430 +0xe6
database/sql.(*Stmt).ExecContext(0xc0000ee090, 0xf26fe0, 0xc0000a0110, 0xc000434000, 0x16, 0x16, 0x0, 0x0, 0x0, 0x0)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2411 +0x20a
database/sql.(*Stmt).Exec(...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2423
.....

@stfnmllr
Copy link
Contributor

stfnmllr commented May 5, 2020

yes - the bug is not fixed yet - looks like an issue in the protocol layer - need to do some more testing to isolate the issue.
Thanks for re-testing!

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

Should be fixed with v0.100.4.
Best regards

@xhit
Copy link
Author

xhit commented May 14, 2020

Testing with v0.100.5, the same code above works when column b is TEXT, but panic when is BINTEXT

panic: Missing FieldType for typeCode tcLocator

goroutine 1 [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.(*parameterField).Converter(0xc000004fc0, 0xc00007daa0, 0x40997c)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/internal/protocol/parameter.go:102 +0x142
github.com/SAP/go-hdb/driver.convertNamedValue(0xc00001e440, 0xc00006d320, 0xb85308, 0x38)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/driver/convert.go:34 +0x7f
github.com/SAP/go-hdb/driver.(*stmt).CheckNamedValue(0xc00004a550, 0xc00006d320, 0x1c0101, 0x0)
        C:/Users/sdelacruz/Documents/go/pkg/mod/github.com/!s!a!p/go-hdb@v0.100.5/driver/connection.go:531 +0x83
database/sql.driverArgsConnLocked(0x70a320, 0xc00003ea80, 0xc00001e480, 0xc00007de98, 0x1, 0x1, 0xc00003eb80, 0x0, 0x0, 0xc0001080f0, ...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/convert.go:177 +0x19b
database/sql.resultFromStatement(0x70b3e0, 0xc000012018, 0x70a320, 0xc00003ea80, 0xc00001e480, 0xc00007de98, 0x1, 0x1, 0x0, 0x0, ...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2430 +0xe6
database/sql.(*Stmt).ExecContext(0xc000108090, 0x70b3e0, 0xc000012018, 0xc00007de98, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2411 +0x20a
database/sql.(*Stmt).Exec(...)
        C:/Users/sdelacruz/sdk/go1.14.2/src/database/sql/sql.go:2423
main.issue41()

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