Question

I'm using the ODBC driver from The Brainman. I'm using the generic ODBC syntax, which is to use "CALL" to invoke a Stored Procedure. Here is my code:

stmt, stmtErr := db.Prepare("CALL RecordClick (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
if stmtErr != nil {
    fmt.Printf("\nstmtErr: %s", stmtErr)
}
defer stmt.Close()

var aclickid int
stmtRows, stmtRowsErr := stmt.Query(xaid, subtag, r.Referer, requestUserAgent, requestIP, ip, ua, title, description, displayurl, clickUrl, kw, rpc, exid)
if stmtRowsErr != nil {
    fmt.Printf("\nstmtRowsErr: %s", stmtRowsErr)
}
for stmtRows.Next() {
    stmtRows.Scan(&aclickid)
}

When I run this, I get the following error:

stmtRowsErr: sql: converting Exec argument #2's type: unsupported type func() string, a func

I really don't understand what I'm doing wrong here. I've tried it with and without curly braces around the CALL XXX (?, ?, ?) part, and it still won't work. Any ideas?

Thanks.

Was it helpful?

Solution

My guess is that r.Referer (Type func) in stmt.Query should be r.Referer() (Returns type string, From net/http).

So the line should read:

stmtRows, stmtRowsErr := stmt.Query(xaid, subtag, r.Referer(), requestUserAgent, requestIP, ip, ua, title, description, displayurl, clickUrl, kw, rpc, exid)

That error is coming from Line #37 of convert.go in the database/sql package.

It's telling you that the type conversion for argument #2 (zero indexed) of the SQL query couldn't be converted into the type expected by the SQL engine (In particular the function driver.DefaultParameterConverter.ConvertValue(arg) failed.)

Check the types for each variable in your query with something like:

fmt.Printf("%T %T %T %T %T %T %T %T %T %T %T %T %T %T", xaid, subtag, r.Referer, requestUserAgent, requestIP, ip, ua, title, description, displayurl, clickUrl, kw, rpc, exid)

and see if any of them are unexpected or incorrect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top