Re: Wildcards for 4GL pgm
Posted in 1996
> cherylk@prod1.jcdc.doleta.gov (Cheryl Kendricks) writes: > I'm doing this for one of my Pgm/Analyst: > How do you get around wildcard characters in a form using query by example > for security measures? > > Software is 4GL 4.X, engine is 5.02 on AIX 3.2. > I think they want to know a way to restrict the user from entering wild > cards on a 4GL form. Any help you can give in this will be greatly > appreciated!!! We haven't ever done exactly this, but are manipulating the results of a construct statement in 4GL extensively for other purposes. What you basically have to do is to analyze the where clause generated by the construct statement and change it before it's used in the select cursor. For your purposes you simply have to find any existence of the "matches" keyword and either remove it or replace it with something else. Something along these lines will do that: construct p_where ... # p_where may contain something like: colname matches "...*" # one or more times. Find it and do something about it: while true let p_matchpos = string_find(p_where, ' matches "') if p_matchpos = 0 then exit while else # Do something about the matches: let p_where[p_matchpos, p_matchpos + 7] = " =" # To replace it with an equalsign makes the p_where syntactically ok, # but no data will be returned (unless you have a column that actually # contains exactly what the user typed, including the *). # Many other alternatives may be thought about including simply giving # an error message to the user that an * isn't allowed in which case # you obviously doesn't need this while loop, but simply a call to # the string_find function. end if end while function string_find(p_string, p_find) define p_string char(512), p_find char(64), p_len, p_1 smallint let p_len = length(p_string) let p_findlen = length(p_find) - 1 for p_1 = 1 to p_len - p_findlen if p_string[p_1, p_1 + p_findlen] = p_find then return p_1 end if end for return 0 end function Some people will dislike me for having written the string_find-function in 4gl. They would want it in C. But in this case (and in most other cases) there is no speed problem, and we think more of the maintenance problems for 4gl programmers with C functions. If that's not an issue do indeed write it in C. PS: I haven't compiled this stuff. Take it for what it is - a few minutes of typing. My variables may easily be 1 or 2 off. Nils.Myklebust@ccmail.telemax.no NM Data AS, Postbox 9090, Gronland, 0133 Oslo, Norway My opinions are those of my company