Re: Pro*C query problem

From: Mahesh Vallampati <m0v5533_at_tam2000.tamu.edu>
Date: 1995/05/27
Message-ID: <3q7pir$m63_at_news.tamu.edu>#1/1


In article <3q59rl$9qd_at_mercury.kingston.ac.uk>, Nick Bailey <ee_d304_at_dcs.king.ac.uk> wrote:
> I am having problems trying to get a query in my Pro*C program to acheive
> what I want it to. The query is as follows -
> EXEC SQL SELECT CNAME, CCLENGTH
> INTO cname, clength
> FROM COURSES WHERE CNAME=:name;
> where name is a string whose contents are variable on each invocation of the
> query.
> I have seen in the Pro*C users guide this being done, but only where name (or equivalent) is an integer...I need it to be a string. The above code doesn't produce any errors, but when I set name to a value that I know is in the table, the call still returns nothing for the other variables....am I doing this right???? Is it possible to use strings in the WHERE declaration??? Can anyone help??
>Please mail me direct, I would appreciate any feedback on this, as the main reason for me using Oracle is that I can use it to search for data, and just have my program manipulate it.
>Many thanks in advance to any replies,
>Cheers,
>Nick.
Hie Nick,
First I see that you have the same column name and the same variable name: CNAME which is the column and cname which is the variable name. Avoid doing that. Steven Bobrowski Book On Oracle "Mastering Oracle 7" suggests not to do that.
Second Have you declared cname,name as varchar? If you declare as char in Oracle 7.0 it wont work.
Third The exec sql should look like

   EXEC SQL SELECT CNAME, CCLENGTH
--> Not here the colon and different variable name:INTO :cname1111,:clength1111

            FROM COURSES WHERE CNAME=:name; Fourth:
name should also be declared as varchar in the EXEC SQL declare section. name should be treated as follows: I am assuming that somebody is inputting the "name":
Here is a sample piece of code:
printf("Enter Employee Name:--> ")
scanf("%s",name.arr);
name.len=strlen(name.arr);
Now you can use the above sql statement.

   EXEC SQL SELECT CNAME, CCLENGTH

	INTO :cname1111,:clength1111
            FROM COURSES WHERE CNAME=:name;

Hope This helps.
If u are still having problems mail me the code and maybe I can help fix it.

PS: It must be noted that varchar is actually a structure with arr part used to store the characters and the len part used to store the length of the character array.
struct varchar
{
arr *char;
len int;
}
Thanks
Mahesh Vallampati
PH : 409 846 3794 (H) | 409 862 1070 (O) e-mail address : vallampa_at_eesun1.tamu.edu

WWW 		: http://tam2000.tamu.edu/~m0v5533/
Lab 		: 409 847 8609 

// In the Beginning there was Codd .... Received on Sat May 27 1995 - 00:00:00 CEST

Original text of this message