Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle C OCI Question

Status
Not open for further replies.

cDevX99

Programmer
Aug 29, 2001
39
US
Following this question is a watered down version of the program that I am trying to write. I get an invalid sql statement error during the parse portion, the statement is valid, is there some other bit of voodoo, that I do not know that is causing this. If anyone can shed some light, I will be very grateful. tks .... here it is. It works when I use the commented out version of the statement ( insert into.... ) but craps out when I use the other ( exec IMPLOAD... )


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <oratypes.h>
#include <ocidfn.h>
#ifdef __STDC__
#include <ociapr.h>
#else
#include <ocikpr.h>
#endif
#include <ocidem.h>

/* Define an LDA, a HDA, and a cursor. */
Lda_Def lda;
ub4 hda[HDA_SIZE/sizeof(ub4)];
Cda_Def cda1;

text *szUID = &quot;UPLOAD&quot; ;
text *szPWD = &quot;UPLOAD&quot; ;
text *szSID = &quot;REARDON&quot; ;
text *szConString = &quot;UPLOAD/UPLOAD@REARDON&quot; ;

text *szQuery = (text *) &quot;exec IMPLOAD( 'Col Number One', 2, 3, 'four')&quot; ;
//text *szQuery = (text *) &quot;INSERT INTO IMPTEST VALUES ( 'Col Number One', 2, 3, 'four')&quot; ;

void err_report(cursor)
Cda_Def *cursor;
{
sword n;
text msg[512];

printf(&quot;\n-- ORACLE error--\n&quot;);
printf(&quot;\n&quot;);
n = oerhms(&lda, cursor->rc, msg, (sword) sizeof msg);
fprintf(stderr, &quot;%s\n&quot;, msg);
if (cursor->fc > 0)
fprintf(stderr, &quot;Processing OCI function %s\n\n&quot;,
oci_func_tab[cursor->fc]);
}


/*
* Exit program with an exit code.
*/
void do_exit(exit_code)
sword exit_code;
{
sword error = 0;

if (oclose(&cda1))
{
fprintf(stderr, &quot;Error closing cursor 1.\n&quot;);
error++;
}
if (ologof(&lda))
{
fprintf(stderr, &quot;Error on disconnect.\n&quot;);
error++;
}
if (error == 0 && exit_code == EXIT_SUCCESS)
printf (&quot;\nG'day\n&quot;);

exit(exit_code);
}


void myfflush()
{
eb1 buf[50];

fgets((char *) buf, 50, stdin);
}


int main( int argc, char * argv[] )
{

/* Connect to the DB server */

printf(&quot;Conecting...\n\n&quot;);

if (olog(&lda, (ub1 *)hda, szConString, -1, szPWD, -1,
(text *) 0, -1, (ub4)OCI_LM_DEF))
{
err_report(&lda);
exit(EXIT_FAILURE);
}

printf(&quot;Connected to ORACLE as %s\n\n&quot;, szConString);

/* Open a cursor */

if (oopen(&cda1, &lda, (text *) 0, -1, -1, (text *) 0, -1))
{
err_report(&cda1);
do_exit(EXIT_FAILURE);
}

printf(&quot;Cursor is open\n\n&quot;);

/* Parse the procedure exec statement */

if( oparse(&cda1, szQuery, -1, 0, 2 ) )
{
err_report(&cda1);
do_exit(EXIT_FAILURE);
}

printf(&quot;Query parsed\n\n&quot;);

/* Execute the statement */

if (oexec(&cda1) && cda1.rc != 1)
{
err_report(&cda1);
do_exit(EXIT_FAILURE);
}

printf(&quot;Query executed\n\n&quot;);

/* Close the cursor */

if (oclose(&cda1))
{
err_report(&cda1);
do_exit(EXIT_FAILURE);
}

printf(&quot;Cursor closed\n\n&quot;);

/* Close the db connection */

if (ologof(&lda))
{
err_report(&cda1);
do_exit(EXIT_FAILURE);
}

printf(&quot;Connection closed\n\n&quot;);

return 0 ;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top