From 7a5cda86c20b97ac5430b7046b9957b3588f2017 Mon Sep 17 00:00:00 2001 From: zYne Date: Sun, 19 Nov 2006 22:20:46 +0000 Subject: [PATCH] added getServerVersion to pgsql driver --- lib/Doctrine/Connection/Pgsql.php | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index 9cba1a8dc..fe6e24117 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -137,4 +137,40 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { } return $query; } + /** + * return version information about the server + * + * @param string $native determines if the raw version string should be returned + * @return array|string an array or string with version information + */ + public function getServerVersion($native = false) { + $query = 'SHOW SERVER_VERSION'; + + $serverInfo = $this->fetchOne($query); + + if( ! $native) { + $tmp = explode('.', $server_info, 3); + + if(empty($tmp[2]) && isset($tmp[1]) + && preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) { + + $serverInfo = array( + 'major' => $tmp[0], + 'minor' => $tmp2[1], + 'patch' => null, + 'extra' => $tmp2[2], + 'native' => $serverInfo, + ); + } else { + $serverInfo = array( + 'major' => isset($tmp[0]) ? $tmp[0] : null, + 'minor' => isset($tmp[1]) ? $tmp[1] : null, + 'patch' => isset($tmp[2]) ? $tmp[2] : null, + 'extra' => null, + 'native' => $serverInfo, + ); + } + } + return $serverInfo; + } }