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 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(driver, func, context = nil) ⇒ FunctionProxy
constructor
Create a new FunctionProxy that encapsulates the given
funcobject. -
#result=(result) ⇒ Object
Calls #set_result to set the result of this function.
-
#set_error(error) ⇒ Object
Set the result of the function to the given error message.
-
#set_result(result, utf16 = false) ⇒ Object
Set the result of the function to the given value.
Constructor Details
#initialize(driver, func, context = nil) ⇒ 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.
647 648 649 650 651 |
# File 'lib/sqlite3/database.rb', line 647 def initialize( driver, func, context=nil ) @driver = driver @func = func @context = context end |
Instance Method Details
#[](key) ⇒ Object
Returns the value with the given key from the context. This is only available to aggregate functions.
680 681 682 683 |
# File 'lib/sqlite3/database.rb', line 680 def []( key ) ensure_aggregate! @context[ key ] end |
#[]=(key, value) ⇒ Object
Sets the value with the given key in the context. This is only available to aggregate functions.
687 688 689 690 |
# File 'lib/sqlite3/database.rb', line 687 def []=( key, value ) ensure_aggregate! @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.
673 674 675 676 |
# File 'lib/sqlite3/database.rb', line 673 def count ensure_aggregate! @driver.aggregate_count( @func ) end |
#result=(result) ⇒ Object
Calls #set_result to set the result of this function.
654 655 656 |
# File 'lib/sqlite3/database.rb', line 654 def result=( result ) set_result( result ) end |
#set_error(error) ⇒ Object
Set the result of the function to the given error message. The function will then return that error.
666 667 668 |
# File 'lib/sqlite3/database.rb', line 666 def set_error( error ) @driver.result_error( @func, error.to_s, -1 ) end |
#set_result(result, utf16 = false) ⇒ Object
Set the result of the function to the given value. The function will then return this value.
660 661 662 |
# File 'lib/sqlite3/database.rb', line 660 def set_result( result, utf16=false ) @driver.result_text( @func, result, utf16 ) end |