Re: How do you choose database at RUNTIME in r4gl?
Posted in 1994
mlester@lonestar.utsa.edu (Micheal W. Lester) writes: >SCENERIO: >We have two systems, production and development. >ISTAR is installed on both systems so we can perform remote queries. >We have scores of 4gl reports that share a common 4gl GLOBAL header file. >When we wish to access data that is on production, we change the statement > database lotsadata >to > database lotsadata@production >and recompile the program. When we run the program on development, we will >get production data. >... >Is there a way that we can specify the database name at run time, instead >of compile time? Maybe make r4gl look at the contents of a UNIX >environmental variable, DBNAME? This is untested, because I don't have access to a remote database site right now, but this should work: # At the top of the module, name the database for use at compile time. # this should also be in the GLOBALS module DATABASE dbname DEFINE modular ... LIKE ... MAIN DEFINE dbname CHAR(18) ... LET dbname = fgl_getenv("DBNAME") # this is the database that will be used to pull data DATABASE dbname ... If this doesn't work, you may have to CLOSE DATABASE before the call. Or, you may have to PREPARE and EXECUTE a string with the DATABASE explanation. But I think it will work as above. The long explanation is: You need a database at compile time if defining variables LIKE a database column, and since this commonly needs to be above a function (for modular definitions), the database name can't be a variable. BUT, using a DATABASE statement within a FUNCTION *does* allow variable usage, according to the manual. Let us know if any of this fails. ======================================================================= Dennis J. Pimple dennisp@informix.com Opinions expressed Senior Consultant -------------------- are mine, and do not Informix Software Inc Voice: 303-850-0210 necessarily reflect Denver Colorado USA Fax: 303-779-4025 those of my employer.