Small. Fast. Reliable.
Choose any three.

About Sitemap Documentation Download License News Developers Support

## SQLite C Interface

## Function Auxiliary Data

>     void *sqlite3_get_auxdata(sqlite3_context*, int N);
>     void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));

The following two functions may be used by scalar SQL functions to associate meta-data with argument values. If the same value is passed to multiple invocations of the same SQL function during query execution, under some circumstances the associated meta-data may be preserved. This may be used, for example, to add a regular-expression matching scalar function. The compiled version of the regular expression is stored as meta-data associated with the SQL value passed as the regular expression pattern. The compiled regular expression can be reused on multiple invocations of the same function so that the original pattern string does not need to be recompiled on each invocation.

The sqlite3_get_auxdata() interface returns a pointer to the meta-data associated by the sqlite3_set_auxdata() function with the Nth argument value to the application-defined function. If no meta-data has been ever been set for the Nth argument of the function, or if the cooresponding function parameter has changed since the meta-data was set, then sqlite3_get_auxdata() returns a NULL pointer.

The sqlite3_set_auxdata() interface saves the meta-data pointed to by its 3rd parameter as the meta-data for the N-th argument of the application-defined function. Subsequent calls to sqlite3_get_auxdata() might return this data, if it has not been destroyed. If it is not NULL, SQLite will invoke the destructor function given by the 4th parameter to sqlite3_set_auxdata() on the meta-data when the corresponding function parameter changes or when the SQL statement completes, whichever comes first.

SQLite is free to call the destructor and drop meta-data on any parameter of any function at any time. The only guarantee is that the destructor will be called before the metadata is dropped.

In practice, meta-data is preserved between function calls for expressions that are constant at compile time. This includes literal values and SQL variables.

These routines must be called from the same thread in which the SQL function is running.

### Invariants:

F16272 | The sqlite3_get_auxdata(C,N) interface returns a pointer to metadata associated with the Nth parameter of the SQL function whose context is C, or NULL if there is no metadata associated with that parameter.
F16274 | The sqlite3_set_auxdata(C,N,P,D) interface assigns a metadata pointer P to the Nth parameter of the SQL function with context C.
F16276 | SQLite will invoke the destructor D with a single argument which is the metadata pointer P following a call to sqlite3_set_auxdata(C,N,P,D) when SQLite ceases to hold the metadata.
F16277 | SQLite ceases to hold metadata for an SQL function parameter when the value of that parameter changes.
F16278 | When sqlite3_set_auxdata(C,N,P,D) is invoked, the destructor is called for any prior metadata associated with the same function context C and parameter N.
F16279 | SQLite will call destructors for any metadata it is holding in a particular prepared statement S when either sqlite3_reset(S) or sqlite3_finalize(S) is called.

See also lists of Objects, Constants, and Functions.

This page last modified 2008/05/12 13:08:44 UTC