Sure!

Here are the results:
 Good:
           The 'destructor' function attribute works just as advertised. I
have included below the modified half.so example code from sqlite website
with the 'constructor' and  'destructor' functions (for linux using gcc).

Bad:
        The '.q' command on sqlite command-line utility  attempts to close
the database before calling 'dlclose' on the loaded extension library. I
think this should be fixed in SQLite code.  Here is the log:
===
sqlite> .load ./libMyLib.so
Success create function: MyLib_test
sqlite> .q
error closing database: Unable to close due to unfinalised statements
Success drop function: MyLib_test
===

MODIFIED HALF.c
===
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1

void construct() __attribute__ ((constructor));
void construct(){
printf("-----In Constructor-----\n");
};
void destruct() __attribute__ ((destructor));
void destruct(){
printf("-----In Destructor-----\n");
};
/*
** The half() SQL function returns half of its input value.
*/
static void halfFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite3_result_double(context, 0.5*sqlite3_value_double(argv[0]));
}

/* SQLite invokes this routine once when it loads the extension.
** Create new functions, collating sequences, and virtual table
** modules here.  This is usually the only exported symbol in
** the shared library.
*/
int sqlite3_extension_init(
  sqlite3 *db,
  char **pzErrMsg,
  const sqlite3_api_routines *pApi
){
//    sqlite3_enable_load_extension(db,1);
  SQLITE_EXTENSION_INIT2(pApi)
  sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
  return 0;
}

===


LOG OF HALF.SO
===
sqlite> .load ./half.so
-----In Constructor-----
sqlite> .q
-----In Destructor-----
===

Thanks,
SK

On Tue, Sep 1, 2009 at 5:54 PM, Jean-Christophe Deschamps <j...@q-e-d.org>wrote:

> Hi,
>
> ´¯¯¯
> >2. Following up on windows dllmain  info - which was very useful in itself
> >-  but since we use both windows and linux, I checked the equivalent for
> >linux as well and yes, luckily, gcc allows you to define a 'function
> >attribute' called 'constructor' and 'destructor' which can be used to
> >export
> >the functions in your shared lib to  invoke at dlopen and dlclose. So, I
> >should be able to use this 'destructor'-attributed function for library
> >stuff cleanup on linux - haven't gotten to testing it yet though.
> `---
>
> I wasn't sure such a possibility was available on Linux, but it was
> nonetheless probable nowadays.
>
> So if it works more or less similarily, you are just a few #ifdef away
> from a workable solution for both systems.  That's a good news.  Let us
> know how it turns out.  I bet others would love to find an already
> tested solution in some future.
>
>
>
> _______________________________________________
> 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

Reply via email to