Module: Sequel::Dataset::StoredProcedureMethods

Included in:
JDBC::Dataset::StoredProcedureMethods, MySQL::Dataset::StoredProcedureMethods
Defined in:
lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb

Constant Summary

SQL_QUERY_TYPE =
Hash.new{|h,k| h[k] = k}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sproc_args=(value) ⇒ Object (writeonly)

The name of the stored procedure to call



11
12
13
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 11

def sproc_args=(value)
  @sproc_args = value
end

#sproc_nameObject

The name of the stored procedure to call



8
9
10
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 8

def sproc_name
  @sproc_name
end

Instance Method Details

#call(*args, &block) ⇒ Object

Call the stored procedure with the given args



14
15
16
17
18
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 14

def call(*args, &block)
  sp = clone
  sp.sproc_args = args
  sp.run(&block)
end

#inspectObject

Programmer friendly string showing this is a stored procedure, showing the name of the procedure.



22
23
24
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 22

def inspect
  "<#{self.class.name}/StoredProcedure name=#{@sproc_name}>"
end

#run(&block) ⇒ Object

Run the stored procedure with the current args on the database



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 27

def run(&block)
  case @sproc_type
  when :select, :all
    all(&block)
  when :first
    first
  when :insert
    insert
  when :update
    update
  when :delete
    delete
  end
end

#sproc_type=(type) ⇒ Object

Set the type of the stored procedure and override the corresponding _sql method to return the empty string (since the result will be ignored anyway).



45
46
47
48
# File 'lib/sequel/lib/sequel/adapters/utils/stored_procedures.rb', line 45

def sproc_type=(type)
  @sproc_type = type
  meta_def("#{sql_query_type}_sql"){|*a| ''}
end