Cast number defaults to integer/float.
authorJan Schneider <jan@horde.org>
Fri, 21 Jan 2011 13:13:53 +0000 (14:13 +0100)
committerJan Schneider <jan@horde.org>
Fri, 21 Jan 2011 13:31:32 +0000 (14:31 +0100)
framework/Db/lib/Horde/Db/Adapter/Base/Schema.php
framework/Db/lib/Horde/Db/Adapter/Mysql/Schema.php

index f86d482..c70e618 100644 (file)
@@ -172,6 +172,10 @@ abstract class Horde_Db_Adapter_Base_Schema
             return $this->_adapter->quoteString($type == 'integer'
                                                 ? $value->format('U')
                                                 : $value->format('Y-m-d H:i:s'));
+        } elseif ($type == 'integer') {
+            return (int)$value;
+        } elseif ($type == 'float') {
+            return (float)$value;
         } else {
             /*@TODO
           when String, ActiveSupport::Multibyte::Chars
index af7a3c6..1827350 100644 (file)
@@ -261,14 +261,14 @@ class Horde_Db_Adapter_Mysql_Schema extends Horde_Db_Adapter_Base_Schema
                        $quotedTableName,
                        $this->quoteString($columnName));
         $res = $this->selectOne($sql);
-        $currentType = $res['Type'];
+        $column = $this->makeColumn($columnName, $res['Default'], $res['Type'], $res['Null'] == 'YES');
 
-        $default = $this->quote($default);
+        $default = $this->quote($default, $column);
         $sql = sprintf('ALTER TABLE %s CHANGE %s %s %s DEFAULT %s',
                        $quotedTableName,
                        $quotedColumnName,
                        $quotedColumnName,
-                       $currentType,
+                       $res['Type'],
                        $default);
         return $this->execute($sql);
     }
@@ -292,6 +292,7 @@ class Horde_Db_Adapter_Mysql_Schema extends Horde_Db_Adapter_Base_Schema
                            $this->quoteString($columnName));
             $row = $this->selectOne($sql);
             $options['default'] = $row['Default'];
+            $options['column'] = $this->makeColumn($columnName, $row['Default'], $row['Type'], $row['Null'] == 'YES');
         }
 
         $limit     = !empty($options['limit'])     ? $options['limit']     : null;