SAP / go-ase

SAP ASE Database Client for Go
Apache License 2.0
25 stars 14 forks source link

Pure go driver ? #44

Closed jaijiv closed 3 years ago

jaijiv commented 4 years ago

Any updates on when pure go driver will be available ?

jaijiv commented 4 years ago

any updates? we are very keen about using a pure go driver. Pl. let us know. We are a big sybase client

cb80 commented 4 years ago

Thanks for your interest in go-ase! The pure go part is in development such that we are able to establish connections. However things like encryption or type handling are not yet finished and we don't know how long it will take to complete this. So I can't tell a specific end date - my personal goal is to have it done mid of 2020. Implementing TDS takes time and we want to get things right. So I have to ask for your patience.

jaijiv commented 4 years ago

Thanks for your reply. It will be great to have this soon. We have used unixodbc / freetds till now but really want to avoid any cgo dependency. We are trying out a pure go driver https://github.com/thda/tds but ofcourse want one endorsed by SAP

jaijiv commented 4 years ago

hi cris @cb80 - i now see a purego version. Any timeline for prod release of this ? We are very keen to use this as we are a big sybase ase shop and devs are demanding to use go. We would rather not use cgo

cb80 commented 4 years ago

In the last months we worked hard on the pure go version based on the TDS protocol. But there is no timeline as we primarily concentrate on delivering correct and running software. There will be a split of the cgo and purego driver in separate repositories soon:

You can already start to use the pure go driver and we are happy about any feedback but with the above split import paths will change.

jaijiv commented 3 years ago

Hi - i started testing the purego driver. See this one issue (exact code worked with https://github.com/thda/tds which is also a pure go driver). Any help greatly appreciated

go-ase: error preparing dynamic SQL: go-ase: error allocating dynamic statement 'select Position_Id, Account_Id, Symbol, Exchg_Code, Security_Type, Long_Or_Short_Cd, Curr_Qty, Prev_Close_Price, BO_Account_Type from ETS_AccountDB..AC_Net_Position where Account_Id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)': error queueing dynamic prepare package: context canceled"

Code is this :

    SQL := "select Position_Id, Account_Id, Symbol, Exchg_Code, Security_Type, " +
        "Long_Or_Short_Cd, Curr_Qty, Prev_Close_Price, BO_Account_Type from ETS_AccountDB..AC_Net_Position where Account_Id in (?)"
    query, args, err := sqlx.In(SQL, req.AccountID)
    if err != nil {
        return nil, errors.Wrap(err, "GetNetPositionsForAcctList - sqlx.In()")
    }

    resp := &GetNetPositionsForAcctListResp{}
    query = s.acctdb.Rebind(query)
    var rows *sqlx.Rows
    rows, err = s.acctdb.QueryxContext(ctx, query, args...)
    if err != nil {
        if err == sql.ErrNoRows {
            return resp, nil
        }
        return nil, errors.Wrap(err, "GetNetPositionsForAcctList - db.Queryx()")
    }
ntnn commented 3 years ago

The context was closed - this could be one of two reasons:

  1. The context you provided was closed
  2. The connection context was closed because the server closed the connection

We'll add something to discern which context exactly was closed. Also - closing a connection will return an error in such cases that will contain all leftover packages and errors, which helps to find errors in cases like this:

if err != nil {
    if err := c.Close(); err != nil {
         return nil, fmt.Errorf("error closing connection after error: %w", err)
    }
}

Please also test the two following scenarios:

  1. Using go-ase directly with a simple query, e.g. select "ping"
  2. Using sqlx with go-ase with the same query
jaijiv commented 3 years ago

Added close on error and got this

store.GetNetPositionsForAcctList(): GetNetPositionsForAcctList - error closing connection after error: go-ase: error closing TDS connection: 1 error occurred:\n\t error closing channel: 4 errors occurred:\n\t error in logout sequence: error sending logout package: context canceled\n\t package still queued: tds.ParamsPackage(1): \n\t package still queued: tds.DonePackage(TDS_DONE_COUNT, TDS_TRAN_COMPLETED, Count=1)\n\t* package still queued: tds.DonePackage(TDS_DONE_FINAL, TDS_NOT_IN_TRAN, Count=0)\n\n\n\n

jaijiv commented 3 years ago

Nelo - as to other 2 scenarios - they do work - it is only this IN clause query where we are experiencing this issue

Thanks -jaijiv

ntnn commented 3 years ago

@jaijiv I've made a PR that adds context showing which context was closed and added an example using sqlx.In.

That example works for me - please post which version of ASE you're using and run the example at examples/purego/sqlx_In from my PR.

jaijiv commented 3 years ago

@ntnn - The sybase version is : Adaptive Server Enterprise/16.0 SP03 PL09/EBF 29247 SMP/P/x86_64/SLES11.1/ase160sp03pl09x/3839/64-bit/FBO/Thu Jul 9 10:21:51 2020 sp03

sendPackets function in channel.go returns this error

store.GetNetPositionsForAcctList(): GetNetPositionsForAcctList - db.Queryx(): go-ase: error preparing dynamic SQL: go-ase: error allocating dynamic statement 'select Position_Id, Account_Id, Symbol, Exchg_Code, Security_Type, Long_Or_Short_Cd, Curr_Qty, Prev_Close_Price, BO_Account_Type from ETS_AccountDB..AC_Net_Position where Account_Id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)': error queueing dynamic prepare package: sendPackets - connection context is closed: context canceled

Thanks for your quick response

ntnn commented 3 years ago

That is very odd.

The problem isn't with the statement itself as the connection context is already closed before the driver tries to queue the first package. This happens in purego/dynamic.g:40, where it tries to queue the package signaling the server that a dynamic SQL stream starts. Additionally I remembered wrong and the connection context is only closed in tds.Conn.Close().

I'm guessing that the issue originates from an earlier statement - could you post the entire function where the error occurs? You can also send it to my SAP email address at nelo-thara.wallus@sap.com.

ntnn commented 3 years ago

I'll be closing this issue due to being stale and the pure go driver being implemented. If any issues come up please open a new ticket.