+ }
+
+ /**
+ * Map a native type back to an independent type + size
+ *
+ * @param string $type
+ * @return array ($type, $size) -- $size may be null
+ */
+ protected function reverseMapType($type)
+ {
+ return array($type, null);
+ }
+
+ /**
+ * Convert an old-style set of ColumnDef objects into the current
+ * Drupal-style schema definition array, for backwards compatibility
+ * with plugins written for 0.9.x.
+ *
+ * @param string $tableName
+ * @param array $defs
+ * @return array
+ */
+ function oldToNew($tableName, $defs)
+ {
+ $table = array();
+ $prefixes = array(
+ 'tiny',
+ 'small',
+ 'medium',
+ 'big',
+ );
+ foreach ($defs as $cd) {
+ $cd->addToTableDef($table);
+ $column = array();
+ $column['type'] = $cd->type;
+ foreach ($prefixes as $prefix) {
+ if (substr($cd->type, 0, strlen($prefix)) == $prefix) {
+ $column['type'] = substr($cd->type, strlen($prefix));
+ $column['size'] = $prefix;
+ break;
+ }
+ }
+
+ if ($cd->size) {
+ if ($cd->type == 'varchar' || $cd->type == 'char') {
+ $column['length'] = $cd->size;
+ }
+ }
+ if (!$cd->nullable) {
+ $column['not null'] = true;
+ }
+ if ($cd->autoincrement) {
+ $column['type'] = 'serial';
+ }
+ if ($cd->default) {
+ $column['default'] = $cd->default;
+ }
+ $table['fields'][$cd->name] = $column;
+
+ if ($cd->key == 'PRI') {
+ // If multiple columns are defined as primary key,
+ // we'll pile them on in sequence.
+ if (!isset($table['primary key'])) {
+ $table['primary key'] = array();
+ }
+ $table['primary key'][] = $cd->name;
+ } else if ($cd->key == 'MUL') {
+ // Individual multiple-value indexes are only per-column
+ // using the old ColumnDef syntax.
+ $idx = "{$tableName}_{$cd->name}_idx";
+ $table['indexes'][$idx] = array($cd->name);
+ } else if ($cd->key == 'UNI') {
+ // Individual unique-value indexes are only per-column
+ // using the old ColumnDef syntax.
+ $idx = "{$tableName}_{$cd->name}_idx";
+ $table['unique keys'][$idx] = array($cd->name);
+ }
+ }
+
+ return $table;
+ }
+
+ function isNumericType($type)
+ {
+ $type = strtolower($type);
+ $known = array('int', 'serial', 'numeric');
+ return in_array($type, $known);
+ }
+
+ /**
+ * Pull info from the query into a fun-fun array of dooooom
+ *
+ * @param string $sql
+ * @return array of arrays
+ */
+ protected function fetchQueryData($sql)
+ {
+ $res = $this->conn->query($sql);
+ if (PEAR::isError($res)) {
+ throw new Exception($res->getMessage());