Db: add idPgsql helper method

This commit is contained in:
Thomas Gelf 2016-03-02 13:42:37 +01:00
parent f2439412b1
commit 2865efde3f
7 changed files with 16 additions and 11 deletions

View File

@ -57,7 +57,7 @@ class DeploymentLogTable extends QuickTable
'duration' => "l.duration_dump || 'ms'", 'duration' => "l.duration_dump || 'ms'",
); );
if ($this->connection->getDbType() === 'pgsql') { if ($this->connection->isPgsql()) {
$columns['checksum'] = "LOWER(ENCODE(c.checksum, 'hex'))"; $columns['checksum'] = "LOWER(ENCODE(c.checksum, 'hex'))";
} }

View File

@ -17,7 +17,7 @@ class GeneratedConfigFileTable extends QuickTable
'config_checksum' => 'LOWER(HEX(cf.config_checksum))', 'config_checksum' => 'LOWER(HEX(cf.config_checksum))',
); );
if ($this->connection->getDbType() === 'pgsql') { if ($this->connection->isPgsql()) {
$columns['checksum'] = "LOWER(ENCODE(f.checksum, 'hex'))"; $columns['checksum'] = "LOWER(ENCODE(f.checksum, 'hex'))";
$columns['config_checksum'] = "LOWER(ENCODE(cf.config_checksum, 'hex'))"; $columns['config_checksum'] = "LOWER(ENCODE(cf.config_checksum, 'hex'))";
} }

View File

@ -13,7 +13,7 @@ class IcingaHostTable extends IcingaObjectTable
public function getColumns() public function getColumns()
{ {
if ($this->connection()->getDbType() === 'pgsql') { if ($this->connection()->isPgsql()) {
$parents = "ARRAY_TO_STRING(ARRAY_AGG(ih.object_name ORDER BY hi.weight), ', ')"; $parents = "ARRAY_TO_STRING(ARRAY_AGG(ih.object_name ORDER BY hi.weight), ', ')";
} else { } else {
$parents = "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')"; $parents = "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')";

View File

@ -12,7 +12,7 @@ class IcingaZoneTable extends IcingaObjectTable
public function getColumns() public function getColumns()
{ {
if ($this->connection()->getDbType() === 'pgsql') { if ($this->connection()->isPgsql()) {
$endpoints = "ARRAY_TO_STRING(ARRAY_AGG(e.object_name), ', ')"; $endpoints = "ARRAY_TO_STRING(ARRAY_AGG(e.object_name), ', ')";
} else { } else {
$endpoints = "GROUP_CONCAT(e.object_name ORDER BY e.object_name SEPARATOR ', ')"; $endpoints = "GROUP_CONCAT(e.object_name ORDER BY e.object_name SEPARATOR ', ')";

View File

@ -629,7 +629,7 @@ abstract class DbObject
unset($properties[$this->autoincKeyName]); unset($properties[$this->autoincKeyName]);
} }
// TODO: Remove this! // TODO: Remove this!
if ($this->connection->getDbType() === 'pgsql') { if ($this->connection->isPgsql()) {
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
if (preg_match('/checksum$/', $key)) { if (preg_match('/checksum$/', $key)) {
$properties[$key] = Util::pgBinEscape($value); $properties[$key] = Util::pgBinEscape($value);
@ -688,7 +688,7 @@ abstract class DbObject
if ($this->insertIntoDb()) { if ($this->insertIntoDb()) {
$id = $this->getId(); $id = $this->getId();
if ($this->autoincKeyName) { if ($this->autoincKeyName) {
if ($this->connection->getDbType() === 'pgsql') { if ($this->connection->isPgsql()) {
$this->properties[$this->autoincKeyName] = $this->db->lastInsertId( $this->properties[$this->autoincKeyName] = $this->db->lastInsertId(
$table, $table,
$this->autoincKeyName $this->autoincKeyName

View File

@ -208,7 +208,7 @@ class Db extends DbConnection
public function fetchActivityLogIdByChecksum($checksum) public function fetchActivityLogIdByChecksum($checksum)
{ {
if ($this->getDbType() === 'pgsql') { if ($this->isPgsql()) {
$checksum = new Zend_Db_Expr("\\x" . bin2hex($checksum)); $checksum = new Zend_Db_Expr("\\x" . bin2hex($checksum));
} }
@ -218,7 +218,7 @@ class Db extends DbConnection
public function fetchActivityLogEntry($checksum) public function fetchActivityLogEntry($checksum)
{ {
if ($this->getDbType() === 'pgsql') { if ($this->isPgsql()) {
$checksum = new Zend_Db_Expr("\\x" . bin2hex($checksum)); $checksum = new Zend_Db_Expr("\\x" . bin2hex($checksum));
} }
@ -238,7 +238,7 @@ class Db extends DbConnection
public function getLastActivityChecksum() public function getLastActivityChecksum()
{ {
if ($this->getDbType() === 'pgsql') { if ($this->isPgsql()) {
$select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(ENCODE(checksum, 'hex')) AS checksum" $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(ENCODE(checksum, 'hex')) AS checksum"
. " FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a" . " FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a"
. " UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; . " UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1";
@ -419,7 +419,7 @@ class Db extends DbConnection
public function getLatestImportedChecksum($source) public function getLatestImportedChecksum($source)
{ {
if ($this->getDbType() === 'pgsql') { if ($this->isPgsql()) {
$col = "LOWER(ENCODE(rowset_checksum, 'hex'))"; $col = "LOWER(ENCODE(rowset_checksum, 'hex'))";
} else { } else {
$col = '(LOWER(HEX(import_run.rowset_checksum)))'; $col = '(LOWER(HEX(import_run.rowset_checksum)))';
@ -665,6 +665,11 @@ class Db extends DbConnection
return $this->db()->fetchAll($select); return $this->db()->fetchAll($select);
} }
public function isPgsql()
{
return $this->getDbType() === 'pgsql';
}
public function getUncollectedDeployments() public function getUncollectedDeployments()
{ {
$db = $this->db(); $db = $this->db();

View File

@ -186,7 +186,7 @@ class IcingaConfig
protected function dbBin($binary) protected function dbBin($binary)
{ {
if ($this->connection->getDbType() === 'pgsql') { if ($this->connection->isPgsql()) {
return Util::pgBinEscape($binary); return Util::pgBinEscape($binary);
} else { } else {
return $binary; return $binary;