Re: 4GL - Database Names
Posted in 1996
David Williams (djw@smooth1.demon.co.uk) wrote: : In article <530m37$qud@bamboo.verinet.com>, Cathy Kipp : <ckipp@bamboo.verinet.com> writes : > : > These statements are useful for being able to use the like : > syntax when defining variables. These statements are really : > only referred to at compile time, and really only require an : > empty database with the correct database name and table and : > column definitions. At any rate, you should be able to leave : > these the way they are. If you want to be able to compile from : > live (or somewhere else), just make sure an empty database : > (at least) exists there. : > : Except when in a 4GL module which contains a MAIN function. : In that case the executable will connect to the database referenced : before your code BEFORE THE FIRST LINE OF CODE IN MAIN IS EXECUTED. I know some (if not all) of this has been said before, but forgive me if I get repetitive for the sake of clarity: - In 4GL, if you have variables defined LIKE table.anything, you need a DATABASE statement before the code, e.g. DATABASE stores5 MAIN DEFINE rec RECORD LIKE customer.* ... END MAIN or DATABASE stores5 FUNCTION foo DEFINE rec RECORD LIKE customer.* ... END FUNCTION - If you use the first example (that is, put a DATABASE statement in your main 4GL module before MAIN), then it will try to open the database stores5 as soon as you execute the program. This will require you to have a stores5 database on your production system, even if the first line of code in your MAIN changes the database to something else with a statement like: DATABASE dbvariable Yes, the database name can be a variable, so you can pass it in, or read it from an environment variable. But not if it's already been hard-coded by your programmers. Unfortunately, there is no way to override a hard-coded name. - When you use the second example (that is, you have a separate 4gl module which contains functions, but no MAIN, and the DATABASE statement before the first function), it does not try to open the database stores5 when it executes. THUS The best workaround to this problem that I've found: - Use a main 4GL module that contains no definitions LIKE tablename. - Use other modules to define variables LIKE tablename. e.g. foomain.4gl ----------- MAIN CALL main_func END MAIN mainfunc.4gl ------------ DATABASE stores5 FUNCTION main_func DEFINE rec RECORD LIKE customer.* ... END FUNCTION In this example, a stores5 database is required at compile time, but not at execution time. You should also be able to include a GLOBALS statement in mainfunc.4gl which uses variables defined LIKE table.column, without including the GLOBALS in the main module. (My 4GL is a bit rusty, so the syntax might be a little off, but you get the idea.) June ---- June Tong Informix Software ---- ---- Senior Consultant (415) 926-6140 ---- ---- International Support junet@informix.com ---- ---- Location-du-jour: Menlo Park ---- * * Standard disclaimers apply * - Please do not send me requests/questions by mail. When I have the knowledge - and time permits, I try to answer questions on comp.databases.informix, but - travel schedule, time, and volume make responding to personal requests - difficult and often slow. Please call your local Informix Technical Support - organization for assistance with technical issues.