formVista(tm) Developers Guide and Reference
 

19.39. <mysql> - Mysql Database Support

The <mysql> tag implements the interface to the Mysql Database Server. It adds a number of convenience features including:

  1. automatic generation of INSERT, UPDATE, DELETE and WHERE clauses.

  2. enforces Mysql quoting rules to prevent sql-injection.

  3. automatically cooperates with List components to generate LIMIT clauses.

  4. supports appending date ranges to the query - today, yesterday, this week, last week, this month, last month, etc.

  5. supports turning any time series query into hour, day, week, and year queries.

Which kind of query <mysql> generates will depend on the event it receives from it's parent. Standard form and list command handler sections, onDoInsert, onDoEdit, onDoDelete, onDoUpdate, onDoSearch, etc will generate corresponding events that <mysql> responds to.

19.39.1. Usage:

Usage in query auto-generation of INSERT, UPDATE, DELETE statements based on fields from the form that match column names in the specified table or that are mapped onto column names via <query_hint type=”set” ..> calls.

<mysql mode="insert|update|delete"
       table="table_name"
       [database="database_name"]
       [namespace="namespace_name"]>
   <query_hint type="primary_key" name="primary_column_name"/>
   [<query_hint type="create_date" name="date_field"/>]
   [<query_hint type="set" name="var_name" value="var_value"/>
</mysql>
   

See the Complete Form Example for a number of auto-generated queries.

Typical time series report usage in SELECT statements:

<mysql type="datafeed|preload"
   table="table_name"
   datecol="date_column"
   [database="database_name"]
   [namespace="namespace_name"]>
   SELECT $MY{DATE_GROUP} as date_group,
          $MY{DATE_GROUP_START} as group_start,
          $MY{DATE_GROUP_END} as group_end,
          COUNT( distinct( some_field ) ) as count
   FROM table_name
   WHERE "1" = "1"
   $MY{SEARCH_CLAUSE}
   $MY{DATE_RANGE}
   GROUP BY date_group
   $MY{LIMIT}   
</mysql>
   

See the Time Series Report Example in the formvista_demoshell to see the query above in action.

19.39.3. Attributes

The mysql tag adds support for the following additional attributes.

19.39.3.3. mode=”datafeed|preload|plain|update|insert|delete” (same as type=”...”)

The mode=”” attribute identifies what “mode” the <mysql> tag should operate in. Whether it should wait to pull in rows when asked , whether it should preload the first row, etc.

19.39.6. Variables

19.39.6.4. DATE_RANGE

Generated by the <mysql> tag and used by long-hand queries as $MY{DATE_RANGE} in the SQL query itself. It's used to generate date range WHERE clause fragments useful in writing reports over time. It handles values of today, yesterday, this week, last week, etc.

From the Time Series Report Example example, selecting this month, which is currently November 2005 $MY{DATE_RANGE} in the query is replaced by:

( entry_date >= "2005-11-01 00:00:00" ) and 
( entry_date <= "2005-11-30 23:59:59" )
    

For this variable to be available the datecol=”..” attribute must be specified in the <mysql> tag. See the