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.
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.
[ show source ]
# File lib/sqlite3/database.rb, line 642
642: def initialize( driver, func, context=nil )
643: @driver = driver
644: @func = func
645: @context = context
646: end
Returns the value with the given key from the context. This is only available to aggregate functions.
[ show source ]
# File lib/sqlite3/database.rb, line 675
675: def []( key )
676: ensure_aggregate!
677: @context[ key ]
678: end
Sets the value with the given key in the context. This is only available to aggregate functions.
[ show source ]
# File lib/sqlite3/database.rb, line 682
682: def []=( key, value )
683: ensure_aggregate!
684: @context[ key ] = value
685: end
(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.
[ show source ]
# File lib/sqlite3/database.rb, line 668
668: def count
669: ensure_aggregate!
670: @driver.aggregate_count( @func )
671: end
Calls set_result to set the result of this function.
[ show source ]
# File lib/sqlite3/database.rb, line 649
649: def result=( result )
650: set_result( result )
651: end
Set the result of the function to the given error message. The function will then return that error.
[ show source ]
# File lib/sqlite3/database.rb, line 661
661: def set_error( error )
662: @driver.result_error( @func, error.to_s, -1 )
663: end
Set the result of the function to the given value. The function will then return this value.
[ show source ]
# File lib/sqlite3/database.rb, line 655
655: def set_result( result, utf16=false )
656: @driver.result_text( @func, result, utf16 )
657: end