Class: JDBCHelper::FunctionWrapper
- Inherits:
-
ObjectWrapper
- Object
- ObjectWrapper
- JDBCHelper::FunctionWrapper
- Defined in:
- lib/jdbc-helper/wrapper/function_wrapper.rb
Overview
conn.function(:coalesce).call(nil, nil, ‘king’)
Instance Attribute Summary
Attributes inherited from ObjectWrapper
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Returns the result of the function call with the given parameters.
-
#initialize(conn, name) ⇒ FunctionWrapper
constructor
A new instance of FunctionWrapper.
Constructor Details
#initialize(conn, name) ⇒ FunctionWrapper
Returns a new instance of FunctionWrapper.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jdbc-helper/wrapper/function_wrapper.rb', line 14 def initialize conn, name super conn, name @suffix = case conn.driver when /oracle/ " from dual" else "" end end |
Instance Method Details
#call(*args) ⇒ Object
Returns the result of the function call with the given parameters
27 28 29 30 31 32 33 34 |
# File 'lib/jdbc-helper/wrapper/function_wrapper.rb', line 27 def call(*args) pstmt = @connection.prepare("select #{name}(#{args.map{'?'}.join ','})#{@suffix}") begin pstmt.query(*args).to_a[0][0] ensure pstmt.close end end |