| THE META-HTML LANGUAGE REFERENCE MANUAL

| [TOC] |

## Manual Page Viewer

Name: MSQL::DATABASE-QUERY

Section: Msql Database Extensions

Synopsis:

`<msql::database-query DBVAR EXPR QUERY [COLNAMES=NAMELIST] [PREFIXTABLENAMES] [QUERY=QUERY-STRING] [FORMAT=FEXPR] [KEYS=VARNAME] [KEYNAME=FIELDNAME]>`

Description:

Select and optionally format records in the database DB according to the criterion in FEXPR.

QUERY is an SQL query, which returns a list of rows.

For each result row, EXPR is then evaluated, with the column values of each row bound to their corresponding column name. If the result of that evaluation is not an empty string, then that record is selected for further processing by either FORMAT, KEYS, or to return in plain text the list of keys. If FORMAT is present, it is an expression to evaluate in the context of the database fields, (as with EXPR).

The example below shows an SQL query which is formatted as rows of an HTML table. In this case, the EXPR is simply the constant true, and all of the selection of records is done via the SQL query itself. The EXPR could be used to impose additional conditions to decide whether to invoke the format expression on a row.

      <msql::with-open-database rdb database=rolodex
    			    host=localhost>
      <table border=1>
        <tr><th>Name</th><th>Age</th></tr>
      <msql::database-query rdb true
    			query="SELECT * FROM people WHERE name like 'Washington' ORDER BY lastname"
    			format=<prog <tr>
    				 <td>
    				 <get-var lastname>, <get-var firstname>
    				 </td>
    				 <td>
    				 <get-var age>
    				 </td>
    				 </tr>>>
        </table>
      </msql::with-open-database>

If KEYS is specified, it is the simple name of a variable to receive the array of keys which satisfied FEXPR. If you specify an argument for KEYS, you must also specify which column to collect the values from, using the KEYNAME keyword argument.

If the optional argument COLNAMES is supplied, then for each row, column values are bound sequentially to these comma-separated names instead of the column names in the result set.

    <msql::database-query mydb true query=<get-var query>
                          colnames="foo.name, bar.name"
                          format=<prog FOO.NAME IS
    				<get-var foo.name>
    				BAR.NAME IS
    				<get-var bar.name>>>

If PREFIXTABLENAMES is non-null, or the database connection option SQL-PREFIX-TABLENAMES is non-null, then for each column in the result set, use the column's table name, if it exists, as a prefix to the column name as the variable name.

Edit Pointer
Function Index
Variable Index
Variable Editor

The META-HTML Reference Manual V1.4 Copyright © 1995, 1996, Brian J. Fox, 1996, 1997 Universal Access Inc.
Found a bug? Send mail to bug-manual@metahtml.com