Stored Procedure Samples
------------------------
1 How to create stored procedures
2 Stored Procedure Sample Files Purpose


1 How to create stored procedures
---------------------------------
    Steps:
       1. Write procedure code in ESQL/C language.

       2. Edit dmconfig.ini to configure related directories

          DB_FODIR: The directory to store the source files as system
                    file objects
          DB_SPDIR: The directory to place dmconfig.ini and makefile.
                    The shared object files for generated stored
                    procedure are also placed this directory.
          DB_SPLOG: The directory to place log files.
          DB_SPINC: Specify extra compile option if necessary.

       3. Create stored procedure by issue create stored procedure
          command in dmsqlc or by DBATool's create procedure function.


2 Stored Procedure Sample Files Purpose
---------------------------------------
    Sample: StoreProc\01simple.ec

    Purpose:
        This sample program show how a stored procedure return the row count
        of SYSTEM.SYSTABLE

    Steps in Windows
        1. Start dmSQL from 'DBMaker 5.4' program folder (Win32).

        2. Execute the SQL command sequentially.
           dmSQL> connect to DBSAMPLE5 sampleuser;
           dmSQL> create procedure from 'C:\DBMaker\5.4\samples\StoreProc\01simple.ec';
           dmSQL> call sample.sp_GetTableCount(?);

    Steps in UNIX
        1. Type '/APP_HOME/bin/dmsqlc' command under UNIX.

        2. Execute the SQL command sequentially.
            dmSQL> connect to DBSAMPLE5 sampleuser;
            dmSQL> create procedure from '/APP_HOME/samples/StoreProc/01simple.ec';
            dmSQL> call sample.sp_GetTableCount(?);


    Sample: StoreProc\02sharedobj.ec

    Purpose:
        This sample program demonstrates store procedure call shared
        object(SYSTEM SP). It simulates a hospital registeration function,
        insertdata, which accepts patient's number and name as input and
        return the register number as result.

    Steps in Windows
        1. Start dmSQL from 'DBMaker 5.4' program folder.

        2. Execute the SQL command sequentially.
            dmSQL> connect to DBSAMPLE5 sampleuser;
            dmSQL> call socreate(100,0,?);
            dmSQL> create procedure from 'C:\DBMaker\5.4\samples\StoreProc\02sharedobj.ec';
            dmSQL> ?=call sample.sp_insertPatient(100,'Joyce',?);

    Steps in UNIX
        1. Type '/APP_HOME/bin/dmsqlc' command under UNIX.

        2. Execute the SQL command sequentially.
            dmSQL> connect to DBSAMPLE5 sampleuser;
            dmSQL> call socreate(100,0,?);
            dmSQL> create procedure from '/APP_HOME/samples/StoreProc/02sharedobj.ec';
            dmSQL> ?=call sample.sp_insertPatient(100,'Joyce',?);


    Sample: StoreProc\03mail.ec

    Purpose:
        This sample program show how to use stored procedure to send mail
        using SMTP on Win32 or UNIX. This example can be used to send mails
        from DBMaker database server. To execute this stored procedure, you
        have to know the parameters to fill. There are four parameters for
        this stored procedure. The first parameter is the e-mail address you
        want to send mail to. The second parameter is the mail server's
        name. The third parameter is the mail subject. The last parameter is
        the mail content.

    Steps in Windows
        1. Start dmSQL from 'DBMaker 5.4' program folder (Win32).

        2. Execute the SQL command sequentially.
            dmSQL> connect to DBSAMPLE5 sampleuser;
            dmSQL> create procedure samplesp.sample.mail(char(32) name, char(32) smtp, char(32) subject, char(256) data);
            dmSQL> call sample.mail('joyce@her.email.addr','your.email.relay.host', 'subject', 'content');
            
            note: the sp "mail" have been built into moudle SAMPLESPSAMPLE.dll, so we can only register 
                  procedure defination. user can create procedure from 03mail.ec.
            
    Steps in UNIX
        1. Type '/APP_HOME/bin/dmsqlc' command under UNIX.

        2. Execute the SQL command sequentially.
            dmSQL> connect to DBSAMPLE5 sampleuser;
            dmSQL> create procedure samplesp.sample.mail(char(32) name, char(32) smtp, char(32) subject, char(256) data);
            dmSQL> call sample.mail('joyce@her.email.addr','your.email.relay.host', 'subject', 'content');

            note: the sp "mail" have been built into moudle SAMPLESPSAMPLE.dll, so we can only register 
                  procedure defination. user can create procedure from 03mail.ec.
