Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- change check to strict for `options` of `$fieldParameters`

- add `types` parameter and strict check if it present in `$fieldParameters` (if it present and not contain column type field parameter will be skipped)
- add `noVal` parameter to `$fieldParameters` if it present and not empty value of this parameter from column will be ignored
- add `unsigned` column type for integer, float and biginteger. If it set to `true` an 'UNSIGNED' will be add in sql column part, if not set or set not to `true` this parameter will be skipped
  • Loading branch information...
commit 2fcb4c3c6cbdd5e95ef5927d3aa38a6f869d565f 1 parent 3ddbddc
imsamurai authored
View
8 lib/Cake/Model/Datasource/Database/Mysql.php
@@ -86,7 +86,13 @@ class Mysql extends DboSource {
public $fieldParameters = array(
'charset' => array('value' => 'CHARACTER SET', 'quote' => false, 'join' => ' ', 'column' => false, 'position' => 'beforeDefault'),
'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collation', 'position' => 'beforeDefault'),
- 'comment' => array('value' => 'COMMENT', 'quote' => true, 'join' => ' ', 'column' => 'Comment', 'position' => 'afterDefault')
+ 'comment' => array('value' => 'COMMENT', 'quote' => true, 'join' => ' ', 'column' => 'Comment', 'position' => 'afterDefault'),
+ 'unsigned' => array(
+ 'value' => 'UNSIGNED', 'quote' => false, 'join' => ' ', 'column' => false, 'position' => 'afterDefault',
+ 'noVal' => true,
+ 'options' => array(true),
+ 'types' => array('integer', 'float', 'biginteger')
+ )
);
/**
View
8 lib/Cake/Model/Datasource/DboSource.php
@@ -3142,14 +3142,18 @@ public function buildColumn($column) {
protected function _buildFieldParameters($columnString, $columnData, $position) {
foreach ($this->fieldParameters as $paramName => $value) {
if (isset($columnData[$paramName]) && $value['position'] == $position) {
- if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) {
+ if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'], true)) {
continue;
}
+ if (isset($value['types']) && !in_array($columnData['type'], $value['types'], true)) {
+ continue;
+ }
+
$val = $columnData[$paramName];
if ($value['quote']) {
$val = $this->value($val);
}
- $columnString .= ' ' . $value['value'] . $value['join'] . $val;
+ $columnString .= ' ' . $value['value'] . (empty($value['noVal']) ? $value['join'] . $val : '');
}
}
return $columnString;
View
94 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
@@ -3154,6 +3154,100 @@ public function testBuildColumnBadType() {
);
$this->Dbo->buildColumn($data);
}
+
+
+/**
+ * testBuildColumn3 method
+ *
+ * @param array $data Column data
+ * @param string $expected Expected sql part
+ *
+ * @return void
+ *
+ * @dataProvider buildColumn3Provider
+ */
+ public function testBuildColumn3($data, $expected) {
+ $restore = $this->Dbo->columns;
+ $this->Dbo->columns = array('string' => 1, 'integer' => 1, 'float' => 1, 'biginteger' => 1, 'any' => 1);
+
+ $result = $this->Dbo->buildColumn($data);
+ $this->assertEquals($expected, $result);
+
+ $this->Dbo->columns = $restore;
+ }
+
+/**
+ * Data provider testBuildColumn3 method
+ *
+ * @return array
+ */
+ public function buildColumn3Provider() {
+ return array(
+ //set #0
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'integer',
+ 'unsigned' => true
+ ),
+ '`testName` UNSIGNED'
+ ),
+ //set #1
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'biginteger',
+ 'unsigned' => true
+ ),
+ '`testName` UNSIGNED'
+ ),
+ //set #2
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'float',
+ 'unsigned' => true
+ ),
+ '`testName` UNSIGNED'
+ ),
+ //set #3
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'string',
+ 'unsigned' => true
+ ),
+ '`testName` '
+ ),
+ //set #4
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'any',
+ 'unsigned' => true
+ ),
+ '`testName` '
+ ),
+ //set #5
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'any',
+ 'unsigned' => false
+ ),
+ '`testName` '
+ ),
+ //set #6
+ array(
+ array(
+ 'name' => 'testName',
+ 'type' => 'integer',
+ 'unsigned' => false
+ ),
+ '`testName` '
+ )
+ );
+ }
/**
* test hasAny()
Please sign in to comment.
Something went wrong with that request. Please try again.