此例子应用程序显示一个雇员列表。应用程序用户可以选择一个雇 员名以察看细节。应用程序使用 SQL 语言环境,并使用 Net.Data 变量 LOGIN 和 PASSWORD 来为数据库认证用户。
%{************************ 动态查询的例子 *****************************
* FileName = sqlsamp1.mac *
* 描述: *
* 这个 Net 宏文件 ... *
* - 从数据库创建一个动态选择列表 *
* - 使用一个缺省表格来显示 SQL 的结果 *
* *
****************************************************************************%}
%{***************************************************************************
* 包含 - *
****************************************************************************%}
%INCLUDE "sqlsamp1.hti"
%{****************************************************************************
* 函数: queryDB 语言环境: SQL *
* 说明: 查询数据库,并从结果中创建一个选择列表。 *
* 数据库名称和表格名称都是变量,在上述包含文件 *
* 中定义。 *
****************************************************************************%}
%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>
%}
%}
%{****************************************************************************
* 功能模块 *
* 说明: 发送 SQL 在数据库中查询选定的第一个名称,并生成一个缺省的 *
* 表格 *
******************************************************************************%}
%FUNCTION(DTW_SQL) fname(){
SELECT FIRSTNME, MIDINIT, LASTNAME, 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 模块: INPUT 标题:Dynamic Query Selection *
* *
* 说明: 查询数据库,创建雇员的 *
* 选择列表 *
****************************************************************************%}
%HTML(INPUT) {
<html><head><title>Dynamic Query Selection</title></head><body><h3>$(exampleTitle)</h3>
<p>This example queries a database and dynamically uses the results to create
a selection list using the <em>%REPORT</em> block.
<hr>
<p>The following selection list is built dynamically by looking into the database
<form method="post" action="report">
@queryDB()<input type="submit" value="Select Employee">
</form>
<hr>
</body>
</html>
%}
%{***************************************************************************
* HTML 模块: REPORT 标题:Dynamic Query Selection *
* 说明: 结果页 - 调用 SQL 函数,显示在上页中选定的 *
* 雇员信息 *
****************************************************************************%}
%HTML(REPORT) {
<html>
<head>
<title>Dynamic Query Selection</title>
</head>
<body>
<h3>You selected employee name = $(emp_name)</h3>
<p>Here is the information for that employee:
<PRE>
------------------------ Database query results ------------------------------
@fname()
</PRE>
<hr><a href="input">Return to previous page</a>
</body>
</html>
%}
%{ End of Net.Data macro 1 %}
===========================================================================
%{**************************** 包含文件 **********************************
* FileName = sqlsamp1.hti *
* 描述: *
* 这个包含文件为 sqlsamp1.mac Net..Data 宏提供了 *
* 全局 DEFINE。 *
* *
* *
****************************************************************************%}
%define {
DATABASE ="SAMPLE"
LOGIN ="USERID"
PASSWORD ="PASSWORD"
emp_name ="a name"
exampleTitle = "SQL Example"
myTable = "EMPLOYEE"
%}
%{ End of include file %}
|