Hello, is there a way to somehow set a connection life-time object? I mean something like: Let's imagine you are working with some sqlite3 connection and want so share same data with extensions, but must be guaranteed, that object gets destroyed when connection is closed.
For now, I use creating function mechanism for it: (pseudo - not tested code) void return_user_data(sqlite3_context* ctxP, int argc, sqlite3_value** argv) { void * ptr = sqlite3_user_data(ctxP); sqlite3_result_blob(ctxP, (void*)&ptr, sizeof(void*)); } int register_app_obj(sqlite3 * db) { my_type *m_obj = (my_type*) sqlite3_malloc(sizeof(my_type)); if (m_obj && SQLITE_OK != sqlite3_create_function_v2( db, "app_obj", 0, SQLITE_ANY, m_obj, return_user_data, NULL, NULL, sqlite3_free)) { sqlite3_free(m_obj); m_obj = NULL; return SQLITE_ERROR; } return SQLITE_OK; } Then if extension needs to get app_obj it queries "SELECT app_obj();" and translates blob. But this way it is too much of overhead and also there is a restriction, that functions can be registered only if there is no any active statement. I have also made a complicated virtual table implementation of the same, because modules can be registered while statements are active, but it is much more complicated then such thing should be. Do you have any idea? It would be fine to have something like: int sqlite3_set_lifetime_object( sqlite3 *db, /*db connection*/ const char *zObjectName, /*utf8 name of object*/ void *pObject, /*if NULL, object is removed*/ void(*xDestroy)(void*) /*destructor*/ ); void * sqlite3_get_lifetime_object( sqlite3 *db, /*db connection*/ const char *zObjectName /*utf8 name of object*/ ); _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users