Re: OCI Example?

From: Tim Smith <tssmith_at_netcom.com>
Date: Tue, 16 Mar 1993 09:27:37 GMT
Message-ID: <1993Mar16.092737.931_at_netcom.com>


In article <1993Mar15.160816.1623_at_cvgis.prime.com> al_at_cvgis.prime.com (Al Parker) writes:
>On a related point,
>With ORACLE V7, there does not seem to be an example of a program which
>mixes both Pro*C and OCI calls.

Al,

I'm the writer on the V6 and V7 OCI manuals, and I can assure you that SQLLDA was tested. I tested it on both V6 and V7, and our QA suite also exercised it. It worked on both versions. I've included a V7 test program below that you can try. Let me (or better, your support people) know if this doesn't work for you. One thing you will need to do is make the included .h files, such as oratypes.h., ocidfn.h, and ocidem.h available. These are included with the OCI ORACLE7 distribution.

I tested this on VMS, but it should work on any platform.

Your message makes me think that we should include this sample program in future manual releases. Consider it done.

>This is more of a problem since ORACLE didn't ship me the
>Pro*C and OCI manuals with this (Beta) release and coding OCI using
>sqllda() as described in the V6 OCI manuals doesn't seem to work.

The way it (should) work is this: when you buy the kernel, you get the OCI libraries, but not the manual. You have to order that separately (the part number is 5411-70-1292). When you buy the procedural option with one or more precompilers, you should get the relevant precompiler manuals. If not, contact your sales person and gripe.

--Tim (tssmith_at_oracle.com)

Demo program follows--

#include <stdio.h>
#include <string.h>
#include <oratypes.h>

/* LDA and CDA struct declarations */
#include <ocidfn.h>
/* use ANSI-style function declarations */ #include <ociapr.h>
/* demo constants and structs */
#include <ocidem.h>

#define OCI

Lda_Def lda;
Cda_Def cda;

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR username[20];
    VARCHAR password[20];
EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE sqlca;

void sqlerror();

main()
{

    strcpy(username.arr, "SCOTT");
    username.len = strlen(username.arr);     strcpy(password.arr, "TIGER");
    password.len = strlen(password.arr);

    EXEC SQL WHENEVER SQLERROR DO sqlerror();

    EXEC SQL CONNECT :username IDENTIFIED BY :password;     printf("\nConnected to ORACLE as user: %s\n", username.arr);

    sqllda(&lda);

    if (oopen(&cda, &lda, (text *) 0, -1, -1, (text *) 0, -1))     {

        printf("\nCannot open OCI cursor\n");
        exit(1);

    }

    if (oparse(&cda, "create table xyzzy (c1 varchar2(10))", -1, 0, 2))     {

        sqlerror();
    }

    EXEC SQL COMMIT WORK RELEASE;
    exit(0);
}     

void
sqlerror()
{

    char msgbuf[512];
    int msglen, buflen;     

    EXEC SQL WHENEVER SQLERROR CONTINUE;     printf("\nORACLE error detected:\n"); #ifdef OCI

    printf("\n%d\n", cda.rc);
    buflen = sizeof msgbuf;
    oerhms(&lda, cda.rc, msgbuf, buflen);     printf("%.*s\n", msglen, msgbuf);
#else

    printf("%d\n", sqlca.sqlcode);
    printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc); #endif         

    EXEC SQL ROLLBACK RELEASE;
    exit(1);
} Received on Tue Mar 16 1993 - 10:27:37 CET

Original text of this message