mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-23 05:44:37 +02:00
DbHelper: new trait with DB-specific utils
This commit is contained in:
parent
5579a927ad
commit
7258b83dbb
43
library/Director/Web/Table/DbHelper.php
Normal file
43
library/Director/Web/Table/DbHelper.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
trait DbHelper
|
||||
{
|
||||
public function dbHexFunc($column)
|
||||
{
|
||||
if ($this->isPgsql()) {
|
||||
return sprintf("LOWER(ENCODE(%s, 'hex'))", $column);
|
||||
} else {
|
||||
return sprintf("LOWER(HEX(%s))", $column);
|
||||
}
|
||||
}
|
||||
|
||||
public function quoteBinary($binary)
|
||||
{
|
||||
if ($this->isPgsql()) {
|
||||
return new Expr("'\\x" . bin2hex($binary) . "'");
|
||||
}
|
||||
|
||||
return $binary;
|
||||
}
|
||||
|
||||
public function isPgsql()
|
||||
{
|
||||
return $this->db->getConfig() instanceof \Zend_Db_Adapter_Pdo_Pgsql;
|
||||
}
|
||||
|
||||
public function isMysql()
|
||||
{
|
||||
return $this->db->getConfig() instanceof \Zend_Db_Adapter_Pdo_Mysql;
|
||||
}
|
||||
|
||||
public function wantBinaryValue($value)
|
||||
{
|
||||
if (is_resource($value)) {
|
||||
return stream_get_contents($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user