public function getCountSQL($Aggregate, $ParentTable, $ChildTable, $ParentColumnName = '', $ChildColumnName = '', $ParentJoinColumn = '', $ChildJoinColumn = '')
{
if (!$ParentColumnName) {
switch (strtolower($Aggregate)) {
case 'count':
$ParentColumnName = "Count{$ChildTable}s";
break;
case 'max':
$ParentColumnName = "Last{$ChildTable}ID";
break;
case 'min':
$ParentColumnName = "First{$ChildTable}ID";
break;
case 'sum':
$ParentColumnName = "Sum{$ChildTable}s";
break;
}
}
if (!$ChildColumnName) {
$ChildColumnName = $ChildTable . 'ID';
}
if (!$ParentJoinColumn) {
$ParentJoinColumn = $ParentTable . 'ID';
}
if (!$ChildJoinColumn) {
$ChildJoinColumn = $ParentJoinColumn;
}
$Result = "update :_{$ParentTable} p\n set p.{$ParentColumnName} = (\n select {$Aggregate}(c.{$ChildColumnName})\n from :_{$ChildTable} c\n where p.{$ParentJoinColumn} = c.{$ChildJoinColumn})";
return $Result;
}