Go MySql - out parameter

2,237 views
Skip to first unread message

Kiril Skliar

unread,
May 7, 2014, 9:29:48 AM5/7/14
to golan...@googlegroups.com
Hi guys, 
Does anyone know how to execute mysql stored procedure with output parameters?



email:= v.Get("email")
pss:= v.Get("pss")

var userId string
var errorCode int

// Execute the query
rows, err := db.Query("CALL User_Register(?,?,?,?)", email,pss,errorCode, userId)
if err != nil {
     panic(err.Error())
}

I do know how to pass regular params and how to get the  field's value from select in one row\rows


in my case, errorCode and userId will be output.


thanks in advance

Arne Hormann

unread,
May 7, 2014, 10:02:21 AM5/7/14
to golan...@googlegroups.com
Stored procedures are unsupported in github.com/go-sql-driver/mysql.

The reasoning: database/sql does not support retrieving multiple result sets, it would need a connection.NextResult().
The driver tries to follow database/sql as close as possible and does not support multiple results either.
Stored procedures might return multiple results, so support for them must be signalled with a flag on connection.
The driver doesn't do that because it could not support it in all cases.

Ergo, no stored procedures.

Daniel Theophanes

unread,
May 7, 2014, 2:08:14 PM5/7/14
to golan...@googlegroups.com
I am creating a more powerful database interface that supports output parameters. 

I am creating it tandem with a ms sql driver, and will start on a postgresql driver next. The api is still changing though and doesn't have a mysql driver yet.

Kiril Skliar

unread,
May 7, 2014, 3:33:31 PM5/7/14
to Daniel Theophanes, golan...@googlegroups.com
I need a package for mysql that supports:
1. Stored procedure
2.  Output parameter

Do you know?

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/5AJyGW9d9Wg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dharampalsi...@gmail.com

unread,
Apr 4, 2017, 8:27:41 AM4/4/17
to golang-nuts
Hi Kiril,

Were you able to get this working , I am also struggling to get the Output parameters working with mssql driver .




Thanks,
Dharam

Daniel Theophanes

unread,
Apr 4, 2017, 10:07:46 AM4/4/17
to dharampalsi...@gmail.com, golang-nuts
mssql driver ( https://github.com/denisenkom/go-mssqldb ) doesn't yet support output variables, though I have support planned for go1.9. You can use rdb (I currently use it in a line of business application), but I would recommend you use https://github.com/denisenkom/go-mssqldb if possible (select your output vars in SQL text if that is an option) as that will supersede rdb/ms and database/sql will supersede rdb.

--
Reply all
Reply to author
Forward
0 new messages