Re: Dynamic SQL in ProC

From: Vandra Huber <vandra_at_u.washington.edu>
Date: 1996/07/25
Message-ID: <31F84091.305A_at_u.washington.edu>#1/1


Ravi_Kasarla_at_wb.xerox.com wrote:
>
> In article <4t23s6$802_at_ninurta.fer.uni-lj.si>, <pmarko_at_news.fer.uni-lj.si> writes:
> > Path: rocksanne!parc!news.Stanford.EDU!agate!howland.reston.ans.net!newsfeed.internetmci.com!inXS.uu.net!01-newsfeed.univie.ac.at!cmir.arnes.si!news.fer.uni-
> > From: pmarko_at_news.fer.uni-lj.si (marko plevel)
> > Newsgroups: comp.databases.oracle
> > Subject: Dynamic SQL in ProC
> > Date: 23 Jul 1996 08:52:22 GMT
> > Organization: Faculty of Electrical and Computer Engeneering, Ljubljana, Slovenia
> > Lines: 17
> > Message-ID: <4t23s6$802_at_ninurta.fer.uni-lj.si>
> > NNTP-Posting-Host: ixtas.fri.uni-lj.si
> > X-Newsreader: TIN [version 1.2 PL2]
> >
> > Hi,
> >
> > I need help about querying Oracle with dynamic SQL statements.
> >
> > The "select" clause is known at run-time, and I have to handle it
> > dynamicly ( stuff like number of columns, names of columns, gettting data
> > for a specific column,...). I plan to make a C++ class, that would
> > handle that.
> >
> > Can this be done by ProC ? How ?
> >
> > Maybe you could e_mail me an example source ?
> >
> > Please e_mail me directly to: marko.plevel_at_rd.iskraemeco.si
> >
> > Thanks
> > Marko
> >
> I had a similar problem. I wrote a C program, which would create another
> pro-c program. By this you can have dynamic SQL.
>
> Ravi S. Kasarla
> Ravi_Kasarla_at_wb.xerox.com

Assuming that you have the ProC, etc

I believe the only thing you need do is use the PREPARE statement.

Ex.

len = sprintf(buffer, "SELECT ... ")
len = sprintf(buffer+len, "fieldA = '%s' " ,strVar1) if somecondition
{

        len = sprintf(buffer+len, " and fieldB in (%s) ", inStr) }
len = sprintf(buffer+len, "and fieldC = :someVar ");

// convert buffer to varchar buffer -> myVarcharBuffer

EXEC SQL PREPARE mySQLCommand FROM :myVarcharBuffer;

EXEC SQL mySQLCommand USING someVariable;

etc....

Mike Krolewski mkrolews_at_upw.com Received on Thu Jul 25 1996 - 00:00:00 CEST

Original text of this message