Skip to content

Commit 30436ce

Browse files
committed
UnreachableParent: Use driver specific types in CAST expressions
1 parent 8a4fa0b commit 30436ce

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

library/Icingadb/Model/UnreachableParent.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ipl\Orm\Model;
1212
use ipl\Orm\Query;
1313
use ipl\Orm\Relations;
14+
use ipl\Sql\Adapter\Pgsql;
1415
use ipl\Sql\Connection;
1516
use ipl\Sql\Expression;
1617
use ipl\Sql\Select;
@@ -102,15 +103,23 @@ public static function on(Connection $db, Model $root = null): Query
102103

103104
private static function selectNodes(Connection $db, Model $root): Select
104105
{
106+
if ($db->getAdapter() instanceof Pgsql) {
107+
$binaryCast = "CAST('00000000000000000000' AS bytea20)";
108+
$booleanCast = "CAST('0' AS boolean)";
109+
} else {
110+
$binaryCast = "CAST('' AS binary(20))";
111+
$booleanCast = '0';
112+
}
113+
105114
$rootQuery = DependencyNode::on($db)
106115
->columns([
107116
'id' => 'id',
108117
'child_id' => 'id',
109118
'level' => new Expression('0'),
110119
'host_id' => 'host_id',
111-
'service_id' => new Expression("COALESCE(%s, CAST('' as binary(20)))", ['service_id']),
112-
'redundancy_group_id' => new Expression("CAST('' as binary(20))"),
113-
'is_group_member' => new Expression('0')
120+
'service_id' => new Expression("COALESCE(%s, $binaryCast)", ['service_id']),
121+
'redundancy_group_id' => new Expression($binaryCast),
122+
'is_group_member' => new Expression($booleanCast)
114123
]);
115124
if ($root instanceof Host) {
116125
$rootQuery->filter(Filter::all(

0 commit comments

Comments
 (0)