function drush_sql_build_createdb_sql

6.x sql.drush.inc drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)
4.x sql.drush.inc drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)
5.x sql.drush.inc drush_sql_build_createdb_sql($db_spec, $quoted = FALSE)
2 calls to drush_sql_build_createdb_sql()

File

commands/sql/sql.drush.inc, line 1268
Drush sql commands

Code

function drush_sql_build_createdb_sql($db_spec, $quoted = FALSE) {
  $sql = array();
  switch (_drush_sql_get_scheme($db_spec)) {
    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);
      $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;';
      break;
    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);
      break;
  }
  return implode(' ', $sql);
}