Re: *********** Pro*C Question *********

From: Ray Ontko <rayo_at_ontko.com>
Date: 20 Jun 1994 13:25:35 GMT
Message-ID: <rayo.190.0_at_ontko.com>


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



Ray Ontko rayo_at_ontko.com "Ask me about Database Illustrator(tm)" Ray Ontko & Co info_at_ontko.com ftp cscns.com:/pub/ontko Received on Mon Jun 20 1994 - 15:25:35 CEST

Original text of this message