<IfDefine SQLTEMPLATE>
  <IfModule !mod_sqltemplate.c>
    LoadModule sqltemplate_module modules/mod_sqltemplate.so
  </IfModule>

  # These commands MUST appear before any template sections, to initialise the
  # database connection:

  # DBD driver to use
  SQLTemplateDBDriver "mysql"
  # DBD driver parameters
  SQLTemplateDBParams "host=localhost,user=db-username-here,pass=password-goes-here,dbname=database-name"

  # There are three new sections: <SQLRepeat>, <SQLCatSet> and <SQLSimpleIf>

  # SQLRepeat sections repeat their content for every result row, replacing
  # variables with column values as necessary. NULL values expand to the empty
  # string. The sections take the form:
  #   <SQLRepeat "query goes here">
  #     ...
  #   </SQLRepeat>
  #
  # Note that, in all cases, variable names are taken from the column names
  # returned by the query.
  #
  <SQLRepeat "SELECT id, foo, bar, quux FROM t_baz WHERE your_bases = 'us'">
    <VirtualHost *:80>
      # variables can be "bare" (i.e. no braces) and the longest match (no
      # spaces) wins
      ServerName $foo.base.example.org
      # or they can be enclosed in braces to force an exact match
      Header Add "X-Your-Base" "${foo}"
      # Note that in this example, $barrister would substitute the same way
      # as ${bar}rister
      Header Add "X-Are-Belong" "$barrister"
      Header Add "X-To-Us" "${quux}"
    </VirtualHost>

    # Repeat sections can be nested... but escape the variables unless you
    # want warnings or want them replaced by the outside section. This ${id}
    # comes from the outer section:
    <SQLRepeat "SELECT * FROM aliases WHERE base_id = ${id}">
      # but these come from the inner
      Alias "\$base" "\$target"
      # If you had a third-level nesting, you would need two backslashes
    </SQLRepeat>

    # SQLCatSet sections concatenate all of the results for each field of the
    # query into one string, separated by a given delimiter string. It takes
    # the form:
    #   <SQLCatSet "sep" "query">
    #     ...
    #   </SQLCatSet>
    #
    # The example below will take all results of the query (e.g. "*.base",
    # "*.base.org", "*.base.example.com") and concatenate them with a space to
    # form: "*.base *.base.org *.base.example.com"
    #
    <SQLCatSet " " "SELECT hostname FROM server_aliases WHERE base_id=$id">
      ServerAlias ${hostname}
    </SQLCatSet>

    # Finally, SQLSimpleIf provides a very simple conditional inclusion test.
    # If the first character of its argument is an exclamation mark, it is
    # negated. Otherwise, the content is included if the argument is a non-zero
    # integer, "on", "true" or "yes".
    <SQLSimpleIf ${quux}>
      Header Add "X-Quux" "Included"
    </SQLSimpleIf>

    <SQLSimpleIf !${quux}>
      Header Add "X-Quux" "Not included"
    </SQLSimpleIf>
  </SQLRepeat>
</IfDefine>

# vim: ft=apache sw=2 ts=2 et
