Professional Web Applications Themes

constructor in dynamicly loaded library containing user defined functions not run when loading from mysql? - MySQL

Hi, I've been writing a user defined function with a very expensive initialisation which only needs to run once. I thought it might be possible to put it in the constructor section of the shared library object (__attribute__((constructor)) function) to be run at dlopen time, but this does not seem to be run when loading from mysql. Is this really the case? If so, what's the correct way to go about solving the situation? Would creating a soliton be ok? (eg. the following dummy library returns 0 when called from mysql, but should return 3 if the constructor would be ...

  1. #1

    Default constructor in dynamicly loaded library containing user defined functions not run when loading from mysql?

    Hi,

    I've been writing a user defined function with a very expensive
    initialisation which only needs to run once. I thought it might be possible
    to put it in the constructor section of the shared library object
    (__attribute__((constructor)) function) to be run at dlopen time, but this
    does not seem to be run when loading from mysql.
    Is this really the case? If so, what's the correct way to go about solving
    the situation? Would creating a soliton be ok?

    (eg. the following dummy library returns 0 when called from mysql, but
    should return 3 if the constructor would be run.

    //start
    #ifdef STANDARD
    #include <stdio.h>
    #include <string.h>
    #ifdef __WIN__
    typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
    typedef __int64 longlong;
    #else
    typedef unsigned long long ulonglong;
    typedef long long longlong;
    #endif /*__WIN__*/
    #else
    #include <my_global.h>
    #include <my_sys.h>
    #endif
    #include <mysql.h>


    #ifdef HAVE_DLOPEN

    extern "C" {
    my_bool dummy_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
    void dummy_deinit(UDF_INIT *initid);
    long long dummy(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
    *error);
    void __attribute__((constructor)) dummy_real_init(void);
    void __attribute__((destructor)) dummy_real_deinit(void);
    }

    static long long secret = 0;
    void __attribute__((constructor)) dummy_real_init(void) {
    secret = 3;
    }

    void __attribute__((destructor)) dummy_real_deinit(void) {
    secret = 1;
    }

    my_bool dummy_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
    {
    return 0;
    }


    void dummy_deinit(UDF_INIT *initid)
    {
    }

    long long dummy(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
    *error)
    {

    return secret;
    }


    #endif /* HAVE_DLOPEN */

    //end

    Thanks,
    alejandro

    Alejandro Dubrovsky Guest

  2. #2

    Default Re: constructor in dynamicly loaded library containing user definedfunctions not run when loading from mysql?

    Alejandro Dubrovsky wrote:
    > I've been writing a user defined function with a very expensive
    > initialisation which only needs to run once.
    The above immediately gives me a gut feeling that the work done by your
    UDF should be implemented in the application, not in a UDF.

    Or alternately by using additional tables in the database. That is,
    there are ways to keep predefined data in the database and use operators
    like JOIN to perform work that could have been done by a UDF.

    Regards,
    Bill K.
    Bill Karwin Guest

Similar Threads

  1. Dynamicly loaded User Control events in a Placeholder
    By MikeM in forum ASP.NET Building Controls
    Replies: 1
    Last Post: April 12th, 07:31 PM
  2. Loading dynamicly from from Library
    By mrmille in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 27th, 05:13 PM
  3. User Defined Functions, and other stories....
    By Brian McGee in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 8th, 02:41 PM
  4. How and where to create User-Defined functions
    By Serge Rielau in forum IBM DB2
    Replies: 0
    Last Post: June 30th, 05:16 PM
  5. user defined functions and recursive selects
    By Serge Rielau in forum IBM DB2
    Replies: 0
    Last Post: June 30th, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139