final class CreateDatabase
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] name [option …]: a request to create a database.

Mirrors SQLCOM_CREATE_DB with HA_CREATE_INFO. Rule: MYSQL-CREATE-DATABASE-001. The options are kept in written order. A database holds no columns, so the statement declares no relation. SCHEMA is a synonym of DATABASE, which the lexer folds. Source: https://dev.mysql.com/doc/refman/8.4/en/create-database.html. Status: Implemented.

Creating a database with optionsdoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('create schema if not exists shop default charset utf8mb4 collate utf8mb4_bin');
    [$create->toString(), count($create->statement->options)] // => ['CREATE DATABASE IF NOT EXISTS shop CHARACTER SET utf8mb4 COLLATE utf8mb4_bin', 2]

Properties§

public list<DatabaseOption> $options
public bool $ifNotExists
public Name $name

Methods§

public function __construct(
    public bool $ifNotExists,
    public Name $name,
    list<DatabaseOption> $options = [],
)

Parameters

$ifNotExistsboolWhether IF NOT EXISTS is written
$nameNameThe database name
$optionslist<DatabaseOption>The options in written order

Throws

InvalidConstruction When an option is READ ONLY, which only ALTER DATABASE takes
Calls 3
public function deriveStatement(Derivation $derivation): void

Has nothing to derive: a database is no relation.

Parameters

$derivationDerivation
public function render(Output $out): void

Writes the request.

Parameters

$outOutput
Calls 4

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1
Other tests reaching this symbol 2

Relations§

Instantiated in 1