Class: SQLite3::Database::FunctionProxy
- Inherits:
-
Object
- Object
- SQLite3::Database::FunctionProxy
- Defined in:
- lib/sqlite3/database.rb
Overview
A helper class for dealing with custom functions (see #create_function, #create_aggregate, and #create_aggregate_handler). It encapsulates the opaque function object that represents the current invocation. It also provides more convenient access to the API functions that operate on the function object.
This class will almost always be instantiated indirectly, by working with the create methods mentioned above.
Instance Attribute Summary collapse
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value with the given key from the context.
-
#[]=(key, value) ⇒ Object
Sets the value with the given key in the context.
-
#count ⇒ Object
(Only available to aggregate functions.) Returns the number of rows that the aggregate has processed so far.
-
#initialize ⇒ FunctionProxy
constructor
Create a new FunctionProxy that encapsulates the given
func
object. -
#set_error(error) ⇒ Object
Set the result of the function to the given error message.
Constructor Details
#initialize ⇒ FunctionProxy
Create a new FunctionProxy that encapsulates the given func
object. If context is non-nil, the functions context will be set to that. If it is non-nil, it must quack like a Hash. If it is nil, then none of the context functions will be available.
561 562 563 564 |
# File 'lib/sqlite3/database.rb', line 561 def initialize @result = nil @context = {} end |
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
555 556 557 |
# File 'lib/sqlite3/database.rb', line 555 def result @result end |
Instance Method Details
#[](key) ⇒ Object
Returns the value with the given key from the context. This is only available to aggregate functions.
581 582 583 |
# File 'lib/sqlite3/database.rb', line 581 def []( key ) @context[ key ] end |
#[]=(key, value) ⇒ Object
Sets the value with the given key in the context. This is only available to aggregate functions.
587 588 589 |
# File 'lib/sqlite3/database.rb', line 587 def []=( key, value ) @context[ key ] = value end |
#count ⇒ Object
(Only available to aggregate functions.) Returns the number of rows that the aggregate has processed so far. This will include the current row, and so will always return at least 1.
575 576 577 |
# File 'lib/sqlite3/database.rb', line 575 def count @driver.aggregate_count( @func ) end |
#set_error(error) ⇒ Object
Set the result of the function to the given error message. The function will then return that error.
568 569 570 |
# File 'lib/sqlite3/database.rb', line 568 def set_error( error ) @driver.result_error( @func, error.to_s, -1 ) end |