From efc586da77e041f3c9b68b33aa84af9380fda6de Mon Sep 17 00:00:00 2001
From: mrded <mrded@556088.no-reply.drupal.org>
Date: Wed, 18 Dec 2013 15:02:50 +0000
Subject: [PATCH] Schema module reporting some Date discrepancies

---
 engines/mysql.inc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 engines/pgsql.inc | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)

diff --git a/engines/mysql.inc b/engines/mysql.inc
index 545423c..eb2734c 100644
--- a/engines/mysql.inc
+++ b/engines/mysql.inc
@@ -146,4 +146,51 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
     return $tables;
   }
 
+  /**
+   * Get parent's type mapping and add missing
+   * 3rd-party module defined types.
+   *
+   * @return array
+   *   An array with engine-specific type mappings.
+   */
+  public function getFieldTypeMap() {
+    static $map = null;
+
+    if (!$map) {
+      // Get our parent class mapping first.
+      $map = parent::getFieldTypeMap();
+      $db_type = db_driver() . '_type';
+
+      // Load all table schema fields. This has the effect of
+      //  loading in any 3rd-party module field_schemas.
+      $include_additional = array(
+        'include_deleted' => TRUE,
+        'include_inactive' => TRUE
+      );
+      $fields = field_read_fields(array(), $include_additional);
+
+      foreach ($fields as $field) {
+        $cols = $field['columns'];
+
+        // Loop through each column and add any missing mappings.
+        foreach ($cols as $col) {
+          // Schema API says "type" is a required field - bail if it's missing.
+          if (!isset($col['type'])) {
+            continue;
+          }
+          $type = $col['type'];
+          $size = (isset($col['size']) ? $col['size'] : 'normal');
+          $generic_type = $type . ':' . $size;
+          if (!isset($map[$generic_type])) {
+            // Use engine specific type if it exists.
+            $map[$generic_type] = isset($col[$db_type]) ? $col[$db_type] : $type;
+            $map[$generic_type] = drupal_strtoupper($map[$generic_type]);
+          }
+        }
+      }
+    }
+
+    return $map;
+  }
+
 }
diff --git a/engines/pgsql.inc b/engines/pgsql.inc
index 4b702b5..4896fd2 100644
--- a/engines/pgsql.inc
+++ b/engines/pgsql.inc
@@ -240,5 +240,51 @@ class SchemaDatabaseSchema_pgsql extends DatabaseSchema_pgsql {
     return $tables;
   }
 
+  /**
+   * Get parent's type mapping and add missing
+   * 3rd-party module defined types.
+   *
+   * @return array
+   *   An array with engine-specific type mappings.
+   */
+  public function getFieldTypeMap() {
+    static $map = null;
+
+    if (!$map) {
+      // Get our parent class mapping first.
+      $map = parent::getFieldTypeMap();
+      $db_type = db_driver() . '_type';
+
+      // Load all table schema fields. This has the effect of
+      //  loading in any 3rd-party module field_schemas.
+      $include_additional = array(
+        'include_deleted' => TRUE,
+        'include_inactive' => TRUE
+      );
+      $fields = field_read_fields(array(), $include_additional);
+
+      foreach ($fields as $field) {
+        $cols = $field['columns'];
+
+        // Loop through each column and add any missing mappings.
+        foreach ($cols as $col) {
+          // Schema API says "type" is a required field - bail if it's missing.
+          if (!isset($col['type'])) {
+            continue;
+          }
+          $type = $col['type'];
+          $size = (isset($col['size']) ? $col['size'] : 'normal');
+          $generic_type = $type . ':' . $size;
+          if (!isset($map[$generic_type])) {
+            // Use engine specific type if it exists.
+            $map[$generic_type] = isset($col[$db_type]) ? $col[$db_type] : $type;
+            $map[$generic_type] = drupal_strtoupper($map[$generic_type]);
+          }
+        }
+      }
+    }
+
+    return $map;
+  }
 
 }
-- 
1.8.3.4 (Apple Git-47)

