Re: Embedded SQL
Posted in 1995
To add my 2 cents worth (as you Yanks say :->), I don't have access to 4GL or ESQL (nor the knowledge to use them if I did!), and it is amazing what you can do just with UNIX shell scripts when that's all you have. Clem's example below shows a very basic illustration of their use, but you are only really limited by what you know about UNIX. My usual tactic when faced with a new problem is to decide what UNIX functionality I'm going to need, guess what the command might be called, and then type 'man xxx' at the UNIX prompt. It generally returns 'No man page for xxx', but sometimes you get lucky! All routinely used ACE reports on my databases are accessed via shell scripts, using sacego. The ACE report outputs to a file, then the shell script displays the file and asks the user whether they want a printout (using $DBPRINT to send it to their local printer) and/or whether they want to save the file in their home directory. I also have a couple of shell scripts that get really snazzy - running an ACE report using user-supplied variables, outputting the result to a file, and then using the contents of this file as variables for a succession of other ACE reports. So, if you're just using ISQL, and reading all the 4GL, New Era and other stuff on this list makes you feel inferior, don't despair, we can do just as much as they can (well, nearly!). Cheers, Richard. (no .sig this time!) } From ilist@rmy.emory.edu Thu Oct 19 18:24:12 1995 } Date: Thu, 19 Oct 1995 09:52:12 -0500 } From: Clem Akins <cwakins@leia.alloys.rmc.com> } To: informix-list@rmy.emory.edu } Subject: Re: Embedded SQL } X-Informix-List-To: rt10hp@csl.gov.uk } X-Informix-List-Id: <list.7712> } } > 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 | } |________________________________________________________________| }