docs.roxen.comBack to normal mode
DocsRoxenWebServer 3.3TutorialsDatabase Tutorial
Copyright © 2004, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com

The emit and sqlquery Tags

The <emit> tag is a plugin-based data management system.

Generally speaking, <emit> will iterate through all the data in a dataset such as the result of a SQL query, processing the contents of the tag for each item in the dataset. The source of the dataset is specified in the tag's arguments, along with a few source-dependent parameters. See the chapter on emit in the creator manual for more details. The emit tag allows to take full advantage of the Roxen WebServer variable scopes.

Applying this to the case of SQL queries, the dataset is a tabular result, and the items are the result's rows. The source to be used is named "sql", and it takes as additional arguments host (the SQL-URL of the host to be contacted) and query (the SQL query to be executed). Additionally, it accepts the same parameters as the sqloutput tag.

The example in the tablify chapter can be rendered with emit as:


<table border=1>
<emit source="sql" host="mysql://user:password@localhost/sample"
  query="select name,area_tot from ids, countries where
  ids.code=countries.country">
<tr><td>&_.name;</td><td>&_.area_tot;</td></tr>
</emit>
</table>

Remember: _ is the default scope. Should it be unavailable, or should you want to use it for some other tag, you can use another scope, like this:


<table border=1>
<emit source="sql" host="mysql://user:password@localhost/sample"
  scope="queryscope"
  query="select name,area_tot from ids, countries where
  ids.code=countries.country">
<tr><td>&queryscope.name;</td><td>&queryscope.area_tot;</td></tr>
</emit>
</table>

The sqlquery tag can be rendered with an empty emit tag


<sqlquery host="mysql://user:password@localhost/sample"
  query="insert into foo(bar) values ('gazonk')">

can thus be translated into


<emit source="sql" host="mysql://user:password@localhost/sample"
  query="insert into foo(bar) values ('gazonk')" />

There is no builtin way to emulate the sqltable tag, you'll have to follow the syntax described for the <tablify> tag previously.