Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes queries being generated which have an empty WHERE clause #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Store/SqlDBStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function __construct($event_type, $event_data = 'state', $prefix = '') {
public function buildQueries(\DateTime $start_date, \DateTime $end_date, $unit_ids) {
$queries = array();

$queries[Event::BAT_DAY] = 'SELECT * FROM ' . $this->day_table . ' WHERE ';
$queries[Event::BAT_HOUR] = 'SELECT * FROM ' . $this->hour_table . ' WHERE ';
$queries[Event::BAT_MINUTE] = 'SELECT * FROM ' . $this->minute_table . ' WHERE ';
$queries[Event::BAT_DAY] = 'SELECT * FROM ' . $this->day_table;
$queries[Event::BAT_HOUR] = 'SELECT * FROM ' . $this->hour_table;
$queries[Event::BAT_MINUTE] = 'SELECT * FROM ' . $this->minute_table;

// Create a mock event which we will use to determine how to query the database
$mock_event = new Event($start_date, $end_date, new Unit(0, 0, array()), -10);
Expand Down Expand Up @@ -138,9 +138,9 @@ public function buildQueries(\DateTime $start_date, \DateTime $end_date, $unit_i
}

// Add parameters to each query
$queries[Event::BAT_DAY] .= $query_parameters;
$queries[Event::BAT_HOUR] .= $query_parameters;
$queries[Event::BAT_MINUTE] .= $query_parameters;
$queries[Event::BAT_DAY] = !empty($query_parameters) ? $queries[Event::BAT_DAY] . ' WHERE ' . $query_parameters : $queries[Event::BAT_DAY];
$queries[Event::BAT_HOUR] = !empty($query_parameters) ? $queries[Event::BAT_HOUR] . ' WHERE ' . $query_parameters : $queries[Event::BAT_HOUR];
$queries[Event::BAT_MINUTE] = !empty($query_parameters) ? $queries[Event::BAT_MINUTE] . ' WHERE ' . $query_parameters : $queries[Event::BAT_MINUTE];

// Clean up and add ordering information
$queries[Event::BAT_DAY] .= ' ORDER BY unit_id, year, month';
Expand Down