与 DB2 Extender 一起包括了一个名为 extender.d2w 的 Net.Data 宏文件。当由 Web 服务器运行时,宏文件执行调用 DB2 Extender UDF 的 SQL 语句。宏文件返回 Web 浏览器显示的结果。如图 24显示的那样, 每个结果页还显示为了生成结果而运行的 SQL 语句。图 25显示了样本 Net.Data 宏文件的内容。
要运行样本 Net.Data 宏文件,从 Web 浏览器输入以下 URL:http://your server/cgi-bin/db2www/extender.d2w/startHere
其中,your server 是您的 Web 服务器的名称
图 24. 运行样本 Net.Data 宏文件的 Web 应用程序
![]() |
%{ ------------------------------------------------------------------------ %} %{ Copyright International Business Machines Corporation, 1998. %} %{ All rights reserved. %} %{ %} %{ Sample Net.Data macro which shows how to call image, audio, and video %} %{ extender UDFs. %} %{ %} %{ To run, put this macro in your MACRO_PATH root, make sure the tmplobs %} %{ directory exists under your web server's document root, and create %} %{ the database to be used when running the extender sample programs %} %{ 'enable' and 'populate'. Run 'enable' and 'populate'. If you name your %} %{ database something other than 'testdb2', you'll need to change the %} %{ definition of DATABASE below. The extender environment variable %} %{ DB2MMEXPORT needs to be set for the instance used by Net.Data to point %} %{ to the webserver's <document root>/tmplobs directory. Then restart DB2 %} %{ and the extenders to have the variable take effect. %} %{ If you are not running Net.Data's Connection Manager, you'll need to %} %{ provide the LOGIN and PASSWORD to the database. If these instructions %} %{ seem unfamiliar to you, you should read the Net.Data documentation at %} %{ http://www.software.ibm.com/data/netdata/docs (or the extender documen- %} %{ tation on the extender sample programs). %} %{ %} %{ To disable the showing of SQL statements, change the value of SHOWSQL %} %{ below to "no". %} %{ ------------------------------------------------------------------------ %} %{ ------------------------------------------------------------------------ %} %{ Definitions section %} %{ ------------------------------------------------------------------------ %} %define{ DATABASE="testdb2" SHOWSQL="yes" %} %{ ------------------------------------------------------------------------ %} %{ SQL functions %} %{ ------------------------------------------------------------------------ %} %function (DTW_SQL) startHereSQL(){ select artist, title, stock_no, price from sobay_catalog %REPORT{ <table border="2" bgcolor="#b1b1b1"> <tr><th>Artist <th> Title <th> Stock<th> Number <th> Price </tr> %ROW{ <tr><td> $(V_artist) <td> $(V_title) <td> $(V_stock_no) <td> $(V_price) <tr> %} </table> %} %} %function (DTW_SQL) addThumbsSQL(){ select cast(mmdbsys.thumbnail(covers) as blob(10000)), cast(mmdbsys.thumbnail(video) as blob(3000)), mmdbsys.comment(music), artist, title, price, stock_no from sobay_catalog %REPORT{ <table border="2" bgcolor="#b1b1b1"> <tr><th>Cover <th>Video <th>Audio <th>Artist <th>Title <th>Price </tr> %ROW{ <tr><td>< a href="showCover?stock_no=$(V_stock_no)"><img src="$V1)"></a> <td>< a href="getVideo?stock_no=$(V_stock_no)"><img src="$V2)"></a> <td>< a href="getAudio?stock_no=$(V_stock_no)&filename=$V3")>[Listen]</a> <td> $(V_artist) <td> $(V_title) <td> $(V_price) </tr> %} </table> %} %} %function (DTW_SQL) showCoverSQL(){ select cast(mmdbsys.content(covers, 'GIF') as blob(150000)), mmdbsys.format(covers) from sobay_catalog where stock_no = '$(stock_no)' %REPORT{ %ROW{ <img src="$(V1) "> <br><br><b>Original image format: $(V2)</b>%} %} %} %{ The following Content call depends on DB2MMEXPORT being set properly to point to the tmplobs directory under the web server's document root. %} %function (DTW_SQL) showVideoSQL(){ select mmdbsys.comment(video), mmdbsys.content(video, mmdbsys.comment(video), 1), mmdbsys.format(video) from sobay_catalog where stock_no = '$(stock_no)' %REPORT{ %ROW{ <a href="/tmplobs/$(V1)"><i><b> Play Video Clip></b></i></a> <br><br><b>Format: $(V3) <br>(Note: NT/Win95 may not come with a decompressor<br>for this video format. OS/2 Warp does.)</br> %} %} %} %{ The following Content call depends on DB2MMEXPORT being set properly to point to the tmplobs directory under the web server's document root. %} %function (DTW_SQL) showAudioSQL(){ select mmdbsys.comment(music), mmdbsys.content(music, mmdbsys.comment(music), 1), mmdbsys.format(music) from sobay_catalog where stock_no = '$(stock_no)' %REPORT{ %ROW{ < a href="/tmplobs/$(V1) "<i><b>Play Audio Clip</b></i></a> <br><br><b>Format: $(V3)</b> %} %} %} %{ ------------------------------------------------------------------------ %} %{ HTML sections %} %{ E.g., http://<your server>/cgi-bin/db2www/extender.d2w/startHere %} %{ -------------------------------------------------------------------------%} %{ E.g., http:// %{ E.g., http:// %HTML(startHere){ <html> <head><title>UDB Extenders Macro Sample: Simple Row Listing</title></head> <body bgcolor="#ffffff"> <font color="#3300ff" size="3"><b>If no data appears below, you might need to run the UDB Extender sample programs <i>enable</i> and <i>populate</i>. This first HTML section of the extender.d2w macro simply retrieves all the traditional data for all the rows in the UDB Extenders' sample database. %if ( "$(SHOWSQL)" == "yes" || "$(SHOWSQL)" == "YES" ) <br><br> By default, every page generated by this macro shows the SQL used to generate that page. Here is the SQL statement for this page: %else <br> %endif </b></font> <br>@startHereSQL() <br><b>Click < a href="addThumbs"><i>here</i></a> to display thumbnails and links to image/audio/video data.</b> </body> </html> %} %HTML(addThumbs){ <html> <head><title>UDB Extenders Macro Sample: Add Thumbnails</title></head> <body bgcolor="#ffffff"> <font color="#3300ff" size="3"><b>This page adds album cover thumbnails and links to display the multimedia content of the database. To access the multimedia content: <ul> <li> Click on a thumbnail of a CD cover to view a full-size image <li> Click on a "video thumbnail" to view a video <li> Click on a "[Listen]" link to listen to an audio clip </ul> </b></font> @addThumbsSQL() <br><b>Click < a href="startHere"><i>here</i></a> to go back to the first page.</b> </body> </html> %} %HTML(showCover){ <html> <head><title>UDB Extenders Macro Sample: Cover for item $(stock_no)</title></head> <body bgcolor="#ffffff"> <font color="#3300ff" size="3"><b>For this page, the macro gets a full-size cover image, converting the image format to GIF so that a browser can show it: </b></font><br><br> <table width="400" border="2" bgcolor="#b1b1b1" cellpadding="5"> <tr><td align=center> @showCoverSQL() <tr><td align=center> <b>Stock Number: $(stock_no)</b> </table> <br><b>Go <a href="addThumbs"><i>back</i></a>.</b> </body> </html> %} %HTML(getVideo){ <html> <head><title>UDB Extenders Macro Sample: Video clip for item $(stock_no)</title></head> <body bgcolor="#ffffff"> <font color="#3300ff" size="3"><b>From this page, you can view a video clip: </b></font><br><br> <table width="400" border="2" bgcolor="#b1b1b1" cellpadding="5"> <tr><td align=center> @showVideoSQL() <tr><td align=center> <b>Stock Number: $(stock_no)</b> </table> <br><b>Go <a href="addThumbs"><i>back</i></a>.</b> </body> </html> %} %HTML(getAudio){ <html> <head><title>UDB Extenders Macro Sample: Audio clip for item $(stock_no)</title></head> <body bgcolor="#ffffff"> <font color="#3300ff" size="3"><b>From this page, you can listen to an audio clip: </b></font><br><br> <table width="400" border="2" bgcolor="#b1b1b1" cellpadding="5"> <tr><td align=center> @showAudioSQL() <tr><td align=center> <b>Stock Number: $(stock_no)</b> </table> <br><b>Go <a href="addThumbs"><i>back</i></a>.</b> <body> </html> %} |