Re: Accessing different databases using Informix SE 4.10
Posted in 1996
* I am using Informix SE 4.10 on SCO UNIX. * I am writing code which will be used on different databases. * All necessary tables are present in both databases. * There are 10 programs which have been written as separate executables- * * e.g. * program 1 * * main * call <initialisation function> * call <main function> * end main * * function <main function> * define like <tablename.colname> * program code * end function * * The initialisation function is a separate module which detects which * database is present by doing- * * whenever error continue * database x * if status<0 then * database y * end if * * I have several problems * 1. The main program won't compile using this code as the define like * does not find the table in the database. * 2. Putting database x before the main will compile the main program, but * when you switch databases and run, comes with error- * * No system permission or database not found * * Implying that the it can't find the directory for database x. A simple solution. To accomplish what you want and still have the flexibility of using the LIKE definitions, you need to put the MAIN - END MAIN program block in it's own module. All the other modules can then have the DATABASE xxxx statement at the top of the module and not cause problems at run-time. Only the MAIN - END MAIN function uses the DATABASE statement IF it resides in the same module. Here is an example of what you should do, three modules are listed: {----------------------------------------------------------------------------- } # Module MAIN.4GL MAIN CALL open_the_database() CALL initialize_function() CALL main_function() END MAIN {----------------------------------------------------------------------------- } # Module GLOBALS.4GL # you can have global vars defined here, or just use this to state the database name used to compile against. That way, you will only need to change the name in one place if you need to compile against another database name. DATABASE your_database GLOBALS END GLOBALS {----------------------------------------------------------------------------- } # Module - MODULE1.4GL (and 2,3,n...) GLOBALS "globals.4gl" FUNCTION open_the_database() DEFINE db_name CHAR(20) -- Either have the database name as a parameter, or an environment var -- I select environment var. LET db_name = fgl_getenv("DBNAME") IF NOT LENGTH(db_name) THEN LET db_name = "default_name" -- Or show error and exit END IF DATABASE db_name -- check status and deal with it END FUNCTION FUNCTION initialize_function() -- Do stuff here ... END FUNCTION FUNCTION main_function() -- Do stuff here ... END FUNCTION HTH, ----------------------------------------------------------------------------- Robert Minter Data Systems Support Senior Software Engineer A Client Technologies Company E-Mail: rob@dssmktg.com Tel: 714.771.0454 Fax: 714.771.3028 #include <std_disclaimer.h> http://www.dssny.com