Re: Embedded SQL
Posted in 1995
> Is there a way to use variables in embedded sql commands in C/UNIX
> environment? This is what I want to do
> select :var_column_name from :var_table_name;
> I know how to host variables but wanted to know if host variables
> canbe used for the table and column names.
> Thanks in advance
There are many ways. Someone else will probably tell you how to use
the PREPARE statement from within I-4GL.
If you are using Informix ESQL/C then I'm sure there is a way there,
too, but I don't know it offhand. (sorry)
One way you probably won't hear about is using only unix shells. We
have a couple of instances where we build a command string using
unix scripts (including env variables) and pipe them to isql. It
works like this:
$ TABLE_NAME="table";export TABLE_NAME
#!/bin/sh
echo "type in the column name:"
read column_name
echo "select $column_name from $TABLE_NAME where..." | isql dbname
You could also do something like:
$ run_shell_to_build_sql_statement.sh
$ cat sql_statement.sql | isql dbname
One caveat is that if you check the status of the isql command it will
return whether the command "isql" *itself* worked, and not whether it
had an error getting rows, or with the database, or whatever.
This method is pretty simple, but also pretty simplistic. After a
short while it becomes worth the effort to use 4GL or ESQL/C.
Enjoy,
__________________________________________________________________
| Clem Akins Standard Disclaimers Apply |
|Reynolds Metals Co, Alloys Plant "Climb High, Cave Deep!" |
| Muscle Shoals, Alabama USA cwakins@leia.alloys.rmc.com |
|________________________________________________________________|