|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Migratio\GrammarStructure\Mysql; |
|
4
|
|
|
|
|
5
|
|
|
class QuerySyntax extends QuerySyntaxHelper |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @var array $data |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $data = array(); |
|
12
|
|
|
/** |
|
13
|
|
|
* @var array $syntax |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $syntax = array(); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @return array |
|
19
|
|
|
*/ |
|
20
|
|
|
public function syntaxCreate() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->getWizardObjects($this->object); |
|
23
|
|
|
|
|
24
|
|
|
$this->getCreateTableSyntax(); |
|
25
|
|
|
|
|
26
|
|
|
$this->getDefaultSyntaxGroup(); |
|
27
|
|
|
|
|
28
|
|
|
$this->syntax[]=')'; |
|
29
|
|
|
|
|
30
|
|
|
//get table collation |
|
31
|
|
|
if(isset($this->data['tableCollation']['table'])){ |
|
32
|
|
|
$this->syntax[]=' DEFAULT CHARACTER SET '.$this->data['tableCollation']['table']; |
|
33
|
|
|
} |
|
34
|
|
|
else{ |
|
35
|
|
|
$this->syntax[]=' DEFAULT CHARACTER SET utf8'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
//get engine |
|
39
|
|
|
if($this->data['engine']!==null) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->syntax[]=' ENGINE='.$this->data['engine'].' '; |
|
42
|
|
|
} |
|
43
|
|
|
else{ |
|
44
|
|
|
$this->syntax[]=' ENGINE=InnoDB '; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$syntax = implode("",$this->syntax); |
|
48
|
|
|
|
|
49
|
|
|
$query=$this->schema->getConnection()->setQueryBasic($syntax); |
|
50
|
|
|
|
|
51
|
|
|
return [ |
|
52
|
|
|
'syntax'=>$syntax, |
|
53
|
|
|
'type'=>'create', |
|
54
|
|
|
'result'=>$query['result'], |
|
55
|
|
|
'message'=>$query['message'], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return mixed|void |
|
61
|
|
|
*/ |
|
62
|
|
|
private function getDefaultSyntaxGroup() |
|
63
|
|
|
{ |
|
64
|
|
|
|
|
65
|
|
|
$this->syntax[]=implode(",",$this->getCreateDefaultList()); |
|
66
|
|
|
|
|
67
|
|
|
//get unique values |
|
68
|
|
|
if(isset($this->data['uniqueValueList']) && count($this->data['uniqueValueList'])){ |
|
69
|
|
|
$this->syntax[]=','.implode(',',$this->data['uniqueValueList']); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
//get index values |
|
73
|
|
|
if(isset($this->data['indexValueList']) && count($this->data['indexValueList'])){ |
|
74
|
|
|
$this->syntax[]=','.implode(',',$this->data['indexValueList']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
//get index values for key |
|
78
|
|
|
if(count($this->getKeyList())){ |
|
79
|
|
|
$this->syntax[]=','.implode(',',$this->getKeyList()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if(count($this->data['references'])){ |
|
83
|
|
|
$this->syntax[]=$this->getReferenceSyntax($this->data['references']); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return mixed|void |
|
90
|
|
|
*/ |
|
91
|
|
|
public function syntaxAlter() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->getWizardObjects($this->object); |
|
94
|
|
|
|
|
95
|
|
|
$alterType = $this->object->getAlterType(); |
|
96
|
|
|
|
|
97
|
|
|
$group = $alterType['group']; |
|
98
|
|
|
|
|
99
|
|
|
$this->getDefaultSyntaxGroup(); |
|
100
|
|
|
|
|
101
|
|
|
return $this->{$group}($alterType); |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
private function addColumn($alterType) |
|
106
|
|
|
{ |
|
107
|
|
|
if(isset($alterType['place'])){ |
|
108
|
|
|
|
|
109
|
|
|
foreach ($alterType['place'] as $placeKey=>$placeValue){ |
|
110
|
|
|
$placeList=$placeKey .' '.$placeValue.''; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$syntax = implode("",$this->syntax); |
|
114
|
|
|
|
|
115
|
|
|
$alterSytanx = 'ALTER TABLE '.$this->table.' ADD COLUMN '.$syntax.' '.$placeList; |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
$query=$this->schema->getConnection()->setQueryBasic($alterSytanx); |
|
118
|
|
|
|
|
119
|
|
|
return [ |
|
120
|
|
|
'syntax'=>$syntax, |
|
121
|
|
|
'type'=>'create', |
|
122
|
|
|
'result'=>$query['result'], |
|
123
|
|
|
'message'=>$query['message'], |
|
124
|
|
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|