add db::setSchema() for specifying additional database namespaces.
authorDomas Mituzas <midom@users.mediawiki.org>
Thu, 30 Sep 2004 18:56:10 +0000 (18:56 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Thu, 30 Sep 2004 18:56:10 +0000 (18:56 +0000)
allows easy putting of external modules in separate logical namespaces.

includes/DatabasePostgreSQL.php

index f38b70c..d2b8599 100644 (file)
@@ -60,6 +60,7 @@ class DatabasePgsql extends Database {
                $this->mUser = $user;
                $this->mPassword = $password;
                $this->mDBname = $dbName;
+               $this->mSchemas = array($wgDBschema,'public');
                
                $success = false;
                
@@ -75,9 +76,9 @@ class DatabasePgsql extends Database {
                                wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
                                wfDebug( $this->lastError()."\n" );
                        } else { 
+                               $this->setSchema();
                                $this->mOpened = true;
                        }
-                       $this->query("SET search_path = $wgDBschema,public");
                }
                return $this->mConn;
        }
@@ -255,7 +256,7 @@ class DatabasePgsql extends Database {
        }
 
        function strencode( $s ) {
-               return pg_escape_string( $s );
+               return addslashes( $s );
        }
 
        /**
@@ -432,6 +433,13 @@ class DatabasePgsql extends Database {
                $this->freeResult( $res );
                return $version;
        }
+
+       function setSchema($schema=false) {
+               $schemas=$this->mSchemas;
+               if ($schema) { array_unshift($schemas,$schema); }
+               $searchpath=$this->makeList($schemas,LIST_NAMES);
+               $this->query("SET search_path = $searchpath");
+       }
 }
 
 /**