Friday, April 15, 2011

How to use External Procedure with Borland C++ Compiler?

Just got email to ask about External Procedure by using Borland C++ Compiler. I posted "Test Oracle External Procedure on windows". That used Microsoft SDK and Visual C++.
How to use External Procedure with Borland C++ Compiler? I think it's not differ anyway. I replied email and came back for test on my NoteBook.

I downloaded Borland C++ Compiler from Embarcadero Developer Network (EDN), installed at D:\Borland\BCC55 PATH and then build "bcc32.cfg" file at D:\Borland\BCC55 PATH.
In "bcc32.cfg" file:
I started to test with "shell.c" file.
In "shell.c" file:
#include <windows.h>
#include <stdio.h>

#include <stdlib.h>

void __declspec(dllexport) sh(char *);

void sh(char *cmd)
I compiled program (check from below picture):
D:\Borland\shell> bcc32 -WD shell.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
After compiled, I found shell.dll file, then copy to D:\oraclexe\app\oracle\product\11.2.0\server\bin\shell.dll *** for easy ***

*** ORACLE_HOME=D:\oraclexe\app\oracle\product\11.2.0\server***

Check Listener supports External Procedure before (this can check from Link)
*** However, Listener on 11.2 XE supports External Procedure (didn't anything) ***

Then created library and procedure in Database for test.
create or replace library shell_lib as 'D:\oraclexe\app\oracle\product\11.2.0\server\bin\shell.dll';

create or replace procedure SHELL (
cmd IN varchar2)
as external
library shell_lib
name "_sh"
language C
parameters (
cmd string);
Finally, I tested to call procedure like above picture and It's work.

Related Links:
Test Oracle External Procedure on windows
Create and Run a Sample External Procedure Program on Linux

No comments: