Fixed broken code.
[lhc/web/wiklou.git] / includes / DatabasePostgreSQL.php
index e257dc3..f38b70c 100644 (file)
@@ -53,6 +53,8 @@ class DatabasePgsql extends Database {
                        die( "PostgreSQL functions missing, have you compiled PHP with the --with-pgsql option?\n" );
                }
 
+               global $wgDBschema;
+
                $this->close();
                $this->mServer = $server;
                $this->mUser = $user;
@@ -75,6 +77,7 @@ class DatabasePgsql extends Database {
                        } else { 
                                $this->mOpened = true;
                        }
+                       $this->query("SET search_path = $wgDBschema,public");
                }
                return $this->mConn;
        }
@@ -350,8 +353,17 @@ class DatabasePgsql extends Database {
        # Returns the size of a text field, or -1 for "unlimited"
        function textFieldSize( $table, $field ) {
                $table = $this->tableName( $table );
-               $res = $this->query( "SELECT $field FROM $table LIMIT 1", "Database::textFieldLength" );
-               $size = pg_field_size( $res, 0 );
+               $sql = "SELECT t.typname as ftype,a.atttypmod as size
+                       FROM pg_class c, pg_attribute a, pg_type t 
+                       WHERE relname='$table' AND a.attrelid=c.oid AND 
+                               a.atttypid=t.oid and a.attname='$field'";
+               $res =$this->query($sql);
+               $row=$this->fetchObject($res);
+               if ($row->ftype=="varchar") {
+                       $size=$row->size-4;     
+               } else {
+                       $size=$row->size;
+               }
                $this->freeResult( $res );
                return $size;
        }