if directive

Directive Name

if

Directive Type

nested

Synopsis

<sql if> ... </sql>

Description

The if directive process its contents conditionally. The contents will include one or more conditions (introduced with <sql-if ...>) and an optional "else" marker (<sql-else/>).

Each condition tests to see if some condition is true. The if directive will process any contents from the first condition that is true, through to the next condition or "else" marker. If no conditions are true, the if directive will process any contents from the "else" marker through to the end of the if directive.

The following conditions are recognised:

anyrows True if the previous query returned any rows
norows True if the previous query returned no rows
haderror True if the previous database initialisation, connection, query, command, disconnection or uninitialisation generated an error message.
noerror True if the previous database initialisation, connection, query, command, disconnection or uninitialisation did not generate an error message.
anyerror True if any SQL command since the last reseterror generated an error message.
zeroerrors True if no SQL command since the last reseterror generated an error message.
anyinvalid True if any validation has failed since the last resetvalidation.
allvalid True if no validation has failed since the last resetvalidation.
evaluate True if the formula expression contained in this condition evaluates to a nonempty string or a nonzero number.
has-file True if a file was received in a form field named by the contents - eg. <sql-if has-file>uplfile</sql-if>
has-no-file True if no file was received in a form field named by the contents - eg. <sql-if has-no-file>uplfile</sql-if>

Examples

<sql if>
	<sql-if evaluate>
		%r > 20
	</sql-if>
		<p>More than 20 rows were returned</p>
	<sql-if anyrows/>
		<p>Some rows returned</p>
	<sql-else/>
		<p>No rows returned</p>
</sql>
<sql format/>
<sql error/>

<sql query c1>
	select
		name
	from
		passwords
	where
		user = %[+user%] and
		pass = %[+pass%]
</sql>

<sql if>
	<sql-if haderror/>
		<h1>Error accessing user database</h1>
		<p>
			There was an error accessing the user database.
			Please try again later.
		</p>
		</body>
		</html>
		<sql exit/>
	<sql-if norows/>
		<h1>Authentication failed</h1>
		<p>
			Your user name or password was incorrect.
		</p>
		</body>
		</html>
		<sql exit/>
</sql>