Function order_select
This function creates the SQL statement for the query and the corresponding cursor to
retrieve the rows from the orders
table. It calls the function
fetch_order
.
Function
order_select
(orders.4gl):01
FUNCTION
order_select(where_clause)
02
DEFINE
where_clause STRING
,
03
sql_text STRING
04
05
LET
sql_text = "SELECT "
05
|| "orders.store_num, "
06
|| "customer.store_name, "
07
|| "orders.order_num, "
08
|| "orders.order_date, "
09
|| "orders.fac_code, "
10
|| "orders.ship_instr, "
11
|| "orders.promo "
12
|| "FROM orders, customer "
13
|| "WHERE orders.store_num = customer.store_num "
14
|| "AND " || where_clause
15
16
DECLARE
order_curs SCROLL CURSOR FROM
sql_text
17
OPEN
order_curs
18
IF
(NOT
order_fetch(1)) THEN
19
CLEAR FORM
20
MESSAGE
msg04
21
RETURN FALSE
22
END IF
23
24
RETURN TRUE
25
26
END FUNCTION
Note:
- Lines
05
thru14
contain the text of theSELECT
statement with the query criteria contained in the variablewhere_clause
. - Line
16
declares aSCROLL CURSOR
for theSELECT
statement stored in the variablesql_text
. - Line
17
opens theSCROLL CURSOR
. - Line
18
thru22
call the functionorder_fetch
, passing a parameter of 1 to fetch the next row, which in this case will be the first one. If the fetch is not successful,FALSE
is returned. - Line
24
returnsTRUE
, indicating the fetch was successful.