1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class CreateAbstract |
4
|
|
|
* |
5
|
|
|
* @filesource CreateAbstract.php |
6
|
|
|
* @created 03.06.2017 |
7
|
|
|
* @package chillerlan\Database\Query\Dialects |
8
|
|
|
* @author Smiley <[email protected]> |
9
|
|
|
* @copyright 2017 Smiley |
10
|
|
|
* @license MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace chillerlan\Database\Query; |
14
|
|
|
|
15
|
|
|
use chillerlan\Database\Query\Traits\CharsetTrait; |
16
|
|
|
use chillerlan\Database\Query\Traits\IfNotExistsTrait; |
17
|
|
|
use chillerlan\Database\Query\Traits\NameTrait; |
18
|
|
|
|
19
|
|
|
abstract class CreateAbstract extends StatementAbstract implements CreateInterface{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string|null $dbname |
23
|
|
|
* |
24
|
|
|
* @return \chillerlan\Database\Query\CreateDatabaseInterface |
25
|
|
|
*/ |
26
|
|
|
public function database(string $dbname = null):CreateDatabaseInterface{ |
27
|
|
|
|
28
|
|
|
return (new class($this->DBDriver, $this->dialect) extends StatementAbstract implements CreateDatabaseInterface{ |
29
|
|
|
use CharsetTrait, IfNotExistsTrait, NameTrait; |
30
|
|
|
|
31
|
|
|
public function ifNotExists():CreateDatabaseInterface{return $this->_ifNotExists();} |
32
|
|
|
public function name(string $dbname = null):CreateDatabaseInterface{return $this->_name($dbname);} |
33
|
|
|
public function collate(string $collation):CreateDatabaseInterface{return $this->_collate($collation);} |
34
|
|
|
|
35
|
|
|
public function sql():string{ |
36
|
|
|
|
37
|
|
|
if(empty($this->name)){ |
38
|
|
|
throw new \Exception('no name specified'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$sql = 'CREATE DATABASE '; |
42
|
|
|
$sql .= $this->ifNotExists ? 'IF NOT EXISTS ' : ''; |
43
|
|
|
$sql .= $this->quote($this->name); |
44
|
|
|
$sql .= $this->collate ? ' '.$this->_charset($this->collate) : ''; |
45
|
|
|
|
46
|
|
|
return $sql; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
})->name($dbname); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string|null $tablename |
55
|
|
|
* |
56
|
|
|
* @return \chillerlan\Database\Query\CreateTableInterface |
57
|
|
|
*/ |
58
|
|
|
public function table(string $tablename = null):CreateTableInterface{ |
59
|
|
|
$class = $this->dialect.'\\CreateTable'; |
60
|
|
|
/** @var \chillerlan\Database\Query\CreateTableInterface $createTable */ |
61
|
|
|
$createTable = new $class($this->DBDriver, $this->dialect); |
62
|
|
|
|
63
|
|
|
return $createTable->name($tablename); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function index():CreateInterface{ |
67
|
|
|
// TODO: Implement index() method. |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function view():CreateInterface{ |
71
|
|
|
// TODO: Implement view() method. |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function trigger():CreateInterface{ |
75
|
|
|
// TODO: Implement trigger() method. |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|