Re: *********** Pro*C Question *********
Date: Tue, 21 Jun 1994 13:42:27 GMT
Message-ID: <mmaroldaCrr22r.KpA_at_netcom.com>
In article <rayo.190.0_at_ontko.com>, Ray Ontko <rayo_at_ontko.com> wrote:
>In article <2u0ff1$sij_at_gaia.cc.gatech.edu> badri_at_cc.gatech.edu (badri) writes:
>>
>> I am facing a baffling Pro*C behavior. I do the following
>>in Pro*C.
>>
>> Program 1:
>> char my_string[16];
>> VARCHAR sqlcmd[256];
>>
>> sprintf (sqlcmd.arr, "insert into my_table values
>> ('%s')", my_string);
>> sqlcmd.len=strlen(sqlcmd.arr);
>>
>> Program 2:
>> char my_string[16];
>>
>> EXEC SQL DECLARE C1 CURSOR FOR
>> SELECT * FROM my_table
>> WHERE only_attribute = my_string;
>>
>> Sure enough the query in program 2 returns nothing! When
>>I print my_string on both the programs, they give the identical
>>value.
>> Where is the problem?
>
>Three things:
>
>1) I assume that you mean for "my_string" in the second program to be a host
> variable, in which case it should be preceded with a colon, i.e.
> ":my_string".
>
>2) In program 1, I assume that my_string is null terminated. That is,
> it contains up to 15 characters and is followed by a null character.
> In program 2, your usage of my_string as char [16] implies that it is a
> fixed length field containing exactly 16 characters.
>
>3) Consider EXEC SQL INSERT INTO my_table VALUES ( :s ) ;
>
>Ray
>
You didn't mention what version of Pro*C you have but in 1.5 (don't know about 1.4) you can use the mode=ansi flag and oracle will be much friendlier when using char variables.
Mike Marolda
-- Bristol Database Resources Inc. - Providing Mosaic & Oracle Solutions Allen, Texas mmarolda_at_netcom.comReceived on Tue Jun 21 1994 - 15:42:27 CEST