]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/schema.php
Installer tweak to aid with IIS setup: if config.php exists, but is both empty and...
[quix0rs-gnu-social.git] / lib / schema.php
index c1636c21d827a6070e6d6c16ba094bc973606d1f..1503c96d4fc9cb28744aa13cc8ed0580d679f6f1 100644 (file)
@@ -77,74 +77,12 @@ class Schema
     {
         $type = common_config('db', 'type');
         if (empty(self::$_single)) {
-            include "lib/schema.{$type}.php";
-            $class = $type.='Schema';
-            self::$_single = new $class();
+            $schemaClass = ucfirst($type).'Schema';
+            self::$_single = new $schemaClass();
         }
         return self::$_single;
     }
 
-    /**
-     * Returns a TableDef object for the table
-     * in the schema with the given name.
-     *
-     * Throws an exception if the table is not found.
-     *
-     * @param string $name Name of the table to get
-     *
-     * @return TableDef tabledef for that table.
-     */
-
-    public function getTableDef($name)
-    {
-        if(common_config('db','type') == 'pgsql') {
-            $res = $this->conn->query("select column_default as default, is_nullable as Null, udt_name as Type, column_name AS Field from INFORMATION_SCHEMA.COLUMNS where table_name = '$name'");
-        }
-        else { 
-            $res = $this->conn->query('DESCRIBE ' . $name);
-        }
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        $td = new TableDef();
-
-        $td->name    = $name;
-        $td->columns = array();
-
-        $row = array();
-
-        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
-            //lower case the keys, because the php postgres driver is case insentive for column names
-           foreach($row as $k=>$v) {
-               $row[strtolower($k)] = $row[$k];
-            }
-
-            $cd = new ColumnDef();
-
-            $cd->name = $row['field'];
-
-            $packed = $row['type'];
-
-            if (preg_match('/^(\w+)\((\d+)\)$/', $packed, $match)) {
-                $cd->type = $match[1];
-                $cd->size = $match[2];
-            } else {
-                $cd->type = $packed;
-            }
-
-            $cd->nullable = ($row['null'] == 'YES') ? true : false;
-            $cd->key      = $row['Key'];
-            $cd->default  = $row['default'];
-            $cd->extra    = $row['Extra'];
-
-            $td->columns[] = $cd;
-        }
-
-        return $td;
-    }
-
     /**
      * Gets a ColumnDef object for a single column.
      *
@@ -535,7 +473,7 @@ class Schema
         } else {
             $sql .= ($cd->nullable) ? "null " : "not null ";
         }
-        
+
         if (!empty($cd->auto_increment)) {
             $sql .= " auto_increment ";
         }
@@ -547,3 +485,9 @@ class Schema
         return $sql;
     }
 }
+
+class SchemaTableMissingException extends Exception
+{
+    // no-op
+}
+