Unverified Commit b075331d authored by belgattitude's avatar belgattitude Committed by Luís Cobucci

Removes introduced quoting literal support

parent d2543cab
......@@ -2281,7 +2281,7 @@ abstract class AbstractPlatform
$default = $field['default'];
if ( ! isset($field['type'])) {
return ' DEFAULT ' . $this->quoteStringLiteral($default);
return " DEFAULT '" . $default . "'";
}
$type = $field['type'];
......@@ -2306,7 +2306,7 @@ abstract class AbstractPlatform
return " DEFAULT '" . $this->convertBooleans($default) . "'";
}
return ' DEFAULT ' . $this->quoteStringLiteral($default);
return " DEFAULT '" . $default . "'";
}
/**
......
......@@ -41,11 +41,12 @@ final class MariaDb1027Platform extends MySqlPlatform
/**
* {@inheritdoc}
*
* @link https://mariadb.com/kb/en/library/json-data-type/
*/
public function getJsonTypeDeclarationSQL(array $field) : string
{
return 'JSON';
return 'LONGTEXT';
}
/**
......
......@@ -333,68 +333,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertTrue($columns['col_unsigned']->getUnsigned());
}
/**
* As of MariaDB 10.2.7, nullable default values literals are always single quoted in
* information_schema. Non-nullable defaults behaviour is not affected.
* This test ensure accidental removal of double single encoded defaults for MariaDB >= 10.2.7.
*
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
* @link https://dev.mysql.com/doc/refman/5.5/en/string-literals.html
*/
public function testColumnDefaultValuesDoubleQuoted() : void
{
$table = new Table("test_column_default_values_double_quoted");
$table->addColumn('string_nullable_quoted', 'string', ['notnull' => false, 'default' => 'NULL']);
$table->addColumn('string_nullable_double_quoted', 'string', ['notnull' => false, 'default' => "'NULL'"]);
$table->addColumn('string_notnull_quoted', 'string', ['notnull' => true, 'default' => 'NULL']);
$table->addColumn('string_notnull_double_quoted', 'string', ['notnull' => true, 'default' => "\\'NULL\\'"]);
$this->_sm->dropAndCreateTable($table);
$onlineTable = $this->_sm->listTableDetails("test_column_default_values_double_quoted");
self::assertSame('NULL', $onlineTable->getColumn('string_nullable_quoted')->getDefault());
self::assertSame("'NULL'", $onlineTable->getColumn('string_nullable_double_quoted')->getDefault());
self::assertSame("NULL", $onlineTable->getColumn('string_notnull_quoted')->getDefault());
self::assertSame("\\'NULL\\'", $onlineTable->getColumn('string_notnull_double_quoted')->getDefault());
$comparator = new Comparator();
$diff = $comparator->diffTable($table, $onlineTable);
self::assertFalse($diff, "Tables should be identical with double quoted literals.");
}
/**
* @link https://mariadb.com/kb/en/library/string-literals
* @link https://dev.mysql.com/doc/refman/5.7/en/string-literals.html
*/
public function testColumnEscapingDefaultValuesDoesNotTriggerSchemaChange() : void
{
$table = new Table("test_column_default_values_escaping");
$table->addColumn('single_backslash', 'string', ['default' => 'F\Q\D\N']);
$table->addColumn('double_backslash', 'string', ['default' => 'F\\Q\\D\\N']);
$table->addColumn('triple_backslash', 'string', ['default' => 'a\\\z']);
$table->addColumn('repeated_single_quotes', 'string', ['default' => "a''z"]);
$table->addColumn('backslash_double_quote', 'string', ['default' => 'a\"z']);
$table->addColumn('backslash_newline', 'string', ['default' => 'a\nz']);
$this->_sm->dropAndCreateTable($table);
$onlineTable = $this->_sm->listTableDetails("test_column_default_values_escaping");
self::assertSame('F\Q\D\N', $onlineTable->getColumn('single_backslash')->getDefault());
self::assertSame('F\\Q\\D\\N', $onlineTable->getColumn('double_backslash')->getDefault());
self::assertSame('a\\\z', $onlineTable->getColumn('triple_backslash')->getDefault());
self::assertSame("a''z", $onlineTable->getColumn('repeated_single_quotes')->getDefault());
self::assertSame('a\"z', $onlineTable->getColumn('backslash_double_quote')->getDefault());
self::assertSame('a\nz', $onlineTable->getColumn('backslash_newline')->getDefault());
$comparator = new Comparator();
$diff = $comparator->diffTable($table, $onlineTable);
self::assertFalse($diff, "Tables should be identical with values escape sequences.");
}
public function testJsonColumnType() : void
{
$platform = $this->_sm->getDatabasePlatform();
......@@ -411,36 +349,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertSame(TYPE::JSON, $columns['col_json']->getType()->getName());
}
/**
* Ensure that a table created outside doctrine and containing
* quoted default values does not trigger a table diff change. I
* Note: MariaDb 10.2 silently change "\'" into "''" when storing in
* information schema, MariaDb102Platform should normalize the table details.
*/
public function testExistingTableWithQuotedDefaultsDoesNotTriggerChange() : void
{
$this->_conn->query('DROP TABLE IF EXISTS test_column_defaults_with_create');
$sql = "
CREATE TABLE test_column_defaults_with_create (
col1 VARCHAR(255) NULL DEFAULT 'O''Connor\'\"',
col2 VARCHAR(255) NOT NULL DEFAULT 'O''Connor\'\"'
);
";
$this->_conn->query($sql);
$onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_create");
self::assertSame("O'Connor'\"", $onlineTable->getColumn('col1')->getDefault());
self::assertSame("O'Connor'\"", $onlineTable->getColumn('col2')->getDefault());
$table = new Table("test_column_defaults_no_diff");
$table->addColumn('col1', 'string', ['notnull' => false, 'default' => "O'Connor'\""]);
$table->addColumn('col2', 'string', ['notnull' => true, 'default' => "O'Connor'\""]);
$comparator = new Comparator();
$diff = $comparator->diffTable($table, $onlineTable);
self::assertFalse($diff);
}
public function testColumnDefaultCurrentTimestamp() : void
{
$platform = $this->_sm->getDatabasePlatform();
......@@ -552,20 +460,20 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table = new Table("text_blob_default_value");
$json = json_encode(['prop1' => "O'Connor", 'prop2' => 10]);
$json = json_encode(['prop1' => "Hello", 'prop2' => 10]);
$table->addColumn('def_text', 'text', ['default' => "O'Connor"]);
$table->addColumn('def_text', 'text', ['default' => "Hello"]);
$table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']);
$table->addColumn('def_blob', 'blob', ['default' => '\F\Q\D\N']);
$table->addColumn('def_blob', 'blob', ['default' => 'World']);
$table->addColumn('def_json', 'json', ['default' => $json]);
$this->_sm->dropAndCreateTable($table);
$onlineTable = $this->_sm->listTableDetails("text_blob_default_value");
self::assertSame("O'Connor", $onlineTable->getColumn('def_text')->getDefault());
self::assertSame("Hello", $onlineTable->getColumn('def_text')->getDefault());
self::assertSame('def', $onlineTable->getColumn('def_text_null')->getDefault());
self::assertSame('\F\Q\D\N', $onlineTable->getColumn('def_blob')->getDefault());
self::assertSame('World', $onlineTable->getColumn('def_blob')->getDefault());
self::assertSame($json, $onlineTable->getColumn('def_json')->getDefault());
$comparator = new Comparator();
......
......@@ -22,9 +22,13 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
self::assertTrue($this->_platform->hasNativeJsonType());
}
/**
* From MariaDB 10.2.7, JSON type is an alias to LONGTEXT
* @link https://mariadb.com/kb/en/library/json-data-type/
*/
public function testReturnsJsonTypeDeclarationSQL() : void
{
self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([]));
self::assertSame('LONGTEXT', $this->_platform->getJsonTypeDeclarationSQL([]));
}
public function testInitializesJsonTypeMapping() : void
......@@ -51,18 +55,18 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
{
$table = new Table("text_blob_default_value");
$table->addColumn('def_text', 'text', array('default' => "d''ef"));
$table->addColumn('def_blob', 'blob', array('default' => 'def'));
$table->addColumn('def_text', Type::TEXT, ['default' => "hello"]);
$table->addColumn('def_blob', Type::BLOB, ['default' => 'world']);
self::assertSame(
["CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT 'd''''ef' NOT NULL, def_blob LONGBLOB DEFAULT 'def' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
["CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT 'hello' NOT NULL, def_blob LONGBLOB DEFAULT 'world' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
$this->_platform->getCreateTableSQL($table)
);
$diffTable = clone $table;
$diffTable->changeColumn('def_text', ['default' => "d''ef"]);
$diffTable->changeColumn('def_blob', ['default' => 'def']);
$diffTable->changeColumn('def_text', ['default' => "hello"]);
$diffTable->changeColumn('def_blob', ['default' => 'world']);
$comparator = new Comparator();
......@@ -73,12 +77,14 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
{
$table = new Table("text_json_default_value");
$json = json_encode(['prop1' => "O'Connor", 'prop2' => 10]);
$json = json_encode(['prop1' => "Hello", 'prop2' => 10]);
$table->addColumn('def_json', Type::TEXT, ['default' => $json]);
$table->addColumn('def_json', 'text', ['default' => $json]);
$jsonType = $this->createPlatform()->getJsonTypeDeclarationSQL($table->getColumn('def_json')->toArray());
self::assertSame(
["CREATE TABLE text_json_default_value (def_json LONGTEXT DEFAULT '{\"prop1\":\"O''Connor\",\"prop2\":10}' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
["CREATE TABLE text_json_default_value (def_json $jsonType DEFAULT '{\"prop1\":\"Hello\",\"prop2\":10}' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"],
$this->_platform->getCreateTableSQL($table)
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment