]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/schema.php
Merge branch 'testing' into 0.9.x
[quix0rs-gnu-social.git] / lib / schema.php
index df7cb65f56db10c52f0a66f78ae79f48df0c4776..137b814e0269ed727978e11e55ce25cca763a199 100644 (file)
@@ -75,64 +75,14 @@ class Schema
 
     static function get()
     {
+        $type = common_config('db', 'type');
         if (empty(self::$_single)) {
-            self::$_single = new Schema();
+            $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)
-    {
-        $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)) {
-
-            $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.
      *
@@ -213,7 +163,7 @@ class Schema
 
         $sql .= "); ";
 
-        $res =& $this->conn->query($sql);
+        $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -234,7 +184,7 @@ class Schema
 
     public function dropTable($name)
     {
-        $res =& $this->conn->query("DROP TABLE $name");
+        $res = $this->conn->query("DROP TABLE $name");
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -269,7 +219,7 @@ class Schema
             $name = "$table_".implode("_", $columnNames)."_idx";
         }
 
-        $res =& $this->conn->query("ALTER TABLE $table ".
+        $res = $this->conn->query("ALTER TABLE $table ".
                                    "ADD INDEX $name (".
                                    implode(",", $columnNames).")");
 
@@ -291,7 +241,7 @@ class Schema
 
     public function dropIndex($table, $name)
     {
-        $res =& $this->conn->query("ALTER TABLE $table DROP INDEX $name");
+        $res = $this->conn->query("ALTER TABLE $table DROP INDEX $name");
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -314,7 +264,7 @@ class Schema
     {
         $sql = "ALTER TABLE $table ADD COLUMN " . $this->_columnSql($columndef);
 
-        $res =& $this->conn->query($sql);
+        $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -339,7 +289,7 @@ class Schema
         $sql = "ALTER TABLE $table MODIFY COLUMN " .
           $this->_columnSql($columndef);
 
-        $res =& $this->conn->query($sql);
+        $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -363,7 +313,7 @@ class Schema
     {
         $sql = "ALTER TABLE $table DROP COLUMN $columnName";
 
-        $res =& $this->conn->query($sql);
+        $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -446,7 +396,7 @@ class Schema
 
         $sql = 'ALTER TABLE ' . $tableName . ' ' . implode(', ', $phrase);
 
-        $res =& $this->conn->query($sql);
+        $res = $this->conn->query($sql);
 
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
@@ -524,6 +474,14 @@ class Schema
             $sql .= ($cd->nullable) ? "null " : "not null ";
         }
 
+        if (!empty($cd->auto_increment)) {
+            $sql .= " auto_increment ";
+        }
+
+        if (!empty($cd->extra)) {
+            $sql .= "{$cd->extra} ";
+        }
+
         return $sql;
     }
 }