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

Update AnemometerModel.php #189

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/AnemometerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ public function get_reviewers() {
*/
public function checksum_exists($checksum) {
$checksum_field_name = $this->get_field_name('checksum');
$query = "SELECT `{$checksum_field_name}` FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`=" . $this->mysqli->real_escape_string($checksum);
if ($checksum_field_name == 'DIGEST') {
$query = "SELECT `{$checksum_field_name}` FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`='" . $this->mysqli->real_escape_string($checksum) . "'";
} else {
$query = "SELECT `{$checksum_field_name}` FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`=" . $this->mysqli->real_escape_string($checksum);
}
$result = $this->mysqli->query($query);
check_mysql_error($result, $this->mysqli);
if ($result->num_rows) {
Expand Down Expand Up @@ -227,7 +231,11 @@ function ($x, $y) use ($mysqli) {
}, array_keys($fields), array_values($fields)
)
);
$sql .= " WHERE `{$checksum_field_name}`=" . $this->mysqli->real_escape_string($checksum);
if ($checksum_field_name == 'DIGEST') {
$sql .= " WHERE `{$checksum_field_name}`='" . $this->mysqli->real_escape_string($checksum) . "'";
} else {
$sql .= " WHERE `{$checksum_field_name}`=" . $this->mysqli->real_escape_string($checksum);
}
$res = $this->mysqli->query($sql);
// @todo ... fix this by making it a local method
check_mysql_error($res, $this->mysqli);
Expand All @@ -241,7 +249,11 @@ function ($x, $y) use ($mysqli) {
*/
public function get_query_by_checksum($checksum) {
$checksum_field_name = $this->get_field_name('checksum');
$result = $this->mysqli->query("SELECT * FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`={$checksum}");
if ($checksum_field_name == 'DIGEST') {
$result = $this->mysqli->query("SELECT * FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`='{$checksum}'");
} else {
$result = $this->mysqli->query("SELECT * FROM `{$this->fact_table}` WHERE `{$checksum_field_name}`={$checksum}");
}
check_mysql_error($result, $this->mysqli);
if ($row = $result->fetch_assoc()) {
return $row;
Expand All @@ -265,7 +277,11 @@ public function get_query_samples($checksum, $limit = 1, $offset = 0) {
{
$table = $this->fact_table;
}
$sql = "SELECT * FROM `{$table}` WHERE `{$checksum_field_name}`={$checksum} ORDER BY `{$time_field_name}` DESC LIMIT {$limit} OFFSET {$offset}";
if ($checksum_field_name == 'DIGEST') {
$sql = "SELECT * FROM `{$table}` WHERE `{$checksum_field_name}`='{$checksum}' ORDER BY `{$time_field_name}` DESC LIMIT {$limit} OFFSET {$offset}";
} else {
$sql = "SELECT * FROM `{$table}` WHERE `{$checksum_field_name}`={$checksum} ORDER BY `{$time_field_name}` DESC LIMIT {$limit} OFFSET {$offset}";
}
return $this->mysqli->query($sql);
}

Expand Down