Re: C++ & Oracle
Date: 10 Dec 2001 03:58:23 -0800
Message-ID: <e7c90bfa.0112100358.7ad2cc08_at_posting.google.com>
"Sergey Sikorskiy" <sergey_sikorsky_at_worldnet.att.net> wrote in message news:<H2_I7.113736$WW.6929811_at_bgtnsc05-news.ops.worldnet.att.net>...
> http://www.geocities.com/skuchin/otl/home.htm
> is not bad too ...
>
> --
> Sergey Sikorsky
> Informax, Inc.
>
>
> "Raheem Suleman" <r2suleman_at_uwaterloo.ca> wrote in message
> news:mdfC7.352115$j65.91492051_at_news4.rdc1.on.home.com...
> > Can anyone please tell me how will i use Oracle with C++ on unix?
> >
> > Raheem
> >
> >
hi raheem,
as some people said u can either go for OCI or Pro*C. U can start with Pro*C... U need to do changes in ur makefile...
# a sample makefile may look like this.This is for solaris 2.6 and # oracle 7.3.4.U may need to modify further according to ur sys/app
# req.
include ./env_precomp.mk
.SUFFIXES: .pc .c .o
CC=gcc -v -Wall -g
CCP=c++ -v -Wall
LDSTRING=
PRODUCT_LIBHOME=
MAKEFILE=proc.mk
MAKEFILE=Makefile
PROCPLSFLAGS= sqlcheck=full userid=$(USERID) dbms=v6_char
PROCPPFLAGS= code=cpp $(CCPSYSINCLUDE)
USERID=scott/tiger
INCLUDE=$(I_SYM). $(PRECOMPPUBLIC) -I/usr/local/include/g++
SAMPLES=test_customer insert_cust_data select_customer CPPSAMPLES=cppdemo1 cppdemo2 cppdemo3
# Rule to compile any program (specify EXE= and OBJS= on command line)
build: $(OBJS)
$(CC) -o $(EXE) $(OBJS) -L$(LIBHOME) $(PROLDLIBS)
cppbuild:
$(PROC) $(PROCPPFLAGS) iname=$(EXE) $(CCP) -c $(INCLUDE) $(EXE).c $(CCP) -o $(EXE) $(OBJS) -L$(LIBHOME) $(PROLDLIBS)
samples: $(SAMPLES)
cppsamples: $(CPPSAMPLES)
$(SAMPLES):
$(MAKE) -f $(MAKEFILE) build OBJS=$_at_.o EXE=$@
$(CPPSAMPLES):
$(MAKE) -f $(MAKEFILE) cppbuild OBJS=$_at_.o EXE=$@
sample5:
_at_echo 'sample5 is a user-exit demo; use a forms makefile to build it.'
.pc.c:
$(PROC) $(PROCFLAGS) iname=$*.pc
.pc.o:
$(PROC) $(PROCFLAGS) iname=$*.pc $(CC) $(CFLAGS) -c $*.c .c.o: $(CC) $(CFLAGS) -c $*.c sample6.o: sample6.pc $(PROC) dbms=v6_char iname=$*.pc $(CC) $(CFLAGS) $(PRECOMPPUBLIC) -c $*.c sample9.o: sample9.pc calldemo-sql $(PROC) $(PROCPLSFLAGS) iname=$*.pc $(CC) $(CFLAGS) $(PRECOMPPUBLIC) -c $*.c cv_demo.o: cv_demo.pc cv_demo-sql $(PROC) $(PROCPLSFLAGS) iname=$*.pc $(CC) $(CFLAGS) $(PRECOMPPUBLIC) -c $*.c sample11.o: sample11.pc sample11-sql $(PROC) $(PROCPLSFLAGS) iname=$*.pc dbms=v6 $(CC) $(CFLAGS) $(PRECOMPPUBLIC) -c $*.c calldemo-sql: sqlplus scott/tiger _at_../sql/calldemo
Then, a sample Pro*C program would look like this :
/* Sample Pro*C program */
#include <stdio.h>
void Login();
void Query();
void Err();
void Addspc();
EXEC SQL BEGIN DECLARE SECTION; <your variable declarations>
EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE sqlca;
void Login()
{
strcpy(username.arr, "<your last name>/<your password>"); /* append _at_hq to your original password */
username.len = strlen(username.arr);
EXEC SQL WHENEVER SQLERROR GOTO printerror;
EXEC SQL CONNECT :username;
/* Logon Oracle */ printf("\n Connected to ORACLE as user: %s \n", username.arr); return;
printerror:
Err();
} /* end of Login() procedure */
void Query()
{
EXEC SQL WHENEVER SQLERROR GOTO printerror;
<your program>
printerror:
Err();
} /* end of Query() procedure */
void Err()
{
printf("\n\n% .70s \n", sqlca.sqlerrm.sqlerrmc); /*Error message */ EXEC SQL WHENEVER SQLERROR CONTINUE; /* Avoid infinite loop*/
EXEC SQL ROLLBACK WORK RELEASE; /* Disconnect from Oracle */ exit(1);
} /* end of Err() procedure */
void main()
{
Login(); Query();
} Received on Mon Dec 10 2001 - 12:58:23 CET