Re: [sqlite] How to create connection life-time object?
What I need is 'install and don't care' because I use many C++ classes as lifetime objects. I think that my solution does work now well, but if there would be a way to avoid use of SQL parser, it would be better. 2013/7/27 Max Vlasov> On Fri, Jul 26, 2013 at 9:56 PM, Dušan Paulovič > wrote: > > > Thanks for suggestion, but: > > 1.) one object is not linked to one connection > > > > If you have your own memory management, it's not a problem since the scheme > I described is basically just a storage of pointers. To free or not to free > (if the pointer points to a disposable entity) is your decision at your > chosen time. But if you want automatic reference counting (so when a > pointer not referenced anymore, it would be automatically deallocated), I > agree, the proposal is not good. Probably using your own global structure > not related to sqlite is less pain. > > > > 2.) object is not destroyed together with connection > > > > The same, you're free to use the table just as pointers storage > > Max > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to create connection life-time object?
On Fri, Jul 26, 2013 at 9:56 PM, Dušan Paulovičwrote: > Thanks for suggestion, but: > 1.) one object is not linked to one connection > If you have your own memory management, it's not a problem since the scheme I described is basically just a storage of pointers. To free or not to free (if the pointer points to a disposable entity) is your decision at your chosen time. But if you want automatic reference counting (so when a pointer not referenced anymore, it would be automatically deallocated), I agree, the proposal is not good. Probably using your own global structure not related to sqlite is less pain. > 2.) object is not destroyed together with connection > The same, you're free to use the table just as pointers storage Max ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to create connection life-time object?
Thanks for suggestion, but: 1.) one object is not linked to one connection 2.) object is not destroyed together with connection Dusan 2013/7/26 Max Vlasov> Hi, Dušan > > > On Thu, Jul 25, 2013 at 2:39 PM, Dušan Paulovič > wrote: > > > Hello, is there a way to somehow set a connection life-time object? > > ... > > > > > > 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*/ > > ); > > > > > > How about temporary memory table just for the task of storing your objects. > > You initialization code for particular connection > Attach ':memory:' as MyObjectStorage > Create table MyObjectStorage.[objects] (Name Text, Ptr Text) > > Your code for inserting an object > Insert into MyObjectStorage.[objects] (Name, Ptr) VALUES ('obj1', > '0x12345678') > > This code will query the pointer > select Ptr from MyObjectStorage.[objects] where Name='obj1' > > The only convention rule here will be the name of the attached db so no > other databases (or instances of the same storage) should use this name. > > Max > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to create connection life-time object?
Hi, Dušan On Thu, Jul 25, 2013 at 2:39 PM, Dušan Paulovičwrote: > Hello, is there a way to somehow set a connection life-time object? > ... > > > 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*/ > ); > How about temporary memory table just for the task of storing your objects. You initialization code for particular connection Attach ':memory:' as MyObjectStorage Create table MyObjectStorage.[objects] (Name Text, Ptr Text) Your code for inserting an object Insert into MyObjectStorage.[objects] (Name, Ptr) VALUES ('obj1', '0x12345678') This code will query the pointer select Ptr from MyObjectStorage.[objects] where Name='obj1' The only convention rule here will be the name of the attached db so no other databases (or instances of the same storage) should use this name. Max ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How to create connection life-time object?
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*), 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