Re: Syntax error in Pro*C

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 1996/07/31
Message-ID: <31ffd3c9.28151720_at_dcsun4>#1/1


On 30 Jul 1996 21:15:00 -0400, ilg_at_elan.cc.bellcore.com (guthrie,ian) wrote:

>
>I am using Pro*C release 2.1.2.0.0, Oracle version 7.2.2 on Solaris 2.4.
>I have the following code segment:
>
>
> varchar rback[4];
> char *p;
>
> if (p=getenv("RBACK")) {
> strncpy((char *)rback.arr, p, 3);
> rback.arr[4] = '\0';

                         ^^^^^ subtle memory overwrite here.... rback.arr[3] is
                               max you can address

> rback.len = strlen((char *) rback.arr);
>
> EXEC SQL SET TRANSACTION USE ROLLBACK SEGMENT :rback;
>
> if (sqlca.sqlcode != 0) {
> printf("cannot set rollback segment %s\n", rback.arr);
> sql_error();
> }
>
> }
> else
> printf("Environment variable RBACK, not defined.\n");
>
>
>I get the following compile error:
>
> Syntax error at line 1417, column 49, file srf.pc:
> EXEC SQL SET TRANSACTION USE ROLLBACK SEGMENT :rback;
> ..............................................................1
> (1) PCC-S-02201, Encountered the symbol ":" when expecting one
> of the following:
>
> an identifier,
>
>It does not like the :rback. If I replace it with the actual value, (e.g.,
>r01), it compiles. What's wrong with the syntax?

Bind variables can't be used where an IDENTIFIER is expected and only an identifier may be present. For example:

    select * from :table_name

won't work cause only identifiers may be in the from list (not bind variables). On the other hand

    select :value from T

will work since constants/functions/expressions/identifiers/etc may appear in the select list.

What you want to do is:

...
varchar stmt[1024];

	sprintf( stmt.arr, "set transaction use rollback segment %s", 
                            getenv( "RBACK" ) );
	stmt.len = strlen( stmt.arr );

	EXEC SQL EXECUTE IMMEDIATE :stmt;

...

>
>Thanks,
>
>Ian
>--
>
>

Thomas Kyte
Oracle Government
tkyte_at_us.oracle.com                          

http://govt.us.oracle.com -- Check out our web site! Brand new, uses Oracle Web Server and Database


statements and opinions are mine and do not necessarily reflect the opinions of Oracle Corporation Received on Wed Jul 31 1996 - 00:00:00 CEST

Original text of this message