-
Notifications
You must be signed in to change notification settings - Fork 38
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 index out of range inserting empty []byte in BLOB column #73
Comments
Hi @xhit |
A BLOB column can accept NULL but with this driver trigger an error but that is another issue. See #80. This issue is about insert an empty To reproduce: package main
import (
"database/sql"
"fmt"
_ "github.com/ibmdb/go_ibm_db"
)
func main() {
//connecto to DB
db, err := connectDB2("localhost", "SAMPLE", "SCHEMATEST", "db2admin", "pass", 50000)
if err != nil {
panic(err)
}
defer db.Close()
queryDrop := `drop table "issue73";`
db.Exec(queryDrop)
queryCreate := `CREATE TABLE "issue73" ("blob_column" BLOB(50));`
_, err = db.Exec(queryCreate)
if err != nil {
panic(err)
}
defer db.Exec(queryDrop)
queryInsert := `insert into "issue73" ("blob_column") values (?);`
//inserting a empty []byte panic with error panic: runtime error: index out of range [0] with length 0
_, err = db.Exec(queryInsert, []byte{})
if err != nil {
panic(err)
}
}
//connect to db2 database
func connectDB2(host, database, schema, user, password string, port int) (*sql.DB, error) {
//Password cannot contains ;
connString := fmt.Sprintf("HOSTNAME=%s;DATABASE=%s;PORT=%d;UID=%s;PWD=%s", host, database, port, user, password)
db, err := sql.Open("go_ibm_db", connString)
if err != nil {
return nil, err
}
err = db.Ping()
if err != nil {
return nil, err
}
db.SetMaxOpenConns(1)
db.SetMaxIdleConns(1)
//set the schema
if len(schema) > 0 {
_, err = db.Exec("SET CURRENT SCHEMA ?", schema)
if err != nil {
return nil, err
}
}
return db, nil
} |
Hi @akhilravuri1, can you check this panic? Thanks. |
Hi @xhit Thanks, |
go env
Output:The driver cannot insert nil in a column with data type BLOB, launch this error from IBM:
SQLExecute: {HY099} [IBM][CLI Driver] CLI0164E Nullable type out of range. SQLSTATE=HY099
So trying to insert a empty []byte in a data type BLOB return this panic:
The text was updated successfully, but these errors were encountered: