Skip to content

Commit c2549fa

Browse files
committed
UnreachableParent: Use driver specific types in CAST expressions
1 parent 8d39fa3 commit c2549fa

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;
@@ -115,15 +116,23 @@ public static function on(Connection $db, Model $root = null): Query
115116

116117
private static function selectNodes(Connection $db, Model $root): Select
117118
{
119+
if ($db->getAdapter() instanceof Pgsql) {
120+
$binaryCast = "CAST('00000000000000000000' AS bytea20)";
121+
$booleanCast = "CAST('0' AS boolean)";
122+
} else {
123+
$binaryCast = "CAST('' AS binary(20))";
124+
$booleanCast = '0';
125+
}
126+
118127
$rootQuery = DependencyNode::on($db)
119128
->columns([
120129
'id' => 'id',
121130
'child_id' => 'id',
122131
'level' => new Expression('0'),
123132
'host_id' => 'host_id',
124-
'service_id' => new Expression("COALESCE(%s, CAST('' as binary(20)))", ['service_id']),
125-
'redundancy_group_id' => new Expression("CAST('' as binary(20))"),
126-
'is_group_member' => new Expression('0')
133+
'service_id' => new Expression("COALESCE(%s, $binaryCast)", ['service_id']),
134+
'redundancy_group_id' => new Expression($binaryCast),
135+
'is_group_member' => new Expression($booleanCast)
127136
]);
128137
if ($root instanceof Host) {
129138
$rootQuery->filter(Filter::all(

0 commit comments

Comments
 (0)