2 namespace TYPO3\CMS\Dbal\Database\SqlCompilers;
35 if (isset($components[
'VALUES_ONLY']) && is_array($components[
'VALUES_ONLY'])) {
36 $valuesComponents = $components[
'EXTENDED'] ===
'1' ? $components[
'VALUES_ONLY'] : array($components[
'VALUES_ONLY']);
37 $tableFields = array();
39 $valuesComponents = $components[
'EXTENDED'] ===
'1' ? $components[
'FIELDS'] : array($components[
'FIELDS']);
40 $tableFields = array_keys($valuesComponents[0]);
42 foreach ($valuesComponents as $valuesComponent) {
44 foreach ($valuesComponent as $fV) {
47 $values[] =
'(' . implode(
',', $fields) .
')';
50 $query =
'INSERT INTO ' . $components[
'TABLE'];
51 if (!empty($tableFields)) {
52 $query .=
' (' . implode(
',', $tableFields) .
')';
54 $query .=
' VALUES ' . implode(
',', $values);
69 $fieldsKeys = array();
70 foreach ($components[
'FIELDS'] as $fN => $fCfg) {
71 $fieldsKeys[] = $fN .
' ' . $this->
compileFieldCfg($fCfg[
'definition']);
73 if ($components[
'KEYS']) {
74 foreach ($components[
'KEYS'] as $kN => $kCfg) {
75 if ($kN ===
'PRIMARYKEY') {
76 $fieldsKeys[] =
'PRIMARY KEY (' . implode(
',', $kCfg) .
')';
77 }
elseif ($kN ===
'UNIQUE') {
79 $fields = current($kCfg);
80 $fieldsKeys[] =
'UNIQUE KEY ' . $key .
' (' . implode(
',', $fields) .
')';
82 $fieldsKeys[] =
'KEY ' . $kN .
' (' . implode(
',', $kCfg) .
')';
87 $query =
'CREATE TABLE ' . $components[
'TABLE'] .
' (' .
88 implode(
',', $fieldsKeys) .
')' .
89 ($components[
'engine'] ?
' ENGINE=' . $components[
'engine'] :
'');
104 $query =
'ALTER TABLE ' . $components[
'TABLE'] .
' ' . $components[
'action'] .
' ' . ($components[
'FIELD'] ?: $components[
'KEY']);
111 $query .=
' ' . $components[
'newField'] .
' ' . $this->
compileFieldCfg($components[
'definition']);
117 case 'ADDPRIMARYKEY':
119 $query .=
' (' . implode(
',', $components[
'fields']) .
')';
121 case 'DEFAULTCHARACTERSET':
122 $query .= $components[
'charset'];
125 $query .=
'= ' . $components[
'engine'];
142 public function compileFieldList($selectFields, $compileComments =
true, $functionMapping =
true)
147 if (is_array($selectFields)) {
148 $outputParts = array();
149 foreach ($selectFields as $k => $v) {
151 switch ($v[
'type']) {
153 $outputParts[$k] = $v[
'function'] .
'(' . $v[
'func_content'] .
')';
156 if ($v[
'flow-control'][
'type'] ===
'CASE') {
161 $outputParts[$k] = ($v[
'distinct'] ? $v[
'distinct'] :
'') . ($v[
'table'] ? $v[
'table'] .
'.' :
'') . $v[
'field'];
166 $outputParts[$k] .=
' ' . $v[
'as_keyword'] .
' ' . $v[
'as'];
170 $outputParts[$k] .=
' ' . $v[
'sortDir'];
173 if ($compileComments && $selectFields[0][
'comments']) {
174 $fields = $selectFields[0][
'comments'] .
' ';
176 $fields .= implode(
', ', $outputParts);
191 $search = array(
'\\',
'\'',
'"',
"\x00",
"\x0a",
"\x0d",
"\x1a");
192 $replace = array(
'\\\\',
'\\\'',
'\\"',
'\0',
'\n',
'\r',
'\Z');
194 return str_replace($search, $replace, $str);
206 $cfg = $fieldCfg[
'fieldType'];
208 if ((
string)$fieldCfg[
'value'] !==
'') {
209 $cfg .=
'(' . $fieldCfg[
'value'] .
')';
212 if (is_array($fieldCfg[
'featureIndex'])) {
213 foreach ($fieldCfg[
'featureIndex'] as $featureDef) {
214 $cfg .=
' ' . $featureDef[
'keyword'];
216 if (is_array($featureDef[
'value'])) {
217 $cfg .=
' ' . $featureDef[
'value'][1] . $this->
compileAddslashes($featureDef[
'value'][0]) . $featureDef[
'value'][1];
238 if (is_array($clauseArray)) {
239 foreach ($clauseArray as $k => $v) {
241 $output .= $v[
'operator'] ?
' ' . $v[
'operator'] :
'';
243 if (is_array($v[
'sub'])) {
245 }
elseif (isset($v[
'func']) && $v[
'func'][
'type'] ===
'EXISTS') {
246 $output .=
' ' . trim($v[
'modifier']) .
' EXISTS (' . $this->
compileSELECT($v[
'func'][
'subquery']) .
')';
248 if (isset($v[
'func']) && $v[
'func'][
'type'] ===
'LOCATE') {
249 $output .=
' ' . trim($v[
'modifier']) .
' LOCATE(';
250 $output .= $v[
'func'][
'substr'][1] . $v[
'func'][
'substr'][0] . $v[
'func'][
'substr'][1];
251 $output .=
', ' . ($v[
'func'][
'table'] ? $v[
'func'][
'table'] .
'.' :
'') . $v[
'func'][
'field'];
252 $output .= isset($v[
'func'][
'pos']) ?
', ' . $v[
'func'][
'pos'][0] :
'';
254 }
elseif (isset($v[
'func']) && $v[
'func'][
'type'] ===
'IFNULL') {
255 $output .=
' ' . trim($v[
'modifier']) .
' IFNULL(';
256 $output .= ($v[
'func'][
'table'] ? $v[
'func'][
'table'] .
'.' :
'') . $v[
'func'][
'field'];
257 $output .=
', ' . $v[
'func'][
'default'][1] . $this->
compileAddslashes($v[
'func'][
'default'][0]) . $v[
'func'][
'default'][1];
259 }
elseif (isset($v[
'func']) && $v[
'func'][
'type'] ===
'CAST') {
260 $output .=
' ' . trim($v[
'modifier']) .
' CAST(';
261 $output .= ($v[
'func'][
'table'] ? $v[
'func'][
'table'] .
'.' :
'') . $v[
'func'][
'field'];
262 $output .=
' AS ' . $v[
'func'][
'datatype'][0];
264 }
elseif (isset($v[
'func']) && $v[
'func'][
'type'] ===
'FIND_IN_SET') {
265 $output .=
' ' . trim($v[
'modifier']) .
' FIND_IN_SET(';
266 $output .= $v[
'func'][
'str'][1] . $v[
'func'][
'str'][0] . $v[
'func'][
'str'][1];
267 $output .=
', ' . ($v[
'func'][
'table'] ? $v[
'func'][
'table'] .
'.' :
'') . $v[
'func'][
'field'];
271 $output .=
' ' . trim($v[
'modifier'] .
' ' . ($v[
'table'] ? $v[
'table'] .
'.' :
'') . $v[
'field']);
274 $output .= $v[
'calc'] . $v[
'calc_value'][1] . $this->
compileAddslashes($v[
'calc_value'][0]) . $v[
'calc_value'][1];
278 if ($v[
'comparator']) {
279 $output .=
' ' . $v[
'comparator'];
282 if (isset($v[
'subquery'])) {
283 $output .=
' (' . $this->
compileSELECT($v[
'subquery']) .
')';
285 $valueBuffer = array();
286 foreach ($v[
'value'] as $realValue) {
287 $valueBuffer[] = $realValue[1] . $this->
compileAddslashes($realValue[0]) . $realValue[1];
289 $output .=
' (' . trim(implode(
',', $valueBuffer)) .
')';
293 $lbound = $v[
'values'][0];
294 $ubound = $v[
'values'][1];
299 if (isset($v[
'value'][
'operator'])) {
301 foreach ($v[
'value'][
'args'] as $fieldDef) {
302 $values[] = ($fieldDef[
'table'] ? $fieldDef[
'table'] .
'.' :
'') . $fieldDef[
'field'];
304 $output .=
' ' . $v[
'value'][
'operator'] .
'(' . implode(
',', $values) .
')';
306 $output .=
' ' . $v[
'value'][1] . $this->
compileAddslashes($v[
'value'][0]) . $v[
'value'][1];