Small. Fast. Reliable.
Choose any three.

About Sitemap Documentation Download License News Developers Support

## SQLite C Interface

## Obtain Aggregate Function Context

>     void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);

The implementation of aggregate SQL functions use this routine to allocate a structure for storing their state.

The first time the sqlite3_aggregate_context() routine is called for a particular aggregate, SQLite allocates nBytes of memory, zeroes out that memory, and returns a pointer to it. On second and subsequent calls to sqlite3_aggregate_context() for the same aggregate function index, the same buffer is returned. The implementation of the aggregate can use the returned buffer to accumulate data.

SQLite automatically frees the allocated buffer when the aggregate query concludes.

The first parameter should be a copy of the SQL function context that is the first parameter to the callback routine that implements the aggregate function.

This routine must be called from the same thread in which the aggregate SQL function is running.

### Invariants:

H16211 | The first invocation of sqlite3_aggregate_context(C,N) for a particular instance of an aggregate function (for a particular context C) causes SQLite to allocate N bytes of memory, zero that memory, and return a pointer to the allocated memory.
H16213 | If a memory allocation error occurs during sqlite3_aggregate_context(C,N) then the function returns 0.
H16215 | Second and subsequent invocations of sqlite3_aggregate_context(C,N) for the same context pointer C ignore the N parameter and return a pointer to the same block of memory returned by the first invocation.
H16217 | The memory allocated by sqlite3_aggregate_context(C,N) is automatically freed on the next call to sqlite3_reset() or sqlite3_finalize() for the prepared statement containing the aggregate function associated with context C.

See also lists of Objects, Constants, and Functions.

This page last modified 2008/08/11 17:57:43 UTC