From 3fe767144206a8638ccb1bdf8a8b4ba7d0e3e2f1 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 19 Sep 2012 17:27:09 +1200 Subject: [PATCH] FIX: Conditional revert of 06f80d33479fef1c78a870674dc62b67c3653730 as the original code is necessary in some configurations. Now we have the magic of an if block to guide us. --- code/PostgreSQLDatabase.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 85ca843..3e0de0a 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1117,9 +1117,26 @@ class PostgreSQLDatabase extends SS_Database { "SELECT tgargs FROM pg_catalog.pg_trigger WHERE tgname='%s'", $this->addslashes($triggerName) ))->first(); - $argList = explode('\000', $trigger['tgargs']); - array_pop($argList); - + // Option 1: output as a string + if(strpos($trigger['tgargs'],'\000') !== false) { + $argList = explode('\000', $trigger['tgargs']); + array_pop($argList); + + // Option 2: hex-encoded (not sure why this happens, depends on PGSQL config) + } else { + $bytes = str_split($trigger['tgargs'],2); + $argList = array(); + $nextArg = ""; + foreach($bytes as $byte) { + if($byte == "00") { + $argList[] = $nextArg; + $nextArg = ""; + } else { + $nextArg .= chr(hexdec($byte)); + } + } + } + // Drop first two arguments (trigger name and config name) and implode into nice list return array_slice($argList, 2); }