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 metadata 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 metadata 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 metadata 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 metadata associated by the sqlite3_set_auxdata() function with the Nth argument value to the application-defined function. If no metadata has been ever been set for the Nth argument of the function, or if the corresponding 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 metadata pointed to by its 3rd parameter as the metadata 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 metadata when the corresponding function parameter changes or when the SQL statement completes, whichever comes first.
SQLite is free to call the destructor and drop metadata 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, metadata is preserved between function calls for expressions that are constant at compile time. This includes literal values and parameters.
These routines must be called from the same thread in which the SQL function is running.