Cgo argument has Go pointer to Go pointer

Hi,
MY CODE IS:

package main

import (
    _ "github.com/ibmdb/go_ibm_db"
        "fmt"
        "database/sql"
        "math/rand"
        )

func main(){
con:="HOSTNAME=10.45.6.33;PORT=50000;DATABASE=go;UID=*****;PWD=********"
db,err:=sql.Open("go_ibm_db",con)
if err != nil{
fmt.Println(err)

}
defer db.Close()
db.Exec("DROP table byt1")
_,err=db.Query("create table byt1(name INT)")
if err != nil{
    fmt.Println(err)
}

st1,err:=db.Prepare("select name from byt1 ORDER BY name DESC")
if err != nil{
fmt.Println(err)
}

st2,err:=db.Prepare("Insert into byt1(name) values(?)")
if err != nil{
fmt.Println(err)
}

for n := 1; n <= 3; n++ {
    if _, err := st2.Exec(n); err != nil {
        fmt.Println("insert(%d) = %v", n, err)
        }
    }

const nRuns = 10
ch := make(chan bool)
        for i := 0; i < nRuns; i++ {
                go func() {
                        defer func() {
                                ch <- true
                        }()
                        for j := 0; j < 10; j++ {
                                count := 0
                                if err := st1.QueryRow().Scan(&count); err != nil && err != sql.ErrNoRows {
                                        fmt.Println("Query: %v", err)
                                        return
                                }
                                if _, err := st2.Exec(rand.Intn(100)); err != nil {
                                       fmt.Println("Insert: %v", err)
                                        return
                                }
                        }
                }()
        }
        for i := 0; i < nRuns; i++ {
                <-ch
        }

}

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

goroutine 16 [running]:
github.com/ibmdb/go_ibm_db/api.SQLBindCol.func1(0x4000100010001, 0xc00005a3f8, 0xc000000004, 0xc00005a3d8, 0x4edfe0)
/home/rakhil/go/src/github.com/ibmdb/go_ibm_db/api/zapi_unix.go:26 +0x4c
github.com/ibmdb/go_ibm_db/api.SQLBindCol(0x4000100010001, 0xc00005a3f8, 0x4, 0xc00005a3d8, 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(0xc00005a3d8, 0x10001, 0x0, 0x440004, 0xc00005a3f8, 0x4, 0x8, 0xc000010350)
/home/rakhil/go/src/github.com/ibmdb/go_ibm_db/column.go:29 +0x62
github.com/ibmdb/go_ibm_db.(*BindableColumn).Bind(0xc00005a3c0, 0x10001, 0x0, 0xc00005a3c0, 0x0, 0x0)
/home/rakhil/go/src/github.com/ibmdb/go_ibm_db/column.go:202 +0x6c
github.com/ibmdb/go_ibm_db.(*ODBCStmt).BindColumns(0xc000092140, 0x7d9de0, 0x0)
/home/rakhil/go/src/github.com/ibmdb/go_ibm_db/odbcstmt.go:148 +0x1eb
github.com/ibmdb/go_ibm_db.(*Stmt).Query(0xc00007e2d0, 0x7d9de0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/rakhil/go/src/github.com/ibmdb/go_ibm_db/stmt.go:93 +0xe5
database/sql.ctxDriverStmtQuery(0x513040, 0xc000016138, 0x513140, 0xc00007e2d0, 0x7d9de0, 0x0, 0x0, 0x0, 0x0, 0x0, …)
/work/rakhil/go/src/database/sql/ctxutil.go:94 +0x16b
database/sql.rowsiFromStatement(0x513040, 0xc000016138, 0x512f40, 0xc000010290, 0xc00005a240, 0x0, 0x0, 0x0, 0x0, 0x0, …)
/work/rakhil/go/src/database/sql/sql.go:2511 +0x159
database/sql.(*Stmt).QueryContext(0xc0000a6000, 0x513040, 0xc000016138, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/work/rakhil/go/src/database/sql/sql.go:2463 +0x203
database/sql.(*Stmt).QueryRowContext(0xc0000a6000, 0x513040, 0xc000016138, 0x0, 0x0, 0x0, 0xc000016218)
/work/rakhil/go/src/database/sql/sql.go:2521 +0x6d
database/sql.(*Stmt).QueryRow(0xc0000a6000, 0x0, 0x0, 0x0, 0x0)
/work/rakhil/go/src/database/sql/sql.go:2540 +0x61
main.main.func1(0xc00001c2a0, 0xc0000a6000, 0xc0000a6090)
/home/rakhil/go/src/github.com/bradfitz/go-sql-test/src/sqltest/akh.go:49 +0xb4
created by main.main
/home/rakhil/go/src/github.com/bradfitz/go-sql-test/src/sqltest/akh.go:43 +0x472
exit status 2
THANKS IN ADVANCE.

Please don’t open more than one topic for the same issue. Also, remember to format your code properly to help with legibility. Refer to this post, or this one for more info.

I changed it and i will delete the other one. Can you explain me why this error occurs

Is this a valid statement in this database’s sql? In mysql would it have been

select count(*) from byt1 ORDER BY count DESC

to count the number of rows in the table and also it will just result in one value so it isn’t really needed.to sort it.

the select statement has been stated wrong.

select name from byt1 ORDER BY name DESC

It is working for windows when it comes to linux it is producing the error.

I came to know that the error is because of releasing the channel in the main routine before all child go routines are completed. I don’t know whether it is correct or wrong . If this is the error how to solve it.

Look up waitgroups. This is an easy way to wait for multiple go routines to finish. Something like this:

https://golang.org/src/sync/example_test.go

Either you know the number of go routines in forehand (n) and then you could call wg.Add(n) or otherwise does each go routine a wg.Add(1). Each go routine then wd.Done() then finsished. And the main routine uses wg.Wait() for all routines to finish.

when i do
export GODEBUG=cgocheck=0
it is working fine in linux . Is it ok to do like this or i have to do some thing.

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