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

(ravuri sai ram akhil) #1
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 to release the memory but it works fine.



(ravuri sai ram akhil) #2


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

goroutine 1 [running]:, 0xc00005c1b8, 0xc000000008, 0xc00005c198, 0x4df820)
        /home/rakhil/go/src/ +0x4c, 0xc00005c1b8, 0x8, 0xc00005c198, 0x0)
        /home/rakhil/go/src/ +0x59*BufferLen).Bind(0xc00005c198, 0x10001, 0x0, 0x440008, 0xc00005c1b8, 0x8, 0x8, 0xc00000c0a0)
        /home/rakhil/go/src/ +0x62*BindableColumn).Bind(0xc00005c180, 0x10001, 0x0, 0xc00005c180, 0x0, 0x0)
        /home/rakhil/go/src/ +0x6c*ODBCStmt).BindColumns(0xc000092050, 0x7c0860, 0x0)
        /home/rakhil/go/src/ +0x1eb*Stmt).Query(0xc000080240, 0x7c0860, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/rakhil/go/src/ +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
        /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)


(ravuri sai ram akhil) #3

@NobbZ can you help me on this.


(Norbert Melzer) #4

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

(ravuri sai ram akhil) #5

Ok sorry.

(Sean Killian) #6

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).

(ravuri sai ram akhil) #7

It’s working.
Thanks @skillian