Always use dynamic table names

This commit is contained in:
James Brooks
2016-10-30 17:35:57 +00:00
parent a8bdc5bf52
commit 1c00dec364
4 changed files with 27 additions and 13 deletions

View File

@@ -53,7 +53,7 @@ abstract class AbstractMetricRepository
*
* @return string
*/
protected function getTableName()
protected function getMetricsTable()
{
$driver = $this->config->get('database.default');
$connection = $this->config->get('database.connections.'.$driver);
@@ -62,6 +62,20 @@ abstract class AbstractMetricRepository
return $prefix.'metrics';
}
/**
* Get the metric points table name.
*
* @return string
*/
protected function getMetricPointsTable()
{
$driver = $this->config->get('database.default');
$connection = $this->config->get('database.connections.'.$driver);
$prefix = $connection['prefix'];
return $prefix.'metric_points';
}
/**
* Return the query type.
*
@@ -72,11 +86,11 @@ abstract class AbstractMetricRepository
protected function getQueryType(Metric $metric)
{
if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
return 'sum(metric_points.value * metric_points.counter) AS value';
return "sum({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value";
} elseif ($metric->calc_type == Metric::CALC_AVG) {
return 'avg(metric_points.value * metric_points.counter) AS value';
return "avg({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value";
} else {
return 'sum(metric_points.value * metric_points.counter) AS value';
return "sum({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value";
}
}