protected function AppendConstant(QueryBuilder $QueryBuilder, CoreE\ConstantExpression $Expression) { $QueryBuilder->AppendSingleValue($Expression->GetValue()); }
public final function AppendDataAsInlineTable(QueryBuilder $QueryBuilder, array $Columns, $DerivedTableName, array $ColumnDataArray) { $QueryBuilder->Append(' SELECT '); /* * Apply all the persisting data expressions as a select on the inline table * rather than on every row */ foreach ($QueryBuilder->Delimit($Columns, ', ') as $ColumnName => $Column) { $QueryBuilder->AppendExpression(Expression::PersistData($Column, Expression::Identifier([$DerivedTableName, $ColumnName]))); } $QueryBuilder->Append(' FROM ('); $ColumnDataArray = array_map(function (Relational\ColumnData $ColumnData) { return $ColumnData->GetData(); }, $ColumnDataArray); $ColumnNames = array_map(function ($Column) { return $Column->GetName(); }, $Columns); $Identifiers = array_combine($ColumnNames, array_map(function ($Column) { return $Column->GetIdentifier(); }, $Columns)); $ParameterTypes = $this->GetParamterTypes($Columns); $First = true; $QueryBuilder->Append('SELECT '); foreach ($QueryBuilder->Delimit($ColumnDataArray, ' UNION ALL SELECT ') as $ColumnData) { $FirstValue = true; foreach ($Identifiers as $ColumnName => $Identifier) { if ($FirstValue) { $FirstValue = false; } else { $QueryBuilder->Append(','); } $Value = isset($ColumnData[$Identifier]) ? $ColumnData[$Identifier] : null; $QueryBuilder->AppendSingleValue($Value, $Value === null ? ParameterType::Null : $ParameterTypes[$ColumnName]); if ($First) { $QueryBuilder->AppendIdentifier(' AS #', [$ColumnName]); } } $First = false; } $QueryBuilder->AppendIdentifier(') #', [$DerivedTableName]); }