Class: SQLite::Database::FunctionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlite/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

Constructor Details

#initialize(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.



628
629
630
631
# File 'lib/sqlite/database.rb', line 628

def initialize( func, context=nil )
  @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.



655
656
657
658
# File 'lib/sqlite/database.rb', line 655

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.



662
663
664
665
# File 'lib/sqlite/database.rb', line 662

def []=( key, value )
  ensure_aggregate!
  @context[ key ] = value
end

#countObject

(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.



648
649
650
651
# File 'lib/sqlite/database.rb', line 648

def count
  ensure_aggregate!
  SQLite::API.aggregate_count( @func )
end

#set_error(error) ⇒ Object

Set the result of the function to the given error message, which must be a string. The function will then return that error.



641
642
643
# File 'lib/sqlite/database.rb', line 641

def set_error( error )
  SQLite::API.set_result_error( @func, error )
end

#set_result(result) ⇒ Object

Set the result of the function to the given value. The function will then return this value.



635
636
637
# File 'lib/sqlite/database.rb', line 635

def set_result( result )
  SQLite::API.set_result( @func, result )
end