embedded SQL question?

From: Rui Hua Sarah YANG <ruihua_at_cat.cs.mu.OZ.AU>
Date: 1996/12/10
Message-ID: <58j4l2$lu6_at_mulga.cs.mu.OZ.AU>#1/1


Hello,

[Quoted] [Quoted]    Can anyone tell me whether I can use a variable to replace a table name in a    embedded SQL program(The purpose is to make the program generic)? If you    know the answer, would you please tell me how to do it? Thanks!    my email address is : ruihua_at_cs.mu.oz.au

   We assume there is a table student in a database myDatabase.

   The code is:

#include <stdio.h>

EXEC SQL BEGIN DECLARE SECTION;

     char name1[50];
     char address1[80];
     char relName[20];        /*Is it correct to declare table name here?*/ 
EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; main()
{
     strcpy(relName, "student"); /* copy the table student to relName*/
     strcpy(name1, "duncan");
     strcpy(address1, "Melbourne");

     EXEC SQL CONNECT myDatabase;

     EXEC SQL INSERT INTO
	 relName(name, address) /* can I use relName to replace table student?*/
	 ^^^^^^^
     VALUES(:name1, :address1);

     EXEC SQL DECLARE pt CURSOR FOR
	  SELECT name, address
	  FROM relName         /* can I use relName to replace table student?*/
	       ^^^^^^^
	  WHERE name='duncan';

     ...................

     EXEC SQL DISCONNECT;
     exit(0);

} Received on Tue Dec 10 1996 - 00:00:00 CET

Original text of this message