Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> USER EXIT(PL/SQL INTERFACE) problem

USER EXIT(PL/SQL INTERFACE) problem

From: Zhao Fu <scip6125_at_leonis.nus.edu.sg>
Date: 5 Jul 1999 12:08:27 GMT
Message-ID: <7lq77r$p5b$1@nuscc.nus.edu.sg>


Hi,

I am writing a user exit for a Forms45's button. The code is just mimicking a sample code presented in the on-line help(PL/SQL Interface to Foreign functions). The testing code is simple: a numerical value is passed from the form to the C foreign function, in the C code the number is printed into a file. To my surprise, the results are always wrong and irregular.

/******************************************************************************/
 The original C function. Got the .so file by "gcc -G myfile.c -o myfile.so"
/******************************************************************************/
#include <stdio.h>

my_func(short my_int)
{

	FILE *fp;
      	fp=fopen("test.txt","w");
      	fprintf(fp,"The number is %d\n", my_int);
  	fclose(fp);

}

/******************************************************************************/
The PL/SQL interface package: (package specification)
/******************************************************************************/

PACKAGE test_ffi IS

FUNCTION run_ge(my_int in integer)
 return binary_integer;
END test_ffi;

/******************************************************************************/
The PL/SQL interface package: (package body)
/******************************************************************************/
PACKAGE BODY test_ffi IS

 lh_program ora_ffi.libHandleType;
 fh_program ora_ffi.funcHandleType;

 FUNCTION icd_program (funcHandle IN ora_ffi.funcHandleType,my_int in integer)

   return binary_integer;
   PRAGMA interface(C,icd_program,11265);

 FUNCTION run_ge(my_int in integer)
   return binary_integer is
 begin
   return(icd_program(fh_program, my_int));  end run_ge;

BEGIN
  lh_program:=ora_ffi.load_library(NULL,'myfile.so');   fh_program:=ora_ffi.register_function(lh_program,'my_func',ora_ffi.C_STD);   ora_ffi.register_parameter(fh_program,ora_ffi.C_SHORT); END test_ffi;

/******************************************************************************/
I call the foreign fucntion using the following button's trigger:
/******************************************************************************/
declare

   i integer;
   errcode integer;    

 begin
   i:=30;
   errcode:=test_ffi.run_ge(i);
 end;

/******************************************************************************/
Testing the call many times, the results may be some strange numbers like the following one (the right one should be 'The number is 30')
/******************************************************************************/
'The number is -13228'

I would appreciate it very much if you could help me in solving this problem.

Thank you in advance,
Zhao Fu Received on Mon Jul 05 1999 - 07:08:27 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US