Re: Setting database at runtime with 4GL
Posted in 1995
>From: akent@cix.compulink.co.uk ("Andy Kent") >Date: Sat, 28 Jan 1995 10:35:47 GMT >X-Informix-List-Id: <news.11155> > >>> Date: Fri, 20 Jan 1995 17:34:29 +0000 >>> From: simonb@misslink.demon.co.uk (Simon Bunce) >>> >>> Is it possible to choose which database to use from within a 4gl >>> program? >> >> A DATABASE statement at the top of a 4GL source is a declarative >> statement. A DATABASE statement *after* a MAIN or FUNCTION statement is >> an executable statement > >Not quite. The declarative one *also* gets executed. So as I understand >it a database with the same name as the declarative one also has to exist >on the runtime system, even if it's completely empty on that box. On the >development system it would have to contain as a minimum any tables or >columns referenced by DEFINE..LIKE. The declarative form of the DATABASE statement generates an executable DATABASE statement as the first executable statement in the MAIN program, and nowhere else. This means that if the source file containing MAIN does not include a declarative DATABASE statement, no database is opened automatically when the program is started. I also see extensive evidence in code submitted in bug reports that people think that the declarative DATABASE statement must be used -- not so, not at all. There is, in general, no compulsion to use a database with a 4GL program -- the exception is a report which is sorted internally; that needs a database for a temporary table. And the only reasons for using the declarative DATABASE statement are (a) to pre-select the database when the program is started and (b) to allow the use of DEFINE...LIKE. If your code doesn't contain MAIN and doesn't use DEFINE...LIKE then you don't need the declarative DATABASE statement. Your program will compile quicker without it, as the compiler won't open the database. Going back to the original question, if your code needs to choose which database is operational at run-time then, I would suggest, the file containing MAIN should be compiled without any declarative DATABASE statement. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>