mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix issues with SQLServer + boolean columns.
SQLServer should not have lengths applied to BIT column types. Remove any length that could have been provided. Fixes #2439
This commit is contained in:
parent
ee7a224639
commit
4e67698506
2 changed files with 15 additions and 2 deletions
|
@ -656,12 +656,15 @@ class Sqlserver extends DboSource {
|
||||||
/**
|
/**
|
||||||
* Generate a database-native column schema string
|
* Generate a database-native column schema string
|
||||||
*
|
*
|
||||||
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
|
* @param array $column An array structured like the
|
||||||
|
* following: array('name'=>'value', 'type'=>'value'[, options]),
|
||||||
* where options can be 'default', 'length', or 'key'.
|
* where options can be 'default', 'length', or 'key'.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function buildColumn($column) {
|
public function buildColumn($column) {
|
||||||
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
$result = parent::buildColumn($column);
|
||||||
|
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', $result);
|
||||||
|
$result = preg_replace('/(bit)\([0-9]+\)/i', '$1', $result);
|
||||||
if (strpos($result, 'DEFAULT NULL') !== false) {
|
if (strpos($result, 'DEFAULT NULL') !== false) {
|
||||||
if (isset($column['default']) && $column['default'] === '') {
|
if (isset($column['default']) && $column['default'] === '') {
|
||||||
$result = str_replace('DEFAULT NULL', "DEFAULT ''", $result);
|
$result = str_replace('DEFAULT NULL', "DEFAULT ''", $result);
|
||||||
|
|
|
@ -543,6 +543,16 @@ class SqlserverTest extends CakeTestCase {
|
||||||
$result = $this->db->buildColumn($column);
|
$result = $this->db->buildColumn($column);
|
||||||
$expected = '[body] nvarchar(MAX)';
|
$expected = '[body] nvarchar(MAX)';
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$column = array(
|
||||||
|
'name' => 'checked',
|
||||||
|
'type' => 'boolean',
|
||||||
|
'length' => 10,
|
||||||
|
'default' => '1'
|
||||||
|
);
|
||||||
|
$result = $this->db->buildColumn($column);
|
||||||
|
$expected = "[checked] bit DEFAULT '1'";
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue