GithubHelp home page GithubHelp logo

Comments (6)

stfnmllr avatar stfnmllr commented on July 21, 2024

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

from go-hdb.

xhit avatar xhit commented on July 21, 2024

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")
}

from go-hdb.

xhit avatar xhit commented on July 21, 2024

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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
.....

from go-hdb.

stfnmllr avatar stfnmllr commented on July 21, 2024

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!

from go-hdb.

stfnmllr avatar stfnmllr commented on July 21, 2024

Should be fixed with v0.100.4.
Best regards

from go-hdb.

xhit avatar xhit commented on July 21, 2024

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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()

from go-hdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.