IcingaConfig: escape binary checksums for pgsql

This commit is contained in:
Thomas Gelf 2015-06-23 15:13:34 +02:00
parent 8333975662
commit 9c5cd31357
1 changed files with 13 additions and 4 deletions

View File

@ -79,7 +79,7 @@ class IcingaConfig
$this->generateFromDb();
$checksum = $this->calculateChecksum();
$exists = $this->db->fetchOne(
$this->db->select()->from(self::$table, 'COUNT(*)')->where('checksum = ?', $checksum)
$this->db->select()->from(self::$table, 'COUNT(*)')->where('checksum = ?', $this->dbBin($checksum))
);
if ((int) $exists === 0) {
$this->store();
@ -87,6 +87,15 @@ class IcingaConfig
return $this;
}
protected function dbBin($binary)
{
if ($this->connection->getDbType() === 'pgsql') {
return Util::pgBinEscape($binary);
} else {
return $binary;
}
}
protected function calculateChecksum()
{
$files = array($this->getLastActivityHexChecksum());
@ -123,7 +132,7 @@ class IcingaConfig
try {
$existingQuery = $this->db->select()
->from($fileTable, 'checksum')
->where('checksum IN (?)', $this->getFilesChecksums());
->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
$existing = $this->db->fetchCol($existingQuery);
@ -200,7 +209,7 @@ class IcingaConfig
$query = $this->db->select()->from(
self::$table,
array('checksum', 'last_activity_checksum')
)->where('checksum = ?', $checksum);
)->where('checksum = ?', $this->dbBin($checksum));
$result = $this->db->fetchRow($query);
$this->checksum = $result->checksum;
$this->lastActivityChecksum = $result->last_activity_checksum;
@ -215,7 +224,7 @@ class IcingaConfig
array('f' => 'director_generated_file'),
'cf.file_checksum = f.checksum',
array()
)->where('cf.config_checksum = ?', $checksum);
)->where('cf.config_checksum = ?', $this->dbBin($checksum));
foreach ($this->db->fetchAll($query) as $row) {
$file = new IcingaConfigFile();