the stored procedure looks like:
create procedure `manager`(in amount decimal(9,2), in list text, in acc_id int(11), out return_code int(1)) begin declare exit handler sqlexception, sqlwarning begin set return_code = 1; rollback; end; set transaction isolation level serializable; --my code set return_code = 0; end
the method rails model is:
return_code = -1 return_code = self.connection.execute("call manager(#{amount}, '#{list}', #{acc_id}, #{return_code})")
but throws error:
activerecord::statementinvalid: mysql2::error: out or inout argument 4 routine staging.manager not variable or new pseudo-variable in before trigger: call manager(2222, 'list', 2, -1)
need on how pass out parameter while calling stored procedure rails.
the solution below worked me:
i changed #{return_code) @return_code (no need pass return_code = -1 input, out parameter):
return_code = self.connection.execute("call manager(#{amount}, '#{list}', #{acc_id}, @return_code)")
in stored procedure, replaced return_code @return_code , added select statement in end:
create procedure `manager`(in amount decimal(9,2), in list text, in acc_id int(11), out return_code int(1)) begin declare exit handler sqlexception, sqlwarning begin set return_code = 1; rollback; end; set transaction isolation level serializable; --my code set return_code = 0; select @return_code; end