From f0541f6562c81112b49712dd7f2c513c7f161edd Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Wed, 6 Jul 2011 18:41:13 -0400
Subject: [PATCH] Issue #1211294 by pillarsdotnet: Fix various bogus warnings in schema compare.

---
 engines/mysql.inc |   17 +++++++++++++++--
 schema.module     |   16 +++++++++++-----
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/engines/mysql.inc b/engines/mysql.inc
index f86aaa35dda357994a108255554f8b59c781fad2..21592885aca2dafa542353922968fb3c40e2117a 100644
--- a/engines/mysql.inc
+++ b/engines/mysql.inc
@@ -28,6 +28,15 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
     return $map;
   }
 
+  public function getFieldTypeMap() {
+    static $map;
+    if (!isset($map)) {
+      $map = parent::getFieldTypeMap();
+      $map['datetime:normal'] = 'DATETIME';
+    }
+    return $map;
+  }
+
   public function inspect($connection = 'default', $name = NULL) {
     // Get the current database name
     $info = Database::getConnectionInfo($connection);
@@ -67,8 +76,12 @@ class SchemaDatabaseSchema_mysql extends DatabaseSchema_mysql {
         list($col['type'], $col['size']) = schema_schema_type($matches[1], $r->table_name, $r->column_name, 'mysql');
         if (isset($matches[2])) {
           if ($col['type'] == 'numeric' || $col['type'] == 'float' || $col['type'] == 'double') {
-            $col['precision'] = $matches[2];
-            $col['scale'] = $matches[3];
+            if ($matches[2]) {
+              $col['precision'] = $matches[2];
+            }
+            if ($matches[3]) {
+              $col['scale'] = $matches[3];
+            }
           }
           elseif (!$numeric) {
             $col['length'] = $matches[2];
diff --git a/schema.module b/schema.module
index 43f6ac31820b902860a322f0708f80278c8c7242..5d0e31fb33035de9f3cec57581bfa8f65a1f5b79 100755
--- a/schema.module
+++ b/schema.module
@@ -360,6 +360,10 @@ function schema_compare_table($ref, $inspect = NULL) {
       $reasons[] = "$colname: not in database";
       continue;
     }
+    else {
+      $inspect['fields'][$colname]['type'] = strtolower($inspect['fields'][$colname]['type']);
+      $col['type'] = strtolower($col['type']);
+    }
 
     // Account for schemas that contain unnecessary 'default' => NULL
     if (!isset($col['default']) ||
@@ -610,11 +614,13 @@ function schema_compare() {
   // The info array is keyed by state (same/different/missing/extra/warn). For missing,
   // the value is a simple array of table names. For warn, it is a simple array of warnings.
   // Get those out of the way first
-  $warnings = $info['warn'];
-  foreach ($warnings as $message) {
-    drupal_set_message($message, 'warning');
+  if (isset($info['warn'])) {
+    $warnings = $info['warn'];
+    foreach ($warnings as $message) {
+      drupal_set_message($message, 'warning');
+    }
+    unset($info['warn']);
   }
-  unset($info['warn']);
 
   $form['extra'] = array(
     '#type' => 'fieldset',
@@ -629,7 +635,7 @@ function schema_compare() {
   );
   $form['extra']['tablelist'] = array(
     '#theme' => 'item_list',
-    '#items' => $info['extra'],
+    '#items' => isset($info['extra']) ? $info['extra'] : array(),
   );
   unset($info['extra']);
 
-- 
1.7.4.1

