function drush_sql_build_createdb_sql

6.x drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)
4.x drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)
5.x drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)

Build a SQL string for dropping and creating a database.


array $db_spec: A database specification array.

boolean $quoted: Quote the database name. Mysql uses backticks to quote which can cause problems in a Windows shell. Set TRUE if the CREATE is not running on the bash command line.

2 calls to drush_sql_build_createdb_sql()
drush_sql_sync in commands/sql/
_drush_sql_create in commands/sql/
Generate CREATE DATABASE sql plus additonal preparations.


commands/sql/, line 1478
Drush sql commands


function drush_sql_build_createdb_sql($db_spec, $quoted = FALSE) {
  $sql = array();
  $schema = _drush_sql_get_scheme($db_spec);
  switch ($schema) {
    case 'mysql':
      $dbname = $quoted ? '`' . $db_spec['database'] . '`' : $db_spec['database'];
      $sql[] = sprintf('DROP DATABASE IF EXISTS %s;', $dbname);
      $sql[] = sprintf('CREATE DATABASE %s /*!40100 DEFAULT CHARACTER SET utf8 */;', $dbname);
      // Only GRANT PRIVILEGES when using db-su because site user may not have access to 'GRANT'.
      $db_superuser = drush_sitealias_get_option(NULL, 'db-su');
      if (isset($db_superuser)) {
        $sql[] = sprintf('GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@\'%s\'', $dbname, $db_spec['username'], $db_spec['host']);
        $sql[] = sprintf("IDENTIFIED BY '%s';", $db_spec['password']);
        $sql[] = 'FLUSH PRIVILEGES;';
    case 'pgsql':
      $dbname = $quoted ? '"' . $db_spec['database'] . '"' : $db_spec['database'];
      $sql[] = sprintf('drop database if exists %s;', $dbname);
      $sql[] = sprintf("create database %s ENCODING 'UTF8';", $dbname);
    case 'sqlite':
      $sql[] = '';
      drush_log("Unable to generate CREATE DATABASE sql for $schema", 'error');
  return implode(' ', $sql);