Riverwatcher Active Content Environment

RACE Documentation:


DATABASE - Interface for native database support in RACE.



  • NAME - The name of the database to be accessed.
  • USER - The username to log into the database server with.
  • PASSWORD - The password to log into the database server with.
  • TYPE - The type of database server to be accessed (currently supported types are mysql, pgsql, msql and iodbc).
  • QUERY - The command you want to send to the database server.
  • HOST - The hostname of the database server, if not local.
  • DSN/DATASOURCE - The data source name or data source must be specified if you are using a database through ODBC. The built-in support for ODBC allows your RACE script to connect to any backend database, as long as you have the appropriate ODBC driver for it. If you are accessing the database via ODBC, you must specify the DSN (Data Source Name) or DATASOURCE attribute The data source you specified must match an entry in the odbc.ini file. With a DSN specified, the NAME, USER, PASSWORD, and HOST become optional, as long as they are properly specified in the odbc.ini file. For more information, please refer to the ODBC manager documentation for your server.
  • STARTROW - This attribute can be used to indicate which row (or record number) to start processing. When used alone or in conjunction with the optional MAXROWS attribute, you can restrict the portion of records that are returned to the DATABASE tag to execute.
  • MAXROWS - This attribute is used to limit the number of rows to be executed by the DATABASE tag.
The DATABASE tag initiates a database connection, and makes the query (or queries) specified therein. When the data is returned, all code within the tag body is executed on each row.

After a query is executed, the system variable will contain the query. The variable will contain any error messages that may have been returned. Most importantly, the database variables will be given values.

Returned database variables are as follows:

- the value of the field "fieldname" for this particular row.

This is best described by example:

Example - Returning results of a select statement in a table
Source:

<table border="1">
<tr>
<td>ID</td>
<td>Description</td>
<td>Price</td>
</tr>
<database name="mystuff" user="me" password="hidden" type="mysql" query="select ID, Description, Price from Inventory where ID < 3">
<tr>
<td><#ID></td>
<td><#Description></td>
<td><#Price></td>
</tr>
</database>
</table>

Output:
ID Description Price
1 Red Thing $2
2 Green Thing $1
3 Purple Thing $20



Example - Nesting database queries
Source:

<database name="mystuff" user="me" password="hidden" type="mysql" query="SELECT ID, title FROM classes ORDER BY title">
  <#title><br>
  <database name="mystuff" user="me" password="hidden" type="mysql" query="SELECT lastname, firstname FROM students WHERE students.ClassID=<#ID> ORDER BY lastname, firstname">
    - <#lastname>, <#firstname><br>
  </database>
  <br>
</database>

Output:
CS 125
- Smith, Bob
- Jones, Jeff
- Robertson, Mary

MATH 130
- Johnson, David
- McMahon, Ed




RACE Documentation



 
Copyright 2009 Riverwatcher, Inc. Hosting by Riverwatcher Studios