Mysql/Doctrine/Symfony collation and case sensitivity issues

in #symfony7 years ago (edited)

Modifying the column charset and collation (official docs)
https://dev.mysql.com/doc/refman/5.7/en/charset-column.html

ALTER TABLE <some_table> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

and

ALTER TABLE t1 MODIFY
    col1 VARCHAR(5)
      CHARACTER SET latin1
      COLLATE latin1_swedish_ci;

Doctrine/Symfony : the collation works for all common db drivers now, so we can put that into property annotation. Column 'name' will be no case sensitive when doing a SELECT with WHERE condition.

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=false, options={"collation":"utf8_bin"})
     */
    private $name;

utf8_bin guarantees that the column will be treated as case sensitive.


Symfony - we can throw an exception when we're not getting exactly one result from a query (if the query should really return only one result, I wouldn't add there a setMaxResults(1) because then it would be hiding of an error in data, so just throw and handle exception.

https://stackoverflow.com/questions/17798252/symfony2-doctrine-throw-nonuniqueresultexception


How to check if there are non unique entries for given column?
https://stackoverflow.com/questions/13146304/how-to-select-every-row-where-column-value-is-not-distinct

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 60410.66
ETH 2598.79
USDT 1.00
SBD 2.62