TYPO3 CMS  TYPO3_7-6
PostgresSpecifics.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
25 {
31  protected $specificProperties = [
32  self::CAST_FIND_IN_SET => true
33  ];
34 
39  'TINYBLOB' => 'B',
40  'INT' => 'I4',
41  'INTEGER' => 'I4',
42  'TINYINT' => 'I2',
43  'SMALLINT' => 'I2',
44  'MEDIUMINT' => 'I4'
45  ];
46 
53  'R' => 'INT',
54  'I' => 'INT',
55  'I1' => 'SMALLINT',
56  'I2' => 'SMALLINT',
57  'I4' => 'INT',
58  ];
59 
67  public function getNativeFieldLength($mysqlType, $maxLength)
68  {
69  if ($maxLength === -1) {
70  return '';
71  }
72  switch ($mysqlType) {
73  case 'DOUBLE':
74  return '';
75  case 'TINYINT':
76  return '(4)';
77  case 'SMALLINT':
78  return '(6)';
79  case 'MEDIUMINT':
80  return '(9)';
81  case 'INT':
82  return '(11)';
83  case 'BIGINT':
84  return '(20)';
85  default:
86  return '(' . $maxLength . ')';
87  }
88  }
89 
96  protected function getNativeDefaultValue($fieldDefinition)
97  {
98  if (!$fieldDefinition['has_default']) {
99  $returnValue = null;
100  } elseif ($fieldDefinition['type'] === 'SERIAL' && substr($fieldDefinition['default_value'], 0, 7) === 'nextval') {
101  $returnValue = null;
102  } elseif ($fieldDefinition['type'] === 'varchar') {
103  // Strip character class and unquote string
104  if (StringUtility::beginsWith($fieldDefinition['default_value'], 'NULL::')) {
105  $returnValue = null;
106  } else {
107  $returnValue = str_replace("\\'", "'", preg_replace('/\'(.*)\'(::(?:character\svarying|varchar|character|char|text)(?:\(\d+\))?)?\z/', '\\1', $fieldDefinition['default_value']));
108  }
109  } elseif (substr($fieldDefinition['type'], 0, 3) === 'int') {
110  $returnValue = (int)preg_replace('/^\(?(\-?\d+)\)?$/', '\\1', $fieldDefinition['default_value']);
111  } else {
112  $returnValue = $fieldDefinition['default_value'];
113  }
114  return $returnValue;
115  }
116 
128  protected function getNativeKeyForField($fieldDefinition)
129  {
130  if (isset($fieldDefinition['primary_key']) && (bool)$fieldDefinition['primary_key']) {
131  $returnValue = 'PRI';
132  } elseif (isset($fieldDefinition['unique']) && (bool)$fieldDefinition['unique']) {
133  $returnValue = 'UNI';
134  } else {
135  $returnValue = '';
136  }
137  return $returnValue;
138  }
139 
148  protected function getNativeExtraFieldAttributes($fieldDefinition)
149  {
150  if ($fieldDefinition['type'] === 'SERIAL' || substr($fieldDefinition['default_value'], 0, 7) === 'nextval') {
151  return 'auto_increment';
152  }
153  return '';
154  }
155 
167  public function transformQueryParts(&$select_fields, &$from_table, &$where_clause, &$groupBy = '', &$orderBy = '', &$limit = '')
168  {
169  // Strip orderBy part if select statement is a count
170  if (preg_match_all('/count\(([^)]*)\)/i', $select_fields, $matches)) {
171  $orderByFields = GeneralUtility::trimExplode(',', $orderBy);
172  $groupByFields = GeneralUtility::trimExplode(',', $groupBy);
173  foreach ($matches[1] as $matchedField) {
174  $field = $matchedField;
175  // Lookup if the field in COUNT() statement is used in GROUP BY statement
176  $index = array_search($field, $groupByFields, true);
177  if ($index !== false) {
178  // field is used in GROUP BY, continue with next field
179  continue;
180  }
181  // If that field isn't used in GROUP BY statement, drop the ordering for compatibility reason
182  $index = array_search($field, $orderByFields, true);
183  if ($index !== false) {
184  unset($orderByFields[$index]);
185  }
186  }
187  $orderBy = implode(', ', $orderByFields);
188  }
189  }
190 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
transformQueryParts(&$select_fields, &$from_table, &$where_clause, &$groupBy='', &$orderBy='', &$limit='')
static beginsWith($haystack, $needle)