Method: SQLite::API.aggregate_context

Defined in:
ext/sqlite-api.c

.aggregate_context(func) ⇒ Hash

Returns the aggregate context for the given function. This context is a Hash object that is allocated on demand and is available only to the current invocation of the function. It may be used by aggregate functions to accumulate data over multiple rows, prior to being finalized.

The func parameter must be an opaque function handle as given to the callbacks for #create_aggregate.

See #create_aggregate and #aggregate_count.

Returns:

  • (Hash)


840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'ext/sqlite-api.c', line 840

static VALUE
static_api_aggregate_context( VALUE module, VALUE func )
{
  sqlite_func *func_ptr;
  VALUE *ptr;

  GetFunc( func_ptr, func );

  /* FIXME: pointers to VALUEs...how nice is the GC about this kind of
   * thing? Especially when someone else frees the memory? */

  ptr = (VALUE*)sqlite_aggregate_context( func_ptr, sizeof(VALUE) );

  if( *ptr == 0 )
    *ptr = rb_hash_new();

  return *ptr;
}