? 780358-7_fix-change_errors.patch
Index: data_ui/data_ui.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/data/data_ui/data_ui.admin.inc,v
retrieving revision 1.25.2.16
diff -u -p -r1.25.2.16 data_ui.admin.inc
--- data_ui/data_ui.admin.inc	28 Jul 2010 19:03:15 -0000	1.25.2.16
+++ data_ui/data_ui.admin.inc	28 Jul 2010 20:12:07 -0000
@@ -953,7 +953,11 @@ function theme_data_ui_schema_compare_ta
  *
  * Otherwise return FALSE.
  *
- * Currently checked: type, unsigned
+ * Currently checked: type, unsigned, default.
+ *
+ * @todo This is insane, we need to use clean specs instead of converting
+ * existing specs. This will require us also to not allow changes to indexes,
+ * PKs and field specs on the same form.
  */
 function _data_ui_changed($new, $field) {
   $changed = FALSE;
@@ -966,6 +970,9 @@ function _data_ui_changed($new, $field) 
     $changed = TRUE;
   }
   if ($changed) {
+    if ($field['type'] == 'text') {
+      unset($field['default']);
+    }
     return $field;
   }
   return FALSE;
Index: includes/DataTable.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/data/includes/Attic/DataTable.inc,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 DataTable.inc
--- includes/DataTable.inc	28 Jul 2010 19:03:15 -0000	1.1.2.10
+++ includes/DataTable.inc	28 Jul 2010 20:12:07 -0000
@@ -357,9 +357,14 @@ class DataTable {
    */
   public function addPrimaryKey($fields) {
     $ret = array();
+    $schema = $this->table_schema;
+    foreach ($fields as $field) {
+      if ($schema['fields'][$field]['type'] == 'text') {
+        throw new DataException(t('A text field cannot be made a primary key.'));
+      }
+    }
     db_add_primary_key($ret, $this->name, $fields);
     if ($ret[0]['success']) {
-      $schema = $this->table_schema;
       $schema['primary key'] = $fields;
       $this->update(array('table_schema' => $schema));
       drupal_get_schema($this->name, TRUE);
@@ -408,8 +413,23 @@ class DataTable {
    */
   public function changeField($field, $spec) {
     $ret = array();
+    // If new type is text, check for PK and index restrictions.
+    if ($spec['type'] == 'text') {
+      if (in_array($field, $this->table_schema['primary key'])) {
+        throw new DataException(t('Cannot make a primary key field a text field.'));
+      }
+      foreach ($this->table_schema['indexes'] as $index_name => $index) {
+        foreach ($index as $index_field) {
+          if (is_array($index_field)) {
+            $index_field = array_shift($index_field);
+          }
+          if ($field == $index_field) {
+            $this->dropIndex($index_field);
+          }
+        }
+      }
+    }
     db_change_field($ret, $this->name, $field, $field, $spec);
-
     if ($ret[0]['success']) {
       $schema = $this->table_schema;
       $schema['fields'][$field] = $spec;
