Skip to content

Commit

Permalink
SET default as strict mode #378
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jun 26, 2017
1 parent 52d513b commit d9ceb12
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Core/Provider/DatabaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Windwalker\Core\Database\Exporter\AbstractExporter;
use Windwalker\Database\DatabaseFactory;
use Windwalker\Database\Driver\AbstractDatabaseDriver;
use Windwalker\Database\Driver\Mysql\MysqlDriver;
use Windwalker\DataMapper\DatabaseContainer;
use Windwalker\DI\Container;
use Windwalker\DI\ServiceProviderInterface;
Expand Down Expand Up @@ -46,7 +47,14 @@ public function register(Container $container)
'prefix' => $config->get('database.prefix', 'wind_'),
];

return DatabaseFactory::getDbo($option['driver'], $option);
$db = DatabaseFactory::getDbo($option['driver'], $option);

if ($db instanceof MysqlDriver && $config->get('database.mysql.strict', true))
{
$this->strictMode($db);
}

return $db;
};

$container->share(AbstractDatabaseDriver::class, $closure);
Expand All @@ -71,4 +79,27 @@ public function register(Container $container)

$container->share(AbstractExporter::class, $closure);
}

/**
* strictMode
*
* @param MysqlDriver $db
*
* @return void
*/
public function strictMode(MysqlDriver $db)
{
// Set Mysql to strict mode
$modes = array(
// 'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION',
);

$db->connect()
->getConnection()
->exec("SET @@SESSION.sql_mode = '" . implode(',', $modes) . "';");
}
}

0 comments on commit d9ceb12

Please sign in to comment.