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

db.Query with NULL *LOB fields hangs #18

Closed
tc-turner opened this issue Jan 24, 2018 · 6 comments
Closed

db.Query with NULL *LOB fields hangs #18

tc-turner opened this issue Jan 24, 2018 · 6 comments
Labels

Comments

@tc-turner
Copy link

In our HANA2 database we have a Column table with several NCLOB fields, some of them allow NULL data and when running a query with go-hdb Query("SELECT POTENTIALLY_NULL FROM A_TABLE") the program hangs for close to 5 minutes before erroring out with the following

i/o timeout
2018/01/24 16:18:13 SQL HdbError 259 - invalid table name:  Could not find table/view A_TABLE in schema SYSTEM: line 1 col 36 (at pos 35)

I am explicitly setting the SCHEMA to the correct value and the included code works fine if the field I select is NOT NULL.

The JDBC driver handles this with no issues.

I have ran WireShark and it seems that using the go-hdb driver the packets just stop flowing.

package main

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

	_ "github.com/SAP/go-hdb/driver"
)

func getDbURL(host string, port int, username string, password string) string {

	dsn := &url.URL{
		Scheme: "hdb",
		User:   url.UserPassword(username, password),
		Host:   fmt.Sprintf("%s:%d", host, port),
	}
	return dsn.String()
}

func main() {
	db, err := sql.Open("hdb", getDbURL("my.hana.host", 30015, "SYSTEM", "SouperSecretPassword"))
	if err != nil {
		log.Fatal(err)
	}
	if err := db.Ping(); err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	_, err = db.Exec("SET SCHEMA MY_NOT_SYSTEM_SCHEMA")
	if err != nil {
		log.Fatal(err)
	}
	_, err = db.Query("SELECT POTENTIALLY_NULL FROM A_TABLE")
	if err != nil {
		log.Fatal(err)
	}
}

Go Version: go version go1.9.3 darwin/amd64
go-hdb Version: const DriverVersion = "0.9.5"

Thanks for writing the go-hdb library!!

@stfnmllr
Copy link
Contributor

stfnmllr commented Jan 26, 2018

Ok - as the error clearly states, that the table cannot be found in schema SYSTEM:

  • each db. takes a (most probably different) connection out of the connection pool
    --> db.Exec("SET SCHEMA....") is most probably executed not in the same connection as the following db.Query(...)
  • to guarantee the same connection, please use whether schema.tableName syntax in the query, a transaction or (golang > 1.9) a sql.Conn object

Please share the results after the change - thanks!

...Thanks for writing the go-hdb library!!
my pleasure

@stfnmllr
Copy link
Contributor

stfnmllr commented Feb 4, 2018

Didn't hear back, so closing the issue

@stfnmllr stfnmllr closed this as completed Feb 4, 2018
@petar-iv
Copy link

I also observe that the process hangs when trying to fetch a LOB with a value of NULL (with current state of master branch, go version: 1.10.1, HANA 2 SPS 2). Here is a scenario to reproduce:

create schema test;

create table test.table_1 (col clob not null);
insert into test.table_1 values('some-text');

create table test.table_2 (col clob);
insert into test.table_2 values(null);
package main

import (
	"bytes"
	"database/sql"
	"fmt"

	"github.com/SAP/go-hdb/driver"
)

func main() {
	db, err := sql.Open("hdb", "hdb://<user>:<password>@<host>:<port>")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	fetchLob(db, "non-null", "table_1")
	fetchLob(db, "null", "table_2")
}

func fetchLob(db *sql.DB, scenario string, tableName string) {
	fmt.Printf("Fetching %s LOB value ...\n", scenario)
	lob := new(driver.Lob)
	b := new(bytes.Buffer)
	lob.SetWriter(b)
	if err := db.QueryRow(fmt.Sprintf("select col from test.%s", tableName)).Scan(lob); err != nil {
		panic(err)
	}
	fmt.Printf("Fetched value: %v\n\n\n", b)
}

The output is:

Fetching non-null LOB value ...
Fetched value: some-text


Fetching null LOB value ...

There is no value from the second fetch because the process hangs.

Let me know if there is anything wrong in my coding or this is an issue in the library.

Many thanks

@stfnmllr
Copy link
Contributor

thanks a lot for providing the example - the code looks good, so most probably we are going to provide a fix asap

@stfnmllr stfnmllr reopened this Apr 18, 2018
@stfnmllr stfnmllr added bug and removed question labels Apr 22, 2018
@stfnmllr
Copy link
Contributor

should work with the newest release (v0.11.1) - please see new NullLob for scanning Lob null values

@petar-iv
Copy link

Works as expected now, thanks a lot

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

3 participants