Skip to content
Permalink
Browse files

Add support for fixed length strings.

This flag is useful for indicating the difference between varchar + char
fields. In some databases (mysql) the performance characteristics
between char & varchar are important.
  • Loading branch information...
markstory committed May 2, 2013
1 parent b5f7e59 commit 55251e5ebbcc3e2f6a9159ab2644b56ecd2598f0
@@ -66,7 +66,7 @@ public function describeTableSql($table) {
* The returned type will be a type that Cake\Database\Type can handle.
*
* @param string $column The column type + length
* @return array List of (type, length)
* @return array Array of column information.
*/
public function convertColumn($column) {
preg_match('/([a-z]+)(?:\(([0-9,]+)\))?/i', $column, $matches);
@@ -92,6 +92,9 @@ public function convertColumn($column) {
if (strpos($col, 'int') !== false) {
return ['type' => 'integer', 'length' => $length];
}
if ($col === 'char') {
return ['type' => 'string', 'fixed' => true, 'length' => $length];
}
if (strpos($col, 'char') !== false || $col === 'tinytext') {
return ['type' => 'string', 'length' => $length];
}
@@ -74,10 +74,21 @@ public function describeTableSql($table, $config) {
* Cake\Database\Type can handle.
*
* @param string $column The column type + length
* @throws Cake\Error\Exception when column cannot be parsed.
* @return array Array of column information.
*/
public function convertColumn($column) {
$col = strtolower($column);
preg_match('/([a-z\s]+)(?:\(([0-9,]+)\))?/i', $column, $matches);
if (empty($matches)) {
throw new Error\Exception(__d('cake_dev', 'Unable to parse column type from "%s"', $column));
}
$col = strtolower($matches[1]);
$length = null;
if (isset($matches[2])) {
$length = (int)$matches[2];
}
if (in_array($col, array('date', 'time', 'boolean'))) {
return ['type' =>$col, 'length' => null];
}
@@ -99,8 +110,11 @@ public function convertColumn($column) {
if ($col === 'uuid') {
return ['type' => 'string', 'length' => 36];
}
if ($col === 'char' || $col === 'character') {
return ['type' => 'string', 'fixed' => true, 'length' => $length];
}
if (strpos($col, 'char') !== false) {
return ['type' => 'string', 'length' => null];
return ['type' => 'string', 'length' => $length];
}
if (strpos($col, 'text') !== false) {
return ['type' => 'text', 'length' => null];
@@ -71,6 +71,9 @@ public function convertColumn($column) {
if (strpos($col, 'int') !== false) {
return ['type' => 'integer', 'length' => $length];
}
if ($col === 'char') {
return ['type' => 'string', 'fixed' => true, 'length' => $length];
}
if (strpos($col, 'char') !== false) {
return ['type' => 'string', 'length' => $length];
}
@@ -79,7 +79,7 @@ public static function columnProvider() {
],
[
'CHAR(25)',
['type' => 'string', 'length' => 25]
['type' => 'string', 'length' => 25, 'fixed' => true]
],
[
'TINYTEXT',
@@ -128,21 +128,29 @@ public static function columnProvider() {
'VARCHAR',
['type' => 'string', 'length' => null]
],
[
'VARCHAR(10)',
['type' => 'string', 'length' => 10]
],
[
'CHARACTER VARYING',
['type' => 'string', 'length' => null]
],
[
'CHAR',
['type' => 'string', 'length' => null]
'CHARACTER VARYING(10)',
['type' => 'string', 'length' => 10]
],
[
'UUID',
['type' => 'string', 'length' => 36]
'CHAR(10)',
['type' => 'string', 'fixed' => true, 'length' => 10]
],
[
'CHARACTER',
['type' => 'string', 'length' => null]
'CHARACTER(10)',
['type' => 'string', 'fixed' => true, 'length' => 10]
],
[
'UUID',
['type' => 'string', 'length' => 36]
],
[
'INET',
@@ -71,7 +71,7 @@ public static function columnProvider() {
],
[
'CHAR(25)',
['type' => 'string', 'length' => 25]
['type' => 'string', 'fixed' => true, 'length' => 25]
],
[
'BLOB',

0 comments on commit 55251e5

Please sign in to comment.
You can’t perform that action at this time.