]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/schema.php
Ticket #2273: Fix bookmarklet with URls with special characters
[quix0rs-gnu-social.git] / lib / schema.php
index a8ba91b87fcde9ab1132db0ac81ad0c30c7e53d4..1503c96d4fc9cb28744aa13cc8ed0580d679f6f1 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.
      *
@@ -524,6 +474,20 @@ 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;
     }
 }
+
+class SchemaTableMissingException extends Exception
+{
+    // no-op
+}
+