Use pg_ functions to avoid two more startup queries
authorchriskl <chriskl>
Thu, 2 Jun 2005 11:31:02 +0000 (11:31 +0000)
committerchriskl <chriskl>
Thu, 2 Jun 2005 11:31:02 +0000 (11:31 +0000)
HISTORY
classes/database/Postgres.php
libraries/lib.inc.php

diff --git a/HISTORY b/HISTORY
index 20c5ae8c8c09c6a6577821e9968a6f417899bbc4..f08863a0970bd00ad09aacb795783a026fa59ad5 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -19,6 +19,7 @@ Features
 * Rearrange frame layout to suit multi-server support
 * New browser tree with dynamically loading branches
   (Using XLoadTree2 from http://webfx.eae.net/)
+* Avoid getting and setting encoding queries if possible
 * Allow language change from the intro page at any time
   
 Bugs
index cf8c28d3c2ae23a0b24697ae0cc10ad9fb65f8cf..f6177ee381e20907d8e4fd88d54b125d5a2250de 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.261 2005/05/02 15:47:26 chriskl Exp $
+ * $Id: Postgres.php,v 1.262 2005/06/02 11:31:02 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -466,6 +466,12 @@ class Postgres extends ADODB_base {
         * @return The encoding.  eg. SQL_ASCII, UTF-8, etc.
         */
        function getDatabaseEncoding() {
+               // Try to avoid a query if at all possible (5)
+               if (function_exists('pg_parameter_status')) {
+                       $encoding = pg_parameter_status($this->conn->_connectionID, 'server_encoding');
+                       if ($encoding !== false) return $encoding;
+               }
+               
                $sql = "SELECT getdatabaseencoding() AS encoding";
                
                return $this->selectField($sql, 'encoding');
index 79ab471370b4aa2cbaa3265ce6c08bc278b4c7b0..0070c7287c1005958efa24f53a8f9521e44ae313 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Function library read in upon startup
         *
-        * $Id: lib.inc.php,v 1.94 2005/05/02 15:47:28 chriskl Exp $
+        * $Id: lib.inc.php,v 1.95 2005/06/02 11:31:03 chriskl Exp $
         */
        include_once('decorator.inc.php');
        include_once('./lang/translations.php');
                
                // Set client encoding to database encoding
                if ($dbEncoding != '') {
-                       $status = $data->setClientEncoding($dbEncoding);
-                       if ($status != 0 && $status != -99) {
-                               echo $lang['strbadencoding'];
-                               exit;
+                       // Explicitly change client encoding if it's different to server encoding.
+                       if (pg_client_encoding($data->conn->_connectionID) != $dbEncoding) {
+                               $status = $data->setClientEncoding($dbEncoding);
+                               if ($status != 0 && $status != -99) {
+                                       echo $lang['strbadencoding'];
+                                       exit;
+                               }
                        }
-               
+                                       
                        // Override $lang['appcharset']
                        if (isset($data->codemap[$dbEncoding]))
                                $lang['appcharset'] = $data->codemap[$dbEncoding];