Class: Rubyfb::ProcedureCall

Inherits:
Object
  • Object
show all
Defined in:
lib/procedure_call.rb,
lib/active_record/connection_adapters/rubyfb_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, procedure_name) ⇒ ProcedureCall

Returns a new instance of ProcedureCall.


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/procedure_call.rb', line 5

def initialize(connection, procedure_name)
  @procedure_name=procedure_name
  @connection=connection
  @param_names = []
  connection.execute_immediate(
    "SELECT RDB$PARAMETER_NAME
    FROM RDB$PROCEDURE_PARAMETERS
    WHERE RDB$PROCEDURE_NAME='#{procedure_name}' and RDB$PARAMETER_TYPE = 0
    ORDER BY RDB$PARAMETER_NUMBER"
  ) do |row|
    row.each do |col, val|
      @param_names << column_key(val)
    end
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection


3
4
5
# File 'lib/procedure_call.rb', line 3

def connection
  @connection
end

#param_namesObject (readonly)

Returns the value of attribute param_names


3
4
5
# File 'lib/procedure_call.rb', line 3

def param_names
  @param_names
end

#procedure_nameObject (readonly)

Returns the value of attribute procedure_name


3
4
5
# File 'lib/procedure_call.rb', line 3

def procedure_name
  @procedure_name
end

Instance Method Details

#execute(values = {}, transaction = nil) ⇒ Object

execute stored procedure vith parameter values bound to values passing NULL for all parameters not found in values returns output parameters as a hash - { :output_parameter_name=>value, … }


24
25
26
27
28
29
30
31
32
# File 'lib/procedure_call.rb', line 24

def execute(values={}, transaction=nil)
  result = {}
  execute_statement(values, transaction) do |row|
    row.each do |col, value|
      result[column_key(col)] = value
    end
  end
  return result
end

#quote_value(value) ⇒ Object


40
41
42
43
# File 'lib/procedure_call.rb', line 40

def quote_value(value)
  # TODO - proper quoting
  value ? "'#{value}'" : "NULL"
end

#sql_value_list(values) ⇒ Object

returns string containing coma separated parameter values corresponding to param_names array, quoted/formated in SQL format


36
37
38
# File 'lib/procedure_call.rb', line 36

def sql_value_list(values)
  param_names.collect{|p| quote_value(values[p])}.join(',')
end