这个示例宏应用程序显示了一张雇员列表,应用程序用户可以通过在列表中选择雇员的 姓名来获取某个雇员的额外信息。此宏使用 SQL 语言环境来查询 EMPLOYEE 表,从中获取雇员姓名 和某个特定雇员的有关信息。
%{************************ Sample Macro ***************************** * FileName = sqlsamp1.d2w * * Description: * * This Net.Data macro file queries... * * - The EMPLOYEE table to create a selection list of * * employees for display at a browser * * - The EMPLOYEE table to obtain additional information * * about an individual employee * * * ********************************************************************%} %{*************************************************************************** * Include for global DEFINEs - * ****************************************************************************%} %INCLUDE "sqlsamp1.hti" * %{**************************************************************************** * Function: queryDB Language Environment: SQL * * Description: Queries the table designated by the variable myTable and * * creates a selection list from the result. The value of the variable * * myTable is specified in the include file sqlsamp1.hti. * ****************************************************************************%} %FUNCTION(DTW_SQL) queryDB() { SELECT * FROM $(myTable) %MESSAGE { -204: {<p><b>ERROR -204: Table $(myTable) not found. </b> <p>Be sure the correct include file is being used.</b> %} : exit +default: "WARNING $(RETURN_CODE)" : continue -default: "Unexpected ERROR $(RETURN_CODE)" : exit %} %REPORT { <select name=emp_name> %ROW{ <option>$(V2) %} </select> %} %} %{**************************************************************************** * Function: fname Language Environment: SQL * * Description: Queries the table designated by the variable myTable for * * additional information about the employee identified by the * * variable emp_name. * ******************************************************************************%} %FUNCTION(DTW_SQL) fname(){ SELECT EMPNME, PHONENO, JOB FROM $(myTable) WHERE EMPNME='$(emp_name)' %MESSAGE { -204: "Error -204: Table not found " -104: "Error -104: Syntax error" 100: "Warning 100: No records" : continue +default: "Warning $(RETURN_CODE)" : continue -default: "Unexpected SQL error" : exit %} %} %{*************************************************************************** * HTML block: INPUT Title: Dynamic Query Selection * * * * Description: Queries the EMPLOYEE table to create a selection list of * * the employees for display at the browser * ****************************************************************************%} %HTML(INPUT) { <html> <head> <title>Generate Employee Selection List</title> </head> <body> <h3>$(exampleTitle)</h3> <p>This example queries a table and uses the result to create a selection list using a <em>%REPORT</em> block. < hr> <form method="post" action="report"> @queryDB()<input type="submit" value="Select Employee"> </form> < hr> </body> </html> %} %{*************************************************************************** * HTML block: REPORT * * Description: Queries the EMPLOYEE table to obtain additional information * * about an individual employee * ****************************************************************************%} %HTML(REPORT){ <html> <head> <title>Obtain Employee Information</title> </head> <body> <h3>You selected employee name = $(emp_name)</h3> <p>Here is the information for that employee: <PRE> @fname() </PRE> <hr><a href="input">Return to previous page</a> </body> </html> %} %{ End of Net.Data macro 1 %} =========================================================================== %{**************************** Include File ********************************* * FileName = sqlsamp1.hti * * Description: * * This include file provides global DEFINEs for the sqlsamp1.d2w * * Net.Data macro. * ****************************************************************************%} %define { emp_name ="" reposition = sign exampleTitle = "Sample Macro" myTable = "MRZ.EMPLOYEE" %} %{ End of include file %} |