[DBAL-166] Table Encoding on generation table creation query Created: 14/Sep/11  Updated: 01/Apr/12  Resolved: 01/Apr/12

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.1.2
Fix Version/s: 2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Punin Nicolay G. Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
Labels: None
Environment:

mysql


Attachments: File docrine-dbal-patch.php    

 Description   

Can not set charset options for table creation.
Now I am fix thix problem in patch.
File: doctrine-dbal/lib/Doctrine/DBAL/Schema/Schema.php

#!/usr/bin/php
<?php
/**

  • Doctrine DBAL Patch
  • fix table creation query encode
  • (c) _Nicolay
    */
    system ('cp ./vendor/doctrine-dbal/lib/Doctrine/DBAL/Schema/Schema.php ./vendor/doctrine-dbal/lib/Doctrine/DBAL/Schema/Schema.php.Orig');

$data = file_get_contents('./vendor/doctrine-dbal/lib/Doctrine/DBAL/Schema/Schema.php');
$data = str_replace("new Table(\$tableName);",
"new Table(\$tableName,array(),array(),array(),0,array('charset'=>'utf8','collate'=>'utf8_general_ci'));",
$data);
file_put_contents('./vendor/doctrine-dbal/lib/Doctrine/DBAL/Schema/Schema.php', $data);



 Comments   
Comment by Stepan Tanasiychuk [ 20/Oct/11 ]

Guys, it's real problem for me too! (:

My test suite (in symfony2 project) always creates tables with "latin1_swedish_ci" collation. I want set "utf8_general_ci". But I don't want do it's in mysql.ini.

I tried setting it in MysqlSessionInit __construct, but it's not solved my problem.

In MySqlPlatform I found next code (https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L420):

        if (isset($options['charset'])) {
            $optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
            if (isset($options['collate'])) {
                $optionStrings['charset'] .= ' COLLATE ' . $options['collate'];
            }
        }

But any options don't set in this call
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/SchemaTool.php#L133

Comment by Benjamin Eberlei [ 01/Apr/12 ]

Implemented this as a new feature on Schema. Also defaulting to UTF-8 now.

Generated at Wed Oct 01 06:21:19 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.