このサンプル・マクロ・アプリケーションでは、 リストで社員の名前を選択して個々の社員の追加情報を得られるアプリケーションから、 社員名のリストを表示します。 このマクロは、SQL 言語環境を使用して、社員名および特定の社員に関する情報の EMPLOYEE 表を照会します。
マクロ・ファイルは、 マクロ用の DEFINE ブロックを含んでいる組み込みファイルを使用します。
図 29 は、サンプル・マクロを示しています。 図 30 は、組み込みファイルを示しています。
%{************************ Sample Macro ***************************** * FileName = sqlsamp1.d2w * * Description: * * This Net.Data macro 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 FIRSTNME 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>$(V1) %} </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 FIRSTNME, PHONENO, JOB FROM $(myTable) WHERE FIRSTNME='$(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 = "EMPLOYEE" DATABASE = "sample" %} %{ End of include file %} |