如果存在表,如何有条件地编译? [英] How to conditionally compile in case of an existing table?
问题描述
我正在使用 Progress-4GL、11.6 版、appBuilder 和过程编辑器.
I'm working with Progress-4GL, release 11.6, appBuilder and procedure editor.
我刚刚创建了一个名为table_X"的表,我在代码中使用它,例如:
I have just created a table, called "table_X", and I'm using it inside the code, something like:
FIND table_X ...
不过,我的程序是通用的,但是表是定制的(有些客户有这个表,有些没有).
However, my program is general, but the table is custom-based (some customers have this table, but some don't).
所以,我想添加一个预处理器",例如:
So, I'd like to add a "preprocessor", something like:
&IFDEF table_X
&THEN FIND table_X ...
&END
其中 &IFDEF
的意思是:只有在 DB 中存在该表时才编译这段代码".
Where the &IFDEF
means: "Only compile this piece of code if that table exists in DB".
这在 Progress-4GL 版本 11.6 中是否可行?
Is this possible in Progress-4GL, release 11.6?
提前致谢
推荐答案
如果您使用静态查询,您将需要在编译时使用的环境包含中添加定义.在您的标准目录中:
If you are using static queries you will need to add a define in an environment include used when compiling. In your standard directory:
// env.i
// nothing (yet)
在您的客户目录中:
// env.i
&global define table_x
然后你可以在编译时使用你的 propath
,如果你的 propath 以客户目录开始,那么定义就会被选中,否则 env.i 是从你的标准目录中获取的,table_x 是未定义:
Which you can then use at compile time with your propath
, if your propath starts with the customer directory then the definition is picked up, otherwise env.i is taken from your standard directory and table_x is not defined:
{ env.i }
&if defined( table_x ) &then
find table_x no-lock.
&endif
如果你可以用动态使用替换这个表的静态使用,那么你不需要定义,你可以:
If you can replace static use of this table with dynamic use, then you do not need the definitions and you can:
def var hb as handle no-undo.
create buffer hb for table "table_x" no-error.
if valid-handle( hb ) then do:
hb:find-unique( no-lock ).
end.
虽然这可能很有吸引力,但它确实意味着您给所有客户带来了可能不相关的运行时检查的负担.
While this could be attractive, it does mean that you are burdening all your customers with potentially irrelevant run-time checks.
这篇关于如果存在表,如何有条件地编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!