Db: Set MySQL server SQL modes to behave closer to ANSI SQL

refs #4413
This commit is contained in:
Eric Lippmann 2013-07-29 18:37:59 +02:00
parent 104925dff4
commit 457f9b8f50

View File

@ -59,13 +59,18 @@ class Connection implements DatasourceInterface
switch ($this->dbtype) { switch ($this->dbtype) {
case 'mysql': case 'mysql':
$adapter = 'Pdo_Mysql'; $adapter = 'Pdo_Mysql';
$drv_options[PDO::MYSQL_ATTR_INIT_COMMAND] = /* Set MySQL server SQL modes to behave as closely as possible to Oracle and
"SET SESSION SQL_MODE='STRICT_ALL_TABLES,NO_ZERO_IN_DATE," * PostgreSQL. Note that the ONLY_FULL_GROUP_BY mode is left on purpose because
. "NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT," * MySQL requires you to specify all non-aggregate columns in the group by list
. "ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER';"; * even if the query is grouped by the master table's primary key which is valid
// Not using ONLY_FULL_GROUP_BY as of performance impact * ANSI SQL though. Further in that case the query plan would suffer if you add more
// TODO: NO_ZERO_IN_DATE as been added with 5.1.11. Is it * columns to the group by list.
// ignored by other versions? * @TODO(#4462): NO_ZERO_IN_DATE has been added with MySQL version 5.1.11. Is it
* safe to pass this option since (older) versions ignore modes unknown by this time?
*/
$drv_ptions[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='"
. "STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,"
. "NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION';";
$port = $this->config->get('port', 3306); $port = $this->config->get('port', 3306);
break; break;
case 'pgsql': case 'pgsql':
@ -110,7 +115,7 @@ class Connection implements DatasourceInterface
if ($adapter === 'Oracle') { if ($adapter === 'Oracle') {
$this->db->setLobAsString(false); $this->db->setLobAsString(false);
} }
// TODO: ZfDb::FETCH_ASSOC for Oracle? // TODO: ZfDb::FETCH_ASSOC for Oracle?
$this->db->setFetchMode(ZfDb::FETCH_OBJ); $this->db->setFetchMode(ZfDb::FETCH_OBJ);