Statement Expressions
October 3, 2025 ยท View on GitHub
The library provides classes to represent SQL statements as expressions.
The following expression classes are available:
CaseX
The CaseX expression allows you to create SQL CASE statements.
The CaseX class accepts the following arguments:
valuecomparison condition in theCASEexpression:stringis treated as a table column name which will be quoted before usage in the SQL statement;arrayis treated as a condition to check, seeQueryInterface::where();- other values will be converted to their string representation using
QueryBuilderInterface::buildValue(). If not provided, theCASEexpression will be a WHEN-THEN structure without a specific case value.
valueTypeoptional data type of theCASEexpression which can be used in some DBMS to specify the expected type;...argsList ofWHEN-THENconditions and their corresponding results represented as WhenThen instances orELSEvalue in theCASEexpression. StringELSEvalue will be quoted before usage in the SQL statement.
For example:
$case = new CaseX(
'status',
when1: new WnenThen('active', 'Active User'),
when2: new WnenThen('inactive', 'Inactive User'),
else: 'Unknown Status',
);
This will generate the following SQL:
CASE "status"
WHEN 'active' THEN 'Active User'
WHEN 'inactive' THEN 'Inactive User'
ELSE 'Unknown Status'
END