Testing for no input with CONSTRUCT statement
Posted in 1994
Topics: SQL Development & Query Writing
I had a situation where I wanted to prevent the users of a query screen from simply hitting the escape key and selecting every row in a table. My problem was that we are using the CONSTRUCT statement to generate the WHERE clause of the SELECT statement. After many gyrations, I finally discovered that in such a situation, the CONSTRUCT statement builds its where clause simply as "1=1", which of course, simply evaluates to TRUE. Unfortunately, it buries this in a string surrounded by newlines and spaces. I built the following function to check for these situations, and I thought it might be helpful to others, so here it is. # Here's an example of how the function can be called function foo() define where_part char(2000) define allrows smallint construct by name where_part on screen-rec.* call test_select_all(where_part) returning allrows if (allrows = TRUE) then error "You must enter some search criteria." return FALSE end if . . end function ############################################################################## # Routine : test_select_all # # Purpose : Test CONSTRUCTed variable to see if all table records # are going to be selected # # Arguments : where_part # # Returns : TRUE if all records will be selected, otherwise FALSE ############################################################################## function test_select_all(where_part) define where_part char(2000) # These should be as large as the define test_str char(2000) # largest character variable that # The CONSTRUCT statement builds into define x smallint define y smallint let y = 1 for x = 1 to 2000 if (where_part[x] >= "!" and where_part[x] <= "~") then # strip out all non-printable and space characters let test_str[y] = where_part[x] let y = y + 1 end if end for if (test_str = "1=1") then return TRUE else return FALSE end if end function --- =============================================================================== Joe Hartley | jh@cadre.com - Whenever you find that you are on the Cadre Technologies | side of the majority, it is time to reform. - M. Twain 222 Richmond St. | -------------------------------------------------------- Providence, RI 02903 | Overman 1st Class - the Kilgore Trout Memorial Clench (401) 351-5950 x266 | of the Church of the SubGenius ===============================================================================