Return of mysql procedure using golang

Viewed 2360

I'm having a problem getting the return of a procedure using golang. If I remove the parameters from the procedure the procedure is executed normally, however, when I need to get the return (OUT parameter) I can not get it and the procedure is not executed. To make the tests simpler and to get help, I created a simple procedure as below and I want to get the return of it.

Follow procedure below:


drop procedure if exists PESSOA_TESTE;

delimiter $$


create procedure PESSOA_TESTE(out psaida int)

begin

set psaida = 2;

end

$$

Now it follows the section of golang code that I'm using to try to get the value 2 specified in the procedure.

var GerenciaBD GERENCIABD
var PontoExecucao int

GerenciaBD.F_GERENCIABD_ABRIR_CONEXAO_MYSQL()

GerenciaBD.DataBase.ExecContext(context.TODO(),"call PESSOA_TESTE", sql.Named("psaida", sql.Out{Dest:&PontoExecucao}))

println(PontoExecucao)

When executing I have as answer 0 and not 2, which is the one specified in the procedure.

My golang version is at 1.10.

1 Answers

You can see here that usage of out parameter is not yet implemented for https://github.com/go-sql-driver/mysql library.

I'm not sure what you want to do with your code, but if you want to return only one value, you can do something like this:

Stored procedure:

drop procedure if exists PESSOA_TESTE;

delimiter $$


create procedure PESSOA_TESTE(IN psaida int)

begin
SET psaida = 2;
select psaida;

end

$$

Code:

   var GerenciaBD GERENCIABD
    var PontoExecucao int

    GerenciaBD.F_GERENCIABD_ABRIR_CONEXAO_MYSQL()

    GerenciaBD.DataBase.QueryRowContext(context.TODO(),"CALL PESSOA_TESTE(?)", PontoExecucao).Scan(&PontoExecucao)

    println(PontoExecucao)
Related