Information about runtime error: cgo argument has Go pointer to Go pointer

var out api.SQLHANDLE
ret := api.SQLAllocHandle(api.SQL_HANDLE_DBC, api.SQLHANDLE(d.h), &out)
if IsError(ret) {
return nil, NewError("SQLAllocHandle", d.h)
}
h := api.SQLHDBC(out)

In the above code i have created h varaiable using cgo. I did not use C.free to release the memory but it works fine.

How?

Thanks

Error:-

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/ibmdb/go_ibm_db/api.SQLBindCol.func1(0x8000100010001, 0xc00005c1b8, 0xc000000008, 0xc00005c198, 0x4df820)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/api/zapi_unix.go:26 +0x4c
github.com/ibmdb/go_ibm_db/api.SQLBindCol(0x8000100010001, 0xc00005c1b8, 0x8, 0xc00005c198, 0x0)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/api/zapi_unix.go:26 +0x59
github.com/ibmdb/go_ibm_db.(*BufferLen).Bind(0xc00005c198, 0x10001, 0x0, 0x440008, 0xc00005c1b8, 0x8, 0x8, 0xc00000c0a0)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/column.go:31 +0x62
github.com/ibmdb/go_ibm_db.(*BindableColumn).Bind(0xc00005c180, 0x10001, 0x0, 0xc00005c180, 0x0, 0x0)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/column.go:241 +0x6c
github.com/ibmdb/go_ibm_db.(*ODBCStmt).BindColumns(0xc000092050, 0x7c0860, 0x0)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/odbcstmt.go:148 +0x1eb
github.com/ibmdb/go_ibm_db.(*Stmt).Query(0xc000080240, 0x7c0860, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/rakhil/go/src/github.com/ibmdb/go_ibm_db/stmt.go:93 +0xe5
database/sql.ctxDriverStmtQuery(0x502580, 0xc000016138, 0x502700, 0xc000080240, 0x7c0860, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /work/rakhil/go/src/database/sql/ctxutil.go:94 +0x16b
database/sql.rowsiFromStatement(0x502580, 0xc000016138, 0x5024c0, 0xc000010290, 0xc00005c140, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /work/rakhil/go/src/database/sql/sql.go:2511 +0x159
database/sql.(*DB).queryDC(0xc000090000, 0x502580, 0xc000016138, 0x0, 0x0, 0xc00009e000, 0xc0000102a0, 0x4ec83a, 0x13, 0x0, ...)
        /work/rakhil/go/src/database/sql/sql.go:1571 +0x255
database/sql.(*DB).query(0xc000090000, 0x502580, 0xc000016138, 0x4ec83a, 0x13, 0x0, 0x0, 0x0, 0xc00001c101, 0xc0000366a0, ...)
        /work/rakhil/go/src/database/sql/sql.go:1519 +0x136
database/sql.(*DB).QueryContext(0xc000090000, 0x502580, 0xc000016138, 0x4ec83a, 0x13, 0x0, 0x0, 0x0, 0xc0000366c0, 0x18, ...)
        /work/rakhil/go/src/database/sql/sql.go:1496 +0xd3
database/sql.(*DB).Query(0xc000090000, 0x4ec83a, 0x13, 0x0, 0x0, 0x0, 0x0, 0x49bc7a, 0x7c08c0)
        /work/rakhil/go/src/database/sql/sql.go:1510 +0x82
main.main()
        /work/rakhil/go/column_names.go:18 +0x10f
exit status 2

Where i have to change the Code:- (In Bind func or in SQLBindCol func)

func (l *BufferLen) Bind(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN {
        return api.SQLBindCol(h, api.SQLUSMALLINT(idx+1), ctype,api.SQLPOINTER(unsafe.Pointer(&buf[0])), api.SQLLEN(len(buf)),(*api.SQLLEN)(l))
}


func SQLBindCol(statementHandle SQLHSTMT, columnNumber SQLUSMALLINT, targetType SQLSMALLINT, targetValuePtr SQLPOINTER, bufferLength SQLLEN, vallen *SQLLEN) (ret SQLRETURN) {
        r := C.SQLBindCol(C.SQLHSTMT(statementHandle), C.SQLUSMALLINT(columnNumber), C.SQLSMALLINT(targetType), C.SQLPOINTER(targetValuePtr), C.SQLLEN(bufferLength), (*C.SQLLEN)(vallen))
        return SQLRETURN(r)
}

Thanks.

@NobbZ can you help me on this.

Thanks.

Please stop mentioning me out of nowhere, if I were able to help, I had already tried much earlier.

Ok sorry.

Hi, @akhilravuri, I did some searching for that error message and I came across this post (and specific comment):

The way I’m skimming over this, it looks to me like it might work for you if you move the unsafe.Pointer(&buf[0]) into the cgo call (i.e. from (*BufferLen).Bind to SQLBindCol).

It’s working.
Thanks @skillian

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.