User Defined Function Samples
-----------------------------
1 User Defined Function (UDF) Sample Files Purpose
2 How to Run UDF Samples in Windows
3 How to Run UDF Samples in UNIX


1 User Defined Function (UDF) Sample Files Purpose
--------------------------------------------------
    Sample: UDF\md5

    Purpose:    
        This sample program defined two udfs(user-defined function): MD5DATA 
        and MD5FILE, which calculate a message-digest fingerprint (checksum) 
        for a string buffer or a file relatively. Md5 takes as input a 
        message of arbitrary length and produces as output a 128-bit 
        "fingerprint" or "message digest" of the input.  It is conjectured 
        that it is computationally infeasible to produce two messages having 
        the same message digest, or to produce any message having a given 
        prespecified target message digest.  The MD5 algorithm is intended 
        for digital signature applications, where a large file must be 
        "compressed" in a secure manner before being encrypted with a 
        private (secret) key under a public-key cryptosystem such as RSA.     


    Sample: UDF\regex

    Purpose:
        This sample program defined REGEXP udf, which support regular 
        expressions whose syntax and semantics are as close as possible to 
        those of the Perl 5 language.


2 How to Run UDF Samples in Windows
-----------------------------------
    Important Note:
        If you are the power user of VC ++, you can create the dll make file 
        by yourself by the follow steps. All you have to note is set the 
        structure member alignment to be 4 bytes. 

    Build:
        1. Use C Compiler of Microsoft (i.e. Visual C ++ 6.0 or compatible 
           compiler).
        2. Select to create 'Dynamic-Link Library'(DLL).
        3. Add 'C:\DBMaker\5.4\Include' and 'C:\DBMaker\5.4\Samples\udf\
           md5' in the 'Include Files' Search Path.
        4. Add 'C:\DBMaker\5.4\LIB' to the 'Library Modules' Search Path.
        5. Add 'dmudf.lib' to the Link Library Modules.
        6. Select and Build md5.dll file.

    Execute md5:
        1. In database server, add DB_LBDIR keyword to specify the 
           directory. For example, 

            [DBSAMPLE5]
            DB_LBDIR=C:\DBMaker\5.4\samples\database        ; for WIN32     

        2. Copy the md5.dll file to a lib directory of Database.

        3. In database client, start dmSQL. 

        4. Execute SQL command to connect to DBSAMPLE5 database.

             dmSQL> connect to 'DBSAMPLE5' 'SYSADM';

        5. Create user-defined functions.

             dmSQL> create function md5.MD5DATA(string) returns string;
             dmSQL> create function md5.MD5FILE(string) returns string;

        6. Call the functions.

             dmSQL> select md5data('a string') from SYSINFO;
             dmSQL> select md5file('a full path filename') from SYSINFO; 

    Execute regex:
        1. Create user-defined functions.

             dmSQL> create function regex.REGEXP(string, string) returns int;

        2. Call the function.
           To list tables whose name contains 'trigger'       
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/trigger/')=1; 
           
           To list tables whose name contains 'trigger' ignorance case.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/trigger/i')=1;
           
           To list tables whose name was ended by number.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/\d$/')=1; 
           
           To list tables whose name was begin with a, b, or c, ignorance
           case.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/^[a-c]/i')=1; 


3 How to Run UDF Samples in UNIX
--------------------------------
    Build:
        1. Check what compiler is provided on your machine, for example
           'cc'.

        2. Set the include path to the 'inlcude' directory under the home 
           directory of the user 'dbmaker' and compile the C program. For 
           example:

             % cc -fpic  -I. -I/APP_HOME/include -c md5c.c md5hl.c

        3. Link md5.o to a shared module that will loading in the 
           Client-Server environment. For example :

             % ld -Bshareable -o $@ md5c.o md5hl.o

    Execute md5:
        1. Type 'make' command under the shell environment.

             % make

           Two binary file are created, md5.so and md5test. The md5.so is a 
           shared module used by DBMaker database server, and the md5test is 
           development time executable file. You can trace and debug it in 
           your working environment.

        2. In database server, add DB_LBDIR keyword to specify the 
           directory. For example, 

            [DBSAMPLE5]
            DB_LBDIR=/APP_HOME/samples/DATABASE

        3. Makefile will copy the md5.so file to a lib directory of Database 
           for you.

        4. In database client, start dmsqlc
        
             % /APP_HOME/bin/dmsqlc

        5. Execute SQL command to connect to DBSAMPLE5 database.

             dmSQL> connect to 'DBSAMPLE5' 'SYSADM';

        6. Create user-defined functions.

             dmSQL> create function md5.MD5DATA(string) returns string;
             dmSQL> create function md5.MD5FILE(string) returns string;

        7. Call the functions.

             dmSQL> select md5data('a string') from SYSINFO;
             dmSQL> select md5file('a full path filename') from SYSINFO; 

    Execute regex:
        1. Type 'make' command under the shell environment.

             % cd pcre
             % make

           A library file 'libpcre.a' are created. This is Perl-Compatible 
           Regular Expressions matching engine.

             % cd ..
             % make

           Two binary file are created, regex.so and regex. The regex.so is 
           a shared module used by DBMaker database server, and the regex is 
           development time executable file. You can trace and debug it in 
           your working environment.

        2. In database server, add DB_LBDIR keyword to specify the 
           directory. For example, 

            [DBSAMPLE5]
            DB_LBDIR=/APP_HOME/samples/DATABASE

        3. Makefile will copy the regex.so file to a lib directory of 
           Database for you.

        4. In database client, start dmsqlc
        
             % /APP_HOME/bin/dmsqlc

        5. Execute SQL command to connect to DBSAMPLE5 database.

             dmSQL> connect to 'DBSAMPLE5' 'SYSADM';

        6. Create user-defined functions.

             dmSQL> create function regex.REGEXP(string, string) returns int;

        7. Call the function.
           To list tables whose name contains 'trigger'       
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/trigger/')=1; 
           
           To list tables whose name contains 'trigger' ignorance case.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/trigger/i')=1;
           
           To list tables whose name was ended by number.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/\d$/')=1; 
           
           To list tables whose name was begin with a, b, or c, ignorance
           case.
           
             dmSQL> select TABLE_NAME from SYSTABLE 
                     where regexp(TABLE_NAME,'/^[a-c]/i')=1; 


