mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-26 11:19:14 +02:00
Database: Transform assembled binary values to hex format for pgsql
This commit is contained in:
parent
8ba46ac3d3
commit
997517dc8d
@ -5,8 +5,12 @@ namespace Icinga\Common;
|
|||||||
|
|
||||||
use Icinga\Application\Config as IcingaConfig;
|
use Icinga\Application\Config as IcingaConfig;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
|
use Icinga\Util\DBUtils;
|
||||||
|
use ipl\Sql\Adapter\Pgsql;
|
||||||
use ipl\Sql\Config as SqlConfig;
|
use ipl\Sql\Config as SqlConfig;
|
||||||
use ipl\Sql\Connection;
|
use ipl\Sql\Connection;
|
||||||
|
use ipl\Sql\Insert;
|
||||||
|
use ipl\Sql\QueryBuilder;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
@ -41,7 +45,29 @@ trait Database
|
|||||||
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
|
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Connection($config);
|
$conn = new Connection($config);
|
||||||
|
if ($conn->getAdapter() instanceof Pgsql) {
|
||||||
|
$valuesTransformer = function (&$values) {
|
||||||
|
DBUtils::transformValues($values);
|
||||||
|
};
|
||||||
|
|
||||||
|
$conn->getQueryBuilder()
|
||||||
|
->on(QueryBuilder::ON_DELETE_ASSEMBLED, $valuesTransformer)
|
||||||
|
->on(QueryBuilder::ON_UPDATE_ASSEMBLED, $valuesTransformer)
|
||||||
|
->on(QueryBuilder::ON_ASSEMBLE_INSERT, function (Insert $insert) {
|
||||||
|
$values = $insert->getValues();
|
||||||
|
foreach ($insert->getValues() as $key => $value) {
|
||||||
|
if (DBUtils::isBinary($value)) {
|
||||||
|
$values[$key] = DBUtils::getBinaryExpr($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$insert->values(array_combine($insert->getColumns(), $values));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user