-
Notifications
You must be signed in to change notification settings - Fork 57
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
Comments
Please provide the complete example, especially how the table is created and queried - thanks! |
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")
} |
Update with result driver v0.99.1 Whit this driver version, TEXT is returned with datatype Inserting in a TEXT column: inserting in BINTEXT column:
|
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. |
Should be fixed with v0.100.4. |
Testing with v0.100.5, the same code above works when column
|
A column with data type
TEXT
orBINTEXT
is returned like aNCLOB
with this query: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()
intypecode.go
returnsDtUnknown
because theTypeCode
is 32 corresponding totcNlocator
I did changes to treat this
TypeCode
like aLob
but this error was returned from hxe:SQL Error 1033 - error while parsing protocol: no such data type: type_code=32, index=1
The text was updated successfully, but these errors were encountered: