USER EXIT(PL/SQL INTERFACE) problem 
Author Message
 USER EXIT(PL/SQL INTERFACE) problem

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);

Quote:
}

/******************************************************************************/
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



Fri, 21 Dec 2001 03:00:00 GMT
 USER EXIT(PL/SQL INTERFACE) problem



Quote:
> 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.
[snip]
> my_func(short my_int)
[snip]
> 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);

[snip]

I have not dug deeply into you code. But have I noted that you have not
registered the return type of your C function (implicit return type int). I
guess not registering it might f... up your stack frame causing it to return
a "random" value.

Add this call to your package intantiation code, I think that is the missing
part:

ora_ffi.register_return(fh_program,ora_ffi.C_INT);

Cheers,
Johan



Fri, 21 Dec 2001 03:00:00 GMT
 USER EXIT(PL/SQL INTERFACE) problem
Finally got the code work, two things learnt from the course:
1. don't miss the registeration of the return type of the foreign func.  
(thank Johan)
2. if the foreign function's parameter is an integer, define it as the
binary_integer in the PL/SQL interface. (but don't know why)

Regards,
Fu  



Sat, 22 Dec 2001 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. USER EXIT(PL/SQL INTERFACE) problem

2. User Exit Interface to FOREIGN FUNCTIONS

3. Exit from PL/SQL Exception Block

4. PL/SQL: Exiting to Operating System?

5. quit or exit within PL/SQl

6. pgsql/src interfaces/perl5/test.pl interfaces/ ...

7. user exits problem , please help

8. User Exit db2uext2 problem on AIX system

9. TX-DALLAS-170487--ORACLE-C-C++-PL/SQL-SQL-i2-i2 Interface Developer

10. PL/SQL-Problem with access to table of another user

11. PL/SQL - IN OUT PARAMETER problem: ORA-06502: PL/SQL: Numeric or value error


 
Powered by phpBB® Forum Software