Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    13

    Question Unanswered: How to compile C program for stored procedure

    Hi,

    I am converting the Sybase stored procedures to DB2 UDB v7.2.9 for Windows. There are some global variable like @@sid is not supported in DB2. I found the following code in Internet that may help to solve the problem. However, I don't know how to compile the C program. Please advise how can I compile the C program to a DLL file and where to put the DLL file. I am using the compiler GCC on windows to compile stored procedure.

    ==============================================
    create function GET_APPL_ID()
    returns char(32)
    external name 'GET_APPL_ID!GET_APPL_ID'
    language c parameter style db2sql
    NOT DETERMINISTIC FENCED
    NULL CALL
    NO SQL
    EXTERNAL ACTION
    NO SCRATCHPAD
    NO FINAL CALL
    DBINFO
    ;

    C code

    #include <stdlib.h>
    #include <string.h>
    #include <sqludf.h>
    #include "sqlca.h"
    #include "sqlda.h"

    #ifdef __cplusplus
    extern "C"
    #endif

    void SQL_API_FN GET_APPL_ID(
    SQLUDF_CHAR *appl_id, /* application id*/
    SQLUDF_SMALLINT *appl_idNull,
    SQLUDF_TRAIL_ARGS,
    SQLUDF_DBINFO *db) /* db info */
    {
    strcpy(appl_id, db->appl_id);
    }


    ==============================================

    Thanks,
    Vincent

  2. #2
    Join Date
    Apr 2003
    Location
    Phoenix, AZ
    Posts
    177
    Included on your installation CD is a samples directory. In addition to some sample UDF's you will find the .BAT files required to compile and install a UDF.

    BLDRTN.BAT invoke the compile process and may need to be modified to support GCC. I've never used GCC and the .BAT file works fine for Visual C++.

    You will need to create a .DEF file.

    EMBPREP.BAT is called to create a bind file.

    Ultimately, your DLL goes in the function directory under your instance.

    Since the documentation on this process sucks my suggestion is to look at the examples IBM has created under /samples - specifically UDF's.


    fprose at supreme dot sp dot state dot az dot us
    Fred Prose

  3. #3
    Join Date
    Sep 2003
    Posts
    13
    I can compile the C program to DLL file now and put it into the right directory and the stored procedure also compiled successfully. However, when I call the function like this "SELECT GET_APPL_ID() FROM TABLEABC", the call was successful but no result returned. Is this correct? Do I need to generate a .sqc file for the C program and call the EMBPREP.BAT to create a bind file for the C program.

    Thanks,
    Vincent


    Originally posted by fprose
    Included on your installation CD is a samples directory. In addition to some sample UDF's you will find the .BAT files required to compile and install a UDF.

    BLDRTN.BAT invoke the compile process and may need to be modified to support GCC. I've never used GCC and the .BAT file works fine for Visual C++.

    You will need to create a .DEF file.

    EMBPREP.BAT is called to create a bind file.

    Ultimately, your DLL goes in the function directory under your instance.

    Since the documentation on this process sucks my suggestion is to look at the examples IBM has created under /samples - specifically UDF's.


    fprose at supreme dot sp dot state dot az dot us

Posting Permissions

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