Feature Requests: Browse | Submit New | Admin

[#3947] Add support for out parameters

Date:
2006-03-28 16:07
Priority:
3
Submitted By:
Daniel Berger (djberg96)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Add support for out parameters

Detailed description
There is currently no support for out parameters.  Instead, users are forced to call driver specific functions.

I propose that DBI add something like Perl's bind_param_inout.  This would mean an addition to the spec.

If we simulate the Perl API, it would look something like this:

procedure double_it(v_in in number, v_out out number) is
begin
   v_out := v_in * 2;
end;

x = 0
sth = dbh.prepare("begin double_it(?,?); end;")
sth.bind_param(1, 7)
sth.bind_param_inout(2, x)
sth.execute

p x # 14

If folks have better ideas for how the API should be designed, I'm all ears.

Regards,

Dan

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-09-08 18:45
Sender: Venkat Pa

I was thinking if an argument (direction) can be added to the
StatementHandle#bind_param method:

@@param_in = 0, @@param_out = 1, @@param_result = 2

...

def bind_param(param, value, attribs=nil, direction=@@param_in)

The same goes for execute and other methods.

Date: 2006-04-01 07:06
Sender: Kubo Takehiro

How sth.execute changes the x value? If x is an instantiated
object, it can by replacing the object's internal value.
But Fixnum is not.

There are at least two ways:

1. get the value by its position.
  sth = dbh.prepare("begin double_it(?, ?); end;")
  sth.bind_param(1, 7)
  sth.bind_param(2, 0)
  sth.execute
  sth.bound_value(2) # 14

2. sth.execute calls the bound object's setter method.
  class BoundValue
    def initialize(value)
      @value = value
    end
    def set(value)
      @value = value
    end
    def get
      @value
    end
  end

  x = BoundValue.new(0)
  sth = dbh.prepare("begin double_it(?, ?); end;")
  sth.bind_param(1, 7)
  sth.bind_param_inout(2, x)
  sth.execute
  x.get # 14

The former is oci8's way. The latter ruby9i.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item