for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class CreateDatabase
*
* @filesource CreateDatabase.php
* @created 12.06.2017
* @package chillerlan\Database\Query\Dialects\Postgres
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*/
namespace chillerlan\Database\Query\Dialects\Postgres;
use chillerlan\Database\Query\{CreateDatabaseAbstract, QueryException};
class CreateDatabase extends CreateDatabaseAbstract{
public function sql():string{
if(empty($this->name)){
throw new QueryException('no name specified');
}
$sql = 'CREATE DATABASE ';
$sql .= $this->quote($this->name);
if($this->collate){
$charset = explode(',', $this->collate, 3);
$count = count($charset);
if($count > 0){
$sql .= ' ENCODING \''.strtoupper($charset[0]).'\'';
if($count > 1){
$sql .= ' LC_COLLATE=\''.$charset[1].'\'';
if($count > 2){
$sql .= ' LC_CTYPE=\''.$charset[2].'\'';
return $sql;