### Home Classes Methods

### In Files

- lib/amalgalite/function.rb

### Parent

Object

### Methods

- ::new
- #signature
- #to_proc

### Files

- HISTORY.rdoc
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Amalgalite
- Amalgalite::Aggregate
- Amalgalite::Blob
- Amalgalite::Blob::Error
- Amalgalite::Boolean
- Amalgalite::BusyHandler
- Amalgalite::BusyTimeout
- Amalgalite::CSVTableImporter
- Amalgalite::Column
- Amalgalite::Database
- Amalgalite::Database::AggregateError
- Amalgalite::Database::BusyHandlerError
- Amalgalite::Database::FunctionError
- Amalgalite::Database::InvalidModeError
- Amalgalite::Database::ProgressHandlerError
- Amalgalite::Database::TransactionBehavior
- Amalgalite::Error
- Amalgalite::Function
- Amalgalite::Index
- Amalgalite::MemoryDatabase
- Amalgalite::Packer
- Amalgalite::Paths
- Amalgalite::ProfileSampler
- Amalgalite::ProfileTap
- Amalgalite::ProgressHandler
- Amalgalite::Requires
- Amalgalite::SQLite3
- Amalgalite::SQLite3::Constants
- Amalgalite::SQLite3::Constants::Config
- Amalgalite::SQLite3::Constants::DBStatus
- Amalgalite::SQLite3::Constants::DataType
- Amalgalite::SQLite3::Constants::Helpers
- Amalgalite::SQLite3::Constants::Open
- Amalgalite::SQLite3::Constants::ResultCode
- Amalgalite::SQLite3::Constants::StatementStatus
- Amalgalite::SQLite3::Constants::Status
- Amalgalite::SQLite3::Database
- Amalgalite::SQLite3::Database::DBStatus
- Amalgalite::SQLite3::Database::Function
- Amalgalite::SQLite3::Database::Stat
- Amalgalite::SQLite3::Stat
- Amalgalite::SQLite3::Status
- Amalgalite::SQLite3::Version
- Amalgalite::Schema
- Amalgalite::Statement
- Amalgalite::Table
- Amalgalite::Taps
- Amalgalite::Taps::IO
- Amalgalite::Taps::Stderr
- Amalgalite::Taps::Stdout
- Amalgalite::Taps::StringIO
- Amalgalite::TraceTap
- Amalgalite::TypeMap
- Amalgalite::TypeMaps
- Amalgalite::TypeMaps::DefaultMap
- Amalgalite::TypeMaps::StorageMap
- Amalgalite::TypeMaps::TextMap
- Amalgalite::Version
- Amalgalite::View
- Kernel
- Object

No matching classes.

# Amalgalite::Function

A Base class to inherit from for creating your own SQL scalar functions in ruby.

These are SQL functions similar to _abs(X)_, _length(X)_, _random()_. Items that take parameters and return value. They have no state between calls. Built in SQLite scalar functions are :

- www.sqlite.org/lang_corefunc.html

- www.sqlite.org/lang_datefunc.html

Functions defined in Amalgalite databases conform to the Proc interface. Everything that is defined in an Amalgalite database using `define_function` has its `to_proc` method called. As a result, any Function must also conform to the `to_proc` protocol.

If you choose to use Function as a parent class of your SQL scalar function implementation you should only have implement `call` with the appropriate arity.

For instance to implement a _sha1(X)_ SQL function you could implement it as

    class SQLSha1 < ::Amalgalite::Function
      def initialize
        super( 'md5', 1 )
      end
      def call( s )
        ::Digest::MD5.hexdigest( s.to_s )
      end
    end

### Attributes

arity[RW]

The arity of the SQL function

name[RW]

The name of the SQL function

### Public Class Methods

new( name, arity ) click to toggle source

Initialize the function with a name and arity

    # File lib/amalgalite/function.rb, line 42
    def initialize( name, arity )
      @name = name
      @arity = arity
    end

### Public Instance Methods

signature() click to toggle source

Do Not Override

The function signature for use by the Amaglaite datase in tracking function definition and removal.

    # File lib/amalgalite/function.rb, line 57
    def signature
      @signature ||= ::Amalgalite::SQLite3::Database::Function.signature( self.name, self.arity )
    end

to_proc() click to toggle source

All SQL functions defined foloow the `to_proc` protocol

    # File lib/amalgalite/function.rb, line 48
    def to_proc
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.