Re: How do I use Oracle from a UNIX C++ program (Pro C, OCI, etc)?

From: Dudley Irish <dirish_at_arsmagna.com>
Date: 2000/04/26
Message-ID: <m3ya60ohqi.fsf_at_localhost.localdomain>#1/1


"Johan Wegener" <xjw_at_xdde.xdk> writes:

> Don <chambers_at_inquiregroup.com> skrev i en
> nyhedsmeddelelse:3908ad3a.84187304_at_news-east.newscene.com...
> >I am writing a middle tier C++ program that will run on a UNIX system
> >(HP-UX) and needs to connect to Oralce. Has anyone had success with
> >this?
> Yes!
>
> >What is the best way to do it?
> Check out the sample programs (typically in the $ORACLE_HOME/proc directory)
> and read the on-line manual is basically your only options if you do not
> have a guru at your hand...
>
> >[...]
> >They just tell me to look at a sample make file.
> I don't know SoftBench either, I don't think one can expect Oracle support
> to be capable in each and every development tool. But if you know makefiles,
> you can probably mimic that in SoftBench...
>
> >I am considering using the Orcle Call Interface (OCI) but have never
> >used it.
> In that case I would not recommend it, to use it you should IMO be well
> versed in Oracle-eze. And you will have to "face the makefiles" anyway to
> get your stuff to link properly...
>
> >I can't seem to find many books or any classes for Pro*C or OCI.
> The only book that exists is out of print...
>
> >Does anyone have any suggestions?
> As an exercise get one of the sample programs to pre-compile, compile, link
> and execute using SoftBench, then select the sample programs that resembles
> what you want to do mostly, cut and paste the logic and adapt that to you
> middle-tier program...
>
> Cheers,
> Johan

I just had to reply to this. I have just finished a C++ program that accesses Oracle from C++ on both Linux and HP/UX. I used OCI. It has been sugested that OCI is harder to use than PROC. Well, I have used both extensively, and I only use PROC when I am required to.

The reason I use OCI is that I am quite comfortable calling library functions. I think that most developers are. There is extensive documentation available on the documentation CD (Oh, by the way, get the documentation CD). However, in creating a class to wrap your database access (and there are several out there if you look, both free and for sale) using OCI will be much easier. You can use PROC in a C++ program but the only reason for doing it would be if you already were proficent in using embedded SQL. If not, then I would use OCI.

As for getting it all to work under softbench, use gnu make. Just kidding. :-)

The advice given above, to start with one of the sample programs, is good. It is what I do everytime I write an Oracle application. There are two problems that you need to solve, finding the include files and finding the libraries. The include should present no problem; I assume that it is easy to add an include directory to Softbench's search path. The libraries are another matter. If you are familier with make file syntax you can sort out the required libraries from that. There are two problems that might arise depending on details of which C++ compiler you are using and the linker's behavior, getting the libraries in the right order, and repeating libraries. You may need to reorder and repeat the libraries in order to get all the references resolved. The other thing that might seem a little strange if you aren't really familier with Oracle is that there are some object files that need to be linked to your executable which are not in libraries. Don't ask me why.

Just to repeat, use OCI. It will probably fit into Softbench with a lot less fiddling than PROC and it is no harder to use than any other medium sized API.

Dudley Irish Received on Wed Apr 26 2000 - 00:00:00 CEST

Original text of this message