<< previous page   --   table of contents   --   next page >>
| | | | | | | |
  • Return to Table of Contents
  • Table of Contents

    1. General Information
    2. MySQL Installation
    3. Tutorial Introduction
    4. Database Administration
    5. MySQL Optimisation
    6. MySQL Language Reference
    7. MySQL Table Types
    8. MySQL APIs
    9. Extending MySQL

    Chapter 9:  Extending MySQL 619 1.  Call xxx_init() to let the aggregate function allocate the memory it will need to store results. 2.  Sort the table according to the GROUP BY expression. 3.  For the rst row in a new group, call the xxx_reset() function. 4.  For each new row that belongs in the same group, call the xxx_add() function. 5.  When the group changes or after the last row has been processed, call xxx() to get the result for the aggregate. 6.  Repeat 3-5 until all rows has been processed 7.  Call xxx_deinit() to let the UDF free any memory it has allocated. All functions must be thread-safe (not just the main function,  but the initialisation and deinitialisation  functions  as  well).   This  means  that  you  are  not  allowed  to  allocate  any global or static variables that change!  If you need memory, you should allocate it in xxx_ init() and free it in xxx_deinit(). 9.2.2.1  UDF Calling Sequences for simple functions The  main  function  should  be  declared  as  shown  here.    Note  that  the  return  type  and parameters di er, depending on whether you will declare the SQL function XXX() to return STRING,  INTEGER, or  REAL  in the  CREATE FUNCTION  statement: For STRING functions: char *xxx(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error); For INTEGER functions: long long xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); For REAL functions: double xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); The initialisation and deinitialisation functions are declared like this: my_bool xxx_init(UDF_INIT *initid, UDF_ARGS *args, char *message); void xxx_deinit(UDF_INIT *initid); The initid parameter is passed to all three functions. It points to a UDF_INIT structure that is used to communicate information between functions.  The UDF_INIT structure members are listed below.  The initialisation function should ll in any members that it wishes to change.  (To use the default for a member, leave it unchanged.): my_bool maybe_null xxx_init() should set maybe_null to 1 if xxx() can return NULL.  The default value is 1 if any of the arguments are declared maybe_null.
     

    Customer Support CentreMySQL Reference Manual

    Web Hosting Services
    UNIX WEB HOSTING
    MERCHANT ACCOUNTS
    DEDICATED SERVERS
    E-COMMERCE HOSTING
    SUPPORT & FAQ's
    TERMS OF USE
    Domain Services
    DOMAIN
    REGISTRATION
    MANAGE
    YOUR ACCOUNT
    SUPPORT & FAQ's
    TERMS OF USE
    Corporate Info
    ABOUT US
    OUR NETWORK
    CONTACT US
    SITE MAP
    Copyright © 2002 Dyntex Group, Inc. All Rights Reserved
  • Return to Table of Contents
  • Back to top

  • Web Hosting: Manuals & FAQ's

    1. Unix-Based Web Hosting
    2. Unix Dedicated Servers
    3. Windows Dedicated Servers
    4. CuteFTP User’s Guide
    5. CuteHTML User’s Guide
    6. WS_FTP Pro User's Guide
    7. Miva Order User's Guide
    8. Miva Merchant User's Guide