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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Writing a C Program in Unix

Re: Writing a C Program in Unix

From: <steyaert_at_my-deja.com>
Date: Wed, 19 Jan 2000 13:19:51 GMT
Message-ID: <864dla$1u7$1@nnrp1.deja.com>


There are lots of different options. We have a data collection system that was developed in 1991, on Interactive Unix and Oracle 6.0.3.30. Last year, we ported the entire thing to RedHat (5.0, and Oracle 8.0.5, actually) and got things going very well. (At least until RedHat 6.1 came out!)

There are lots of different options for doing database access, but we just stuck with "Embedded SQL." This means our queries are generally hard-coded into our C code (which is actually PC code.) From that C- Code, you run proc (version 7.0 and above, I believe, pcc before that.) That converts the code into C, and then you compile like normal. (With CC, GCC, or whatever.)

At the start of your PC file, you need to:

EXEC SQL INCLUDE SQLCA.H; This line includes all the necessary things that you need to do your embedded SQL.

Before you can use a variable, you need to define it, where Oracle can find it. To do that, you:

EXEC SQL BEGIN DECLARE SECTION;

VARCHAR        uid[20];
VARCHAR        pwd[20];

EXEC SQL END DECLARE SECTION; (With 8.0, and I assume 7.0, these can be locals to your C functions. In 6.0, they really didn't work as locals, and all our SQL variables became globals. This did mean that you needed to keep objects used multiple times the same size.)

Generally, before you start doing database access, you need to log in. We hard-coded the database user name for logging in. To log in, you do a:

EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;

After that, you can do all the database items that you need. You can declare cursors, update, insert, delete, etc. All items just need to be started with EXEC SQL.

Lastly, to log out, EXEC SQL COMMIT WORK RELEASE; or EXEC SQL ROLLBACK WORK RELEASE; Without the WORK RELEASE, the COMMIT and ROLLBACK work like expected. WORK RELEASE should drop your database connection. (If you leave zombie processes behind, your sqlnet.ora needs to have a bequeath_detach=yes added, and cycle the database. One of the many bugs our conversion from 8.0.5 to 8.1.5 turned up.)

There are other options that can be done, PL/SQL, and probably more. I have never investigated anything with that, since our system is programmed using Embedded SQL, and we have had very little problem porting it (and from 6.0 to 8 is a BIG change!)

Oh, you can get error numbers that occur based upon sqlca.sqlcode, with the text in sqlca.sqlerrm.sqlerrmc. They aren't easy, but....

Terry Steyaert
steyaert_at_my-deja.com

In article <86225g$amp$1_at_nnrp1.deja.com>,   Sean_at_kewi.net wrote:
> Very familiar with developing in an NT environment, but I'd like to
> port over to Unix (Hp-UX and Solaris). What do you use to connect to
> an Oracle Database? In Wintel, it's using ADO or OLE DB, what do you
> use in Unix and are there any recommended web sites out there?
>
> Thanks!
> Sean
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Wed Jan 19 2000 - 07:19:51 CST

Original text of this message

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