|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class CreateTableAbstract |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource CreateTableAbstract.php |
|
6
|
|
|
* @created 04.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\IfNotExistsTrait; |
|
16
|
|
|
use chillerlan\Database\Query\Traits\NameTrait; |
|
17
|
|
|
|
|
18
|
|
|
abstract class CreateTableAbstract extends StatementAbstract implements CreateTableInterface{ |
|
19
|
|
|
use IfNotExistsTrait, NameTrait; |
|
20
|
|
|
|
|
21
|
|
|
protected $temp = false; |
|
22
|
|
|
protected $primaryKey; |
|
23
|
|
|
protected $cols = []; |
|
24
|
|
|
|
|
25
|
|
|
public function ifNotExists():CreateTableInterface{return $this->_ifNotExists();} |
|
26
|
|
|
public function name(string $dbname = null):CreateTableInterface{return $this->_name($dbname);} |
|
27
|
|
|
|
|
28
|
|
|
public function execute(){ |
|
29
|
|
|
// TODO: Implement execute() method. |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function temp():CreateTableInterface{ |
|
33
|
|
|
$this->temp = true; |
|
34
|
|
|
|
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function primaryKey(string $field):CreateTableInterface{ |
|
39
|
|
|
$this->primaryKey = $field; |
|
40
|
|
|
|
|
41
|
|
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
abstract protected function fieldspec( |
|
|
|
|
|
|
45
|
|
|
string $name, |
|
46
|
|
|
string $type, |
|
47
|
|
|
$length = null, |
|
48
|
|
|
string $attribute = null, |
|
49
|
|
|
string $collation = null, |
|
50
|
|
|
bool $isNull = false, |
|
51
|
|
|
string $defaultType = null, |
|
52
|
|
|
$defaultValue = null, |
|
53
|
|
|
string $extra = null |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
public function field( |
|
57
|
|
|
string $name, |
|
58
|
|
|
string $type, |
|
59
|
|
|
$length = null, |
|
60
|
|
|
string $attribute = null, |
|
61
|
|
|
string $collation = null, |
|
62
|
|
|
bool $isNull = false, |
|
63
|
|
|
string $defaultType = null, |
|
64
|
|
|
$defaultValue = null, |
|
65
|
|
|
string $extra = null |
|
66
|
|
|
):CreateTableInterface { |
|
67
|
|
|
|
|
68
|
|
|
$this->cols[$name] = $this->fieldspec( |
|
69
|
|
|
$name, |
|
70
|
|
|
$type, |
|
71
|
|
|
$length, |
|
72
|
|
|
$attribute, |
|
73
|
|
|
$collation, |
|
74
|
|
|
$isNull, |
|
75
|
|
|
$defaultType, |
|
76
|
|
|
$defaultValue, |
|
77
|
|
|
$extra |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function index($name){ |
|
84
|
|
|
// TODO: Implement index() method. |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.