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: How do you declare function parameters as host variables in Pro*C/C++?

Re: How do you declare function parameters as host variables in Pro*C/C++?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 01 Sep 1999 13:51:54 GMT
Message-ID: <37cf2f62.98245860@newshost.us.oracle.com>


A copy of this was sent to emoe_at_mmcable.com (Erik Moe) (if that email address didn't require changing) On Wed, 01 Sep 1999 00:18:45 GMT, you wrote:

>Hello,
>
>I haven't done embedded SQL in several years and then it was with
>Informix. I want to use some function parameters as host variables,
>something like this:
>
>func(int foo, char* bar)
>{
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
>}
>
>How do I declare foo and bar as host variables? I don't want to want
>to you K&R syntax:
>
>func(foo, bar)
>EXEC SQL BEGIN DECLARE SECTION
>int foo;
>char* bar;
>EXEC SQL END DECLARE SECTION
>{
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
>}
>
>Is this legal?
>
>func(
>EXEC SQL BEGIN DECLARE SECTION
>int foo, char* bar
>EXEC SQL END DECLARE SECTION
>)
>{
> EXEC SQL INSERT INTO FOOBAR (FOO, BAR) VALUES (:foo, :bar);
>}
>
>Erik Moe

It could look like this:

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

static char * USERID = "tkyte/tkyte";

#define SQLCA_INIT
EXEC SQL INCLUDE sqlca;

static void sqlerror_hard()
{

    EXEC SQL WHENEVER SQLERROR CONTINUE;     printf("\nORACLE error detected:");     printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);

    EXEC SQL ROLLBACK WORK RELEASE;
    exit(1);
}

static void process( int x, char * string ) {

    EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();     exec sql insert into t values ( :x, :string );     exec sql commit;
}

main( argc, argv )
int argc;
char * argv[];
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR oracleid[50];
EXEC SQL END DECLARE SECTION;     strcpy( oracleid.arr, USERID );
    oracleid.len = strlen( oracleid.arr );     EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();     EXEC SQL CONNECT :oracleid;
    printf("\nConnected to ORACLE as user: %s\n\n", oracleid.arr);

    process( 1, "Hello World" );

    /* Disconnect from ORACLE. */
    EXEC SQL COMMIT WORK RELEASE;
    exit(0);
}

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Sep 01 1999 - 08:51:54 CDT

Original text of this message

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