|
0
|
1 |
<?php |
|
|
2 |
/* |
|
|
3 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
4 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
5 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
6 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
7 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
8 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
9 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
10 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
11 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
12 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
13 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
14 |
* |
|
|
15 |
* This software consists of voluntary contributions made by many individuals |
|
|
16 |
* and is licensed under the LGPL. For more information, see |
|
|
17 |
* <http://www.doctrine-project.org>. |
|
|
18 |
*/ |
|
|
19 |
|
|
|
20 |
namespace Doctrine\DBAL\Platforms; |
|
|
21 |
|
|
|
22 |
use Doctrine\DBAL\DBALException, |
|
|
23 |
Doctrine\DBAL\Connection, |
|
|
24 |
Doctrine\DBAL\Types, |
|
|
25 |
Doctrine\DBAL\Schema\Table, |
|
|
26 |
Doctrine\DBAL\Schema\Index, |
|
|
27 |
Doctrine\DBAL\Schema\ForeignKeyConstraint, |
|
|
28 |
Doctrine\DBAL\Schema\TableDiff, |
|
|
29 |
Doctrine\DBAL\Schema\Column, |
|
|
30 |
Doctrine\DBAL\Types\Type; |
|
|
31 |
|
|
|
32 |
/** |
|
|
33 |
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central |
|
|
34 |
* point of abstraction of platform-specific behaviors, features and SQL dialects. |
|
|
35 |
* They are a passive source of information. |
|
|
36 |
* |
|
|
37 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|
|
38 |
* @link www.doctrine-project.org |
|
|
39 |
* @since 2.0 |
|
|
40 |
* @version $Revision: 3938 $ |
|
|
41 |
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> |
|
|
42 |
* @author Jonathan Wage <jonwage@gmail.com> |
|
|
43 |
* @author Roman Borschel <roman@code-factory.org> |
|
|
44 |
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) |
|
|
45 |
* @author Benjamin Eberlei <kontakt@beberlei.de> |
|
|
46 |
* @todo Remove any unnecessary methods. |
|
|
47 |
*/ |
|
|
48 |
abstract class AbstractPlatform |
|
|
49 |
{ |
|
|
50 |
/** |
|
|
51 |
* @var int |
|
|
52 |
*/ |
|
|
53 |
const CREATE_INDEXES = 1; |
|
|
54 |
|
|
|
55 |
/** |
|
|
56 |
* @var int |
|
|
57 |
*/ |
|
|
58 |
const CREATE_FOREIGNKEYS = 2; |
|
|
59 |
|
|
|
60 |
/** |
|
|
61 |
* @var int |
|
|
62 |
*/ |
|
|
63 |
const TRIM_UNSPECIFIED = 0; |
|
|
64 |
|
|
|
65 |
/** |
|
|
66 |
* @var int |
|
|
67 |
*/ |
|
|
68 |
const TRIM_LEADING = 1; |
|
|
69 |
|
|
|
70 |
/** |
|
|
71 |
* @var int |
|
|
72 |
*/ |
|
|
73 |
const TRIM_TRAILING = 2; |
|
|
74 |
|
|
|
75 |
/** |
|
|
76 |
* @var int |
|
|
77 |
*/ |
|
|
78 |
const TRIM_BOTH = 3; |
|
|
79 |
|
|
|
80 |
/** |
|
|
81 |
* @var array |
|
|
82 |
*/ |
|
|
83 |
protected $doctrineTypeMapping = null; |
|
|
84 |
|
|
|
85 |
/** |
|
|
86 |
* Contains a list of all columns that should generate parseable column comments for type-detection |
|
|
87 |
* in reverse engineering scenarios. |
|
|
88 |
* |
|
|
89 |
* @var array |
|
|
90 |
*/ |
|
|
91 |
protected $doctrineTypeComments = null; |
|
|
92 |
|
|
|
93 |
/** |
|
|
94 |
* Constructor. |
|
|
95 |
*/ |
|
|
96 |
public function __construct() {} |
|
|
97 |
|
|
|
98 |
/** |
|
|
99 |
* Gets the SQL snippet that declares a boolean column. |
|
|
100 |
* |
|
|
101 |
* @param array $columnDef |
|
|
102 |
* @return string |
|
|
103 |
*/ |
|
|
104 |
abstract public function getBooleanTypeDeclarationSQL(array $columnDef); |
|
|
105 |
|
|
|
106 |
/** |
|
|
107 |
* Gets the SQL snippet that declares a 4 byte integer column. |
|
|
108 |
* |
|
|
109 |
* @param array $columnDef |
|
|
110 |
* @return string |
|
|
111 |
*/ |
|
|
112 |
abstract public function getIntegerTypeDeclarationSQL(array $columnDef); |
|
|
113 |
|
|
|
114 |
/** |
|
|
115 |
* Gets the SQL snippet that declares an 8 byte integer column. |
|
|
116 |
* |
|
|
117 |
* @param array $columnDef |
|
|
118 |
* @return string |
|
|
119 |
*/ |
|
|
120 |
abstract public function getBigIntTypeDeclarationSQL(array $columnDef); |
|
|
121 |
|
|
|
122 |
/** |
|
|
123 |
* Gets the SQL snippet that declares a 2 byte integer column. |
|
|
124 |
* |
|
|
125 |
* @param array $columnDef |
|
|
126 |
* @return string |
|
|
127 |
*/ |
|
|
128 |
abstract public function getSmallIntTypeDeclarationSQL(array $columnDef); |
|
|
129 |
|
|
|
130 |
/** |
|
|
131 |
* Gets the SQL snippet that declares common properties of an integer column. |
|
|
132 |
* |
|
|
133 |
* @param array $columnDef |
|
|
134 |
* @return string |
|
|
135 |
*/ |
|
|
136 |
abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef); |
|
|
137 |
|
|
|
138 |
/** |
|
|
139 |
* Lazy load Doctrine Type Mappings |
|
|
140 |
* |
|
|
141 |
* @return void |
|
|
142 |
*/ |
|
|
143 |
abstract protected function initializeDoctrineTypeMappings(); |
|
|
144 |
|
|
|
145 |
/** |
|
|
146 |
* Gets the SQL snippet used to declare a VARCHAR column type. |
|
|
147 |
* |
|
|
148 |
* @param array $field |
|
|
149 |
*/ |
|
|
150 |
public function getVarcharTypeDeclarationSQL(array $field) |
|
|
151 |
{ |
|
|
152 |
if ( !isset($field['length'])) { |
|
|
153 |
$field['length'] = $this->getVarcharDefaultLength(); |
|
|
154 |
} |
|
|
155 |
|
|
|
156 |
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false; |
|
|
157 |
|
|
|
158 |
if ($field['length'] > $this->getVarcharMaxLength()) { |
|
|
159 |
return $this->getClobTypeDeclarationSQL($field); |
|
|
160 |
} else { |
|
|
161 |
return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed); |
|
|
162 |
} |
|
|
163 |
} |
|
|
164 |
|
|
|
165 |
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) |
|
|
166 |
{ |
|
|
167 |
throw DBALException::notSupported('VARCHARs not supported by Platform.'); |
|
|
168 |
} |
|
|
169 |
|
|
|
170 |
/** |
|
|
171 |
* Gets the SQL snippet used to declare a CLOB column type. |
|
|
172 |
* |
|
|
173 |
* @param array $field |
|
|
174 |
*/ |
|
|
175 |
abstract public function getClobTypeDeclarationSQL(array $field); |
|
|
176 |
|
|
|
177 |
/** |
|
|
178 |
* Gets the name of the platform. |
|
|
179 |
* |
|
|
180 |
* @return string |
|
|
181 |
*/ |
|
|
182 |
abstract public function getName(); |
|
|
183 |
|
|
|
184 |
/** |
|
|
185 |
* Register a doctrine type to be used in conjunction with a column type of this platform. |
|
|
186 |
* |
|
|
187 |
* @param string $dbType |
|
|
188 |
* @param string $doctrineType |
|
|
189 |
*/ |
|
|
190 |
public function registerDoctrineTypeMapping($dbType, $doctrineType) |
|
|
191 |
{ |
|
|
192 |
if ($this->doctrineTypeMapping === null) { |
|
|
193 |
$this->initializeDoctrineTypeMappings(); |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
if (!Types\Type::hasType($doctrineType)) { |
|
|
197 |
throw DBALException::typeNotFound($doctrineType); |
|
|
198 |
} |
|
|
199 |
|
|
|
200 |
$dbType = strtolower($dbType); |
|
|
201 |
$this->doctrineTypeMapping[$dbType] = $doctrineType; |
|
|
202 |
} |
|
|
203 |
|
|
|
204 |
/** |
|
|
205 |
* Get the Doctrine type that is mapped for the given database column type. |
|
|
206 |
* |
|
|
207 |
* @param string $dbType |
|
|
208 |
* @return string |
|
|
209 |
*/ |
|
|
210 |
public function getDoctrineTypeMapping($dbType) |
|
|
211 |
{ |
|
|
212 |
if ($this->doctrineTypeMapping === null) { |
|
|
213 |
$this->initializeDoctrineTypeMappings(); |
|
|
214 |
} |
|
|
215 |
|
|
|
216 |
$dbType = strtolower($dbType); |
|
|
217 |
if (isset($this->doctrineTypeMapping[$dbType])) { |
|
|
218 |
return $this->doctrineTypeMapping[$dbType]; |
|
|
219 |
} else { |
|
|
220 |
throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it."); |
|
|
221 |
} |
|
|
222 |
} |
|
|
223 |
|
|
|
224 |
/** |
|
|
225 |
* Check if a database type is currently supported by this platform. |
|
|
226 |
* |
|
|
227 |
* @param string $dbType |
|
|
228 |
* @return bool |
|
|
229 |
*/ |
|
|
230 |
public function hasDoctrineTypeMappingFor($dbType) |
|
|
231 |
{ |
|
|
232 |
if ($this->doctrineTypeMapping === null) { |
|
|
233 |
$this->initializeDoctrineTypeMappings(); |
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
$dbType = strtolower($dbType); |
|
|
237 |
return isset($this->doctrineTypeMapping[$dbType]); |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
/** |
|
|
241 |
* Initialize the Doctrine Type comments instance variable for in_array() checks. |
|
|
242 |
* |
|
|
243 |
* @return void |
|
|
244 |
*/ |
|
|
245 |
protected function initializeCommentedDoctrineTypes() |
|
|
246 |
{ |
|
|
247 |
$this->doctrineTypeComments = array(Type::TARRAY, Type::OBJECT); |
|
|
248 |
} |
|
|
249 |
|
|
|
250 |
/** |
|
|
251 |
* Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type? |
|
|
252 |
* |
|
|
253 |
* @param Type $doctrineType |
|
|
254 |
* @return bool |
|
|
255 |
*/ |
|
|
256 |
public function isCommentedDoctrineType(Type $doctrineType) |
|
|
257 |
{ |
|
|
258 |
if ($this->doctrineTypeComments === null) { |
|
|
259 |
$this->initializeCommentedDoctrineTypes(); |
|
|
260 |
} |
|
|
261 |
|
|
|
262 |
return in_array($doctrineType->getName(), $this->doctrineTypeComments); |
|
|
263 |
} |
|
|
264 |
|
|
|
265 |
/** |
|
|
266 |
* Mark this type as to be commented in ALTER TABLE and CREATE TABLE statements. |
|
|
267 |
* |
|
|
268 |
* @param Type $doctrineType |
|
|
269 |
* @return void |
|
|
270 |
*/ |
|
|
271 |
public function markDoctrineTypeCommented(Type $doctrineType) |
|
|
272 |
{ |
|
|
273 |
if ($this->doctrineTypeComments === null) { |
|
|
274 |
$this->initializeCommentedDoctrineTypes(); |
|
|
275 |
} |
|
|
276 |
$this->doctrineTypeComments[] = $doctrineType->getName(); |
|
|
277 |
} |
|
|
278 |
|
|
|
279 |
/** |
|
|
280 |
* Get the comment to append to a column comment that helps parsing this type in reverse engineering. |
|
|
281 |
* |
|
|
282 |
* @param Type $doctrineType |
|
|
283 |
* @return string |
|
|
284 |
*/ |
|
|
285 |
public function getDoctrineTypeComment(Type $doctrineType) |
|
|
286 |
{ |
|
|
287 |
return '(DC2Type:' . $doctrineType->getName() . ')'; |
|
|
288 |
} |
|
|
289 |
|
|
|
290 |
/** |
|
|
291 |
* Return the comment of a passed column modified by potential doctrine type comment hints. |
|
|
292 |
* |
|
|
293 |
* @param Column $column |
|
|
294 |
* @return string |
|
|
295 |
*/ |
|
|
296 |
protected function getColumnComment(Column $column) |
|
|
297 |
{ |
|
|
298 |
$comment = $column->getComment(); |
|
|
299 |
if ($this->isCommentedDoctrineType($column->getType())) { |
|
|
300 |
$comment .= $this->getDoctrineTypeComment($column->getType()); |
|
|
301 |
} |
|
|
302 |
return $comment; |
|
|
303 |
} |
|
|
304 |
|
|
|
305 |
/** |
|
|
306 |
* Gets the character used for identifier quoting. |
|
|
307 |
* |
|
|
308 |
* @return string |
|
|
309 |
*/ |
|
|
310 |
public function getIdentifierQuoteCharacter() |
|
|
311 |
{ |
|
|
312 |
return '"'; |
|
|
313 |
} |
|
|
314 |
|
|
|
315 |
/** |
|
|
316 |
* Gets the string portion that starts an SQL comment. |
|
|
317 |
* |
|
|
318 |
* @return string |
|
|
319 |
*/ |
|
|
320 |
public function getSqlCommentStartString() |
|
|
321 |
{ |
|
|
322 |
return "--"; |
|
|
323 |
} |
|
|
324 |
|
|
|
325 |
/** |
|
|
326 |
* Gets the string portion that ends an SQL comment. |
|
|
327 |
* |
|
|
328 |
* @return string |
|
|
329 |
*/ |
|
|
330 |
public function getSqlCommentEndString() |
|
|
331 |
{ |
|
|
332 |
return "\n"; |
|
|
333 |
} |
|
|
334 |
|
|
|
335 |
/** |
|
|
336 |
* Gets the maximum length of a varchar field. |
|
|
337 |
* |
|
|
338 |
* @return integer |
|
|
339 |
*/ |
|
|
340 |
public function getVarcharMaxLength() |
|
|
341 |
{ |
|
|
342 |
return 4000; |
|
|
343 |
} |
|
|
344 |
|
|
|
345 |
/** |
|
|
346 |
* Gets the default length of a varchar field. |
|
|
347 |
* |
|
|
348 |
* @return integer |
|
|
349 |
*/ |
|
|
350 |
public function getVarcharDefaultLength() |
|
|
351 |
{ |
|
|
352 |
return 255; |
|
|
353 |
} |
|
|
354 |
|
|
|
355 |
/** |
|
|
356 |
* Gets all SQL wildcard characters of the platform. |
|
|
357 |
* |
|
|
358 |
* @return array |
|
|
359 |
*/ |
|
|
360 |
public function getWildcards() |
|
|
361 |
{ |
|
|
362 |
return array('%', '_'); |
|
|
363 |
} |
|
|
364 |
|
|
|
365 |
/** |
|
|
366 |
* Returns the regular expression operator. |
|
|
367 |
* |
|
|
368 |
* @return string |
|
|
369 |
*/ |
|
|
370 |
public function getRegexpExpression() |
|
|
371 |
{ |
|
|
372 |
throw DBALException::notSupported(__METHOD__); |
|
|
373 |
} |
|
|
374 |
|
|
|
375 |
/** |
|
|
376 |
* Returns the average value of a column |
|
|
377 |
* |
|
|
378 |
* @param string $column the column to use |
|
|
379 |
* @return string generated sql including an AVG aggregate function |
|
|
380 |
*/ |
|
|
381 |
public function getAvgExpression($column) |
|
|
382 |
{ |
|
|
383 |
return 'AVG(' . $column . ')'; |
|
|
384 |
} |
|
|
385 |
|
|
|
386 |
/** |
|
|
387 |
* Returns the number of rows (without a NULL value) of a column |
|
|
388 |
* |
|
|
389 |
* If a '*' is used instead of a column the number of selected rows |
|
|
390 |
* is returned. |
|
|
391 |
* |
|
|
392 |
* @param string|integer $column the column to use |
|
|
393 |
* @return string generated sql including a COUNT aggregate function |
|
|
394 |
*/ |
|
|
395 |
public function getCountExpression($column) |
|
|
396 |
{ |
|
|
397 |
return 'COUNT(' . $column . ')'; |
|
|
398 |
} |
|
|
399 |
|
|
|
400 |
/** |
|
|
401 |
* Returns the highest value of a column |
|
|
402 |
* |
|
|
403 |
* @param string $column the column to use |
|
|
404 |
* @return string generated sql including a MAX aggregate function |
|
|
405 |
*/ |
|
|
406 |
public function getMaxExpression($column) |
|
|
407 |
{ |
|
|
408 |
return 'MAX(' . $column . ')'; |
|
|
409 |
} |
|
|
410 |
|
|
|
411 |
/** |
|
|
412 |
* Returns the lowest value of a column |
|
|
413 |
* |
|
|
414 |
* @param string $column the column to use |
|
|
415 |
* @return string |
|
|
416 |
*/ |
|
|
417 |
public function getMinExpression($column) |
|
|
418 |
{ |
|
|
419 |
return 'MIN(' . $column . ')'; |
|
|
420 |
} |
|
|
421 |
|
|
|
422 |
/** |
|
|
423 |
* Returns the total sum of a column |
|
|
424 |
* |
|
|
425 |
* @param string $column the column to use |
|
|
426 |
* @return string |
|
|
427 |
*/ |
|
|
428 |
public function getSumExpression($column) |
|
|
429 |
{ |
|
|
430 |
return 'SUM(' . $column . ')'; |
|
|
431 |
} |
|
|
432 |
|
|
|
433 |
// scalar functions |
|
|
434 |
|
|
|
435 |
/** |
|
|
436 |
* Returns the md5 sum of a field. |
|
|
437 |
* |
|
|
438 |
* Note: Not SQL92, but common functionality |
|
|
439 |
* |
|
|
440 |
* @return string |
|
|
441 |
*/ |
|
|
442 |
public function getMd5Expression($column) |
|
|
443 |
{ |
|
|
444 |
return 'MD5(' . $column . ')'; |
|
|
445 |
} |
|
|
446 |
|
|
|
447 |
/** |
|
|
448 |
* Returns the length of a text field. |
|
|
449 |
* |
|
|
450 |
* @param string $expression1 |
|
|
451 |
* @param string $expression2 |
|
|
452 |
* @return string |
|
|
453 |
*/ |
|
|
454 |
public function getLengthExpression($column) |
|
|
455 |
{ |
|
|
456 |
return 'LENGTH(' . $column . ')'; |
|
|
457 |
} |
|
|
458 |
|
|
|
459 |
/** |
|
|
460 |
* Rounds a numeric field to the number of decimals specified. |
|
|
461 |
* |
|
|
462 |
* @param string $expression1 |
|
|
463 |
* @param string $expression2 |
|
|
464 |
* @return string |
|
|
465 |
*/ |
|
|
466 |
public function getRoundExpression($column, $decimals = 0) |
|
|
467 |
{ |
|
|
468 |
return 'ROUND(' . $column . ', ' . $decimals . ')'; |
|
|
469 |
} |
|
|
470 |
|
|
|
471 |
/** |
|
|
472 |
* Returns the remainder of the division operation |
|
|
473 |
* $expression1 / $expression2. |
|
|
474 |
* |
|
|
475 |
* @param string $expression1 |
|
|
476 |
* @param string $expression2 |
|
|
477 |
* @return string |
|
|
478 |
*/ |
|
|
479 |
public function getModExpression($expression1, $expression2) |
|
|
480 |
{ |
|
|
481 |
return 'MOD(' . $expression1 . ', ' . $expression2 . ')'; |
|
|
482 |
} |
|
|
483 |
|
|
|
484 |
/** |
|
|
485 |
* Trim a string, leading/trailing/both and with a given char which defaults to space. |
|
|
486 |
* |
|
|
487 |
* @param string $str |
|
|
488 |
* @param int $pos |
|
|
489 |
* @param string $char has to be quoted already |
|
|
490 |
* @return string |
|
|
491 |
*/ |
|
|
492 |
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false) |
|
|
493 |
{ |
|
|
494 |
$posStr = ''; |
|
|
495 |
$trimChar = ($char != false) ? $char . ' FROM ' : ''; |
|
|
496 |
|
|
|
497 |
if ($pos == self::TRIM_LEADING) { |
|
|
498 |
$posStr = 'LEADING '.$trimChar; |
|
|
499 |
} else if($pos == self::TRIM_TRAILING) { |
|
|
500 |
$posStr = 'TRAILING '.$trimChar; |
|
|
501 |
} else if($pos == self::TRIM_BOTH) { |
|
|
502 |
$posStr = 'BOTH '.$trimChar; |
|
|
503 |
} |
|
|
504 |
|
|
|
505 |
return 'TRIM(' . $posStr . $str . ')'; |
|
|
506 |
} |
|
|
507 |
|
|
|
508 |
/** |
|
|
509 |
* rtrim |
|
|
510 |
* returns the string $str with proceeding space characters removed |
|
|
511 |
* |
|
|
512 |
* @param string $str literal string or column name |
|
|
513 |
* @return string |
|
|
514 |
*/ |
|
|
515 |
public function getRtrimExpression($str) |
|
|
516 |
{ |
|
|
517 |
return 'RTRIM(' . $str . ')'; |
|
|
518 |
} |
|
|
519 |
|
|
|
520 |
/** |
|
|
521 |
* ltrim |
|
|
522 |
* returns the string $str with leading space characters removed |
|
|
523 |
* |
|
|
524 |
* @param string $str literal string or column name |
|
|
525 |
* @return string |
|
|
526 |
*/ |
|
|
527 |
public function getLtrimExpression($str) |
|
|
528 |
{ |
|
|
529 |
return 'LTRIM(' . $str . ')'; |
|
|
530 |
} |
|
|
531 |
|
|
|
532 |
/** |
|
|
533 |
* upper |
|
|
534 |
* Returns the string $str with all characters changed to |
|
|
535 |
* uppercase according to the current character set mapping. |
|
|
536 |
* |
|
|
537 |
* @param string $str literal string or column name |
|
|
538 |
* @return string |
|
|
539 |
*/ |
|
|
540 |
public function getUpperExpression($str) |
|
|
541 |
{ |
|
|
542 |
return 'UPPER(' . $str . ')'; |
|
|
543 |
} |
|
|
544 |
|
|
|
545 |
/** |
|
|
546 |
* lower |
|
|
547 |
* Returns the string $str with all characters changed to |
|
|
548 |
* lowercase according to the current character set mapping. |
|
|
549 |
* |
|
|
550 |
* @param string $str literal string or column name |
|
|
551 |
* @return string |
|
|
552 |
*/ |
|
|
553 |
public function getLowerExpression($str) |
|
|
554 |
{ |
|
|
555 |
return 'LOWER(' . $str . ')'; |
|
|
556 |
} |
|
|
557 |
|
|
|
558 |
/** |
|
|
559 |
* returns the position of the first occurrence of substring $substr in string $str |
|
|
560 |
* |
|
|
561 |
* @param string $substr literal string to find |
|
|
562 |
* @param string $str literal string |
|
|
563 |
* @param int $pos position to start at, beginning of string by default |
|
|
564 |
* @return integer |
|
|
565 |
*/ |
|
|
566 |
public function getLocateExpression($str, $substr, $startPos = false) |
|
|
567 |
{ |
|
|
568 |
throw DBALException::notSupported(__METHOD__); |
|
|
569 |
} |
|
|
570 |
|
|
|
571 |
/** |
|
|
572 |
* Returns the current system date. |
|
|
573 |
* |
|
|
574 |
* @return string |
|
|
575 |
*/ |
|
|
576 |
public function getNowExpression() |
|
|
577 |
{ |
|
|
578 |
return 'NOW()'; |
|
|
579 |
} |
|
|
580 |
|
|
|
581 |
/** |
|
|
582 |
* return string to call a function to get a substring inside an SQL statement |
|
|
583 |
* |
|
|
584 |
* Note: Not SQL92, but common functionality. |
|
|
585 |
* |
|
|
586 |
* SQLite only supports the 2 parameter variant of this function |
|
|
587 |
* |
|
|
588 |
* @param string $value an sql string literal or column name/alias |
|
|
589 |
* @param integer $from where to start the substring portion |
|
|
590 |
* @param integer $len the substring portion length |
|
|
591 |
* @return string |
|
|
592 |
*/ |
|
|
593 |
public function getSubstringExpression($value, $from, $len = null) |
|
|
594 |
{ |
|
|
595 |
if ($len === null) |
|
|
596 |
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')'; |
|
|
597 |
else { |
|
|
598 |
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')'; |
|
|
599 |
} |
|
|
600 |
} |
|
|
601 |
|
|
|
602 |
/** |
|
|
603 |
* Returns a series of strings concatinated |
|
|
604 |
* |
|
|
605 |
* concat() accepts an arbitrary number of parameters. Each parameter |
|
|
606 |
* must contain an expression |
|
|
607 |
* |
|
|
608 |
* @param string $arg1, $arg2 ... $argN strings that will be concatinated. |
|
|
609 |
* @return string |
|
|
610 |
*/ |
|
|
611 |
public function getConcatExpression() |
|
|
612 |
{ |
|
|
613 |
return join(' || ' , func_get_args()); |
|
|
614 |
} |
|
|
615 |
|
|
|
616 |
/** |
|
|
617 |
* Returns the SQL for a logical not. |
|
|
618 |
* |
|
|
619 |
* Example: |
|
|
620 |
* <code> |
|
|
621 |
* $q = new Doctrine_Query(); |
|
|
622 |
* $e = $q->expr; |
|
|
623 |
* $q->select('*')->from('table') |
|
|
624 |
* ->where($e->eq('id', $e->not('null')); |
|
|
625 |
* </code> |
|
|
626 |
* |
|
|
627 |
* @return string a logical expression |
|
|
628 |
*/ |
|
|
629 |
public function getNotExpression($expression) |
|
|
630 |
{ |
|
|
631 |
return 'NOT(' . $expression . ')'; |
|
|
632 |
} |
|
|
633 |
|
|
|
634 |
/** |
|
|
635 |
* Returns the SQL to check if a value is one in a set of |
|
|
636 |
* given values. |
|
|
637 |
* |
|
|
638 |
* in() accepts an arbitrary number of parameters. The first parameter |
|
|
639 |
* must always specify the value that should be matched against. Successive |
|
|
640 |
* must contain a logical expression or an array with logical expressions. |
|
|
641 |
* These expressions will be matched against the first parameter. |
|
|
642 |
* |
|
|
643 |
* @param string $column the value that should be matched against |
|
|
644 |
* @param string|array(string) values that will be matched against $column |
|
|
645 |
* @return string logical expression |
|
|
646 |
*/ |
|
|
647 |
public function getInExpression($column, $values) |
|
|
648 |
{ |
|
|
649 |
if ( ! is_array($values)) { |
|
|
650 |
$values = array($values); |
|
|
651 |
} |
|
|
652 |
$values = $this->getIdentifiers($values); |
|
|
653 |
|
|
|
654 |
if (count($values) == 0) { |
|
|
655 |
throw \InvalidArgumentException('Values must not be empty.'); |
|
|
656 |
} |
|
|
657 |
return $column . ' IN (' . implode(', ', $values) . ')'; |
|
|
658 |
} |
|
|
659 |
|
|
|
660 |
/** |
|
|
661 |
* Returns SQL that checks if a expression is null. |
|
|
662 |
* |
|
|
663 |
* @param string $expression the expression that should be compared to null |
|
|
664 |
* @return string logical expression |
|
|
665 |
*/ |
|
|
666 |
public function getIsNullExpression($expression) |
|
|
667 |
{ |
|
|
668 |
return $expression . ' IS NULL'; |
|
|
669 |
} |
|
|
670 |
|
|
|
671 |
/** |
|
|
672 |
* Returns SQL that checks if a expression is not null. |
|
|
673 |
* |
|
|
674 |
* @param string $expression the expression that should be compared to null |
|
|
675 |
* @return string logical expression |
|
|
676 |
*/ |
|
|
677 |
public function getIsNotNullExpression($expression) |
|
|
678 |
{ |
|
|
679 |
return $expression . ' IS NOT NULL'; |
|
|
680 |
} |
|
|
681 |
|
|
|
682 |
/** |
|
|
683 |
* Returns SQL that checks if an expression evaluates to a value between |
|
|
684 |
* two values. |
|
|
685 |
* |
|
|
686 |
* The parameter $expression is checked if it is between $value1 and $value2. |
|
|
687 |
* |
|
|
688 |
* Note: There is a slight difference in the way BETWEEN works on some databases. |
|
|
689 |
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database |
|
|
690 |
* independence you should avoid using between(). |
|
|
691 |
* |
|
|
692 |
* @param string $expression the value to compare to |
|
|
693 |
* @param string $value1 the lower value to compare with |
|
|
694 |
* @param string $value2 the higher value to compare with |
|
|
695 |
* @return string logical expression |
|
|
696 |
*/ |
|
|
697 |
public function getBetweenExpression($expression, $value1, $value2) |
|
|
698 |
{ |
|
|
699 |
return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2; |
|
|
700 |
} |
|
|
701 |
|
|
|
702 |
public function getAcosExpression($value) |
|
|
703 |
{ |
|
|
704 |
return 'ACOS(' . $value . ')'; |
|
|
705 |
} |
|
|
706 |
|
|
|
707 |
public function getSinExpression($value) |
|
|
708 |
{ |
|
|
709 |
return 'SIN(' . $value . ')'; |
|
|
710 |
} |
|
|
711 |
|
|
|
712 |
public function getPiExpression() |
|
|
713 |
{ |
|
|
714 |
return 'PI()'; |
|
|
715 |
} |
|
|
716 |
|
|
|
717 |
public function getCosExpression($value) |
|
|
718 |
{ |
|
|
719 |
return 'COS(' . $value . ')'; |
|
|
720 |
} |
|
|
721 |
|
|
|
722 |
/** |
|
|
723 |
* Calculate the difference in days between the two passed dates. |
|
|
724 |
* |
|
|
725 |
* Computes diff = date1 - date2 |
|
|
726 |
* |
|
|
727 |
* @param string $date1 |
|
|
728 |
* @param string $date2 |
|
|
729 |
* @return string |
|
|
730 |
*/ |
|
|
731 |
public function getDateDiffExpression($date1, $date2) |
|
|
732 |
{ |
|
|
733 |
throw DBALException::notSupported(__METHOD__); |
|
|
734 |
} |
|
|
735 |
|
|
|
736 |
/** |
|
|
737 |
* Add the number of given days to a date. |
|
|
738 |
* |
|
|
739 |
* @param string $date |
|
|
740 |
* @param int $days |
|
|
741 |
* @return string |
|
|
742 |
*/ |
|
|
743 |
public function getDateAddDaysExpression($date, $days) |
|
|
744 |
{ |
|
|
745 |
throw DBALException::notSupported(__METHOD__); |
|
|
746 |
} |
|
|
747 |
|
|
|
748 |
/** |
|
|
749 |
* Substract the number of given days to a date. |
|
|
750 |
* |
|
|
751 |
* @param string $date |
|
|
752 |
* @param int $days |
|
|
753 |
* @return string |
|
|
754 |
*/ |
|
|
755 |
public function getDateSubDaysExpression($date, $days) |
|
|
756 |
{ |
|
|
757 |
throw DBALException::notSupported(__METHOD__); |
|
|
758 |
} |
|
|
759 |
|
|
|
760 |
/** |
|
|
761 |
* Add the number of given months to a date. |
|
|
762 |
* |
|
|
763 |
* @param string $date |
|
|
764 |
* @param int $months |
|
|
765 |
* @return string |
|
|
766 |
*/ |
|
|
767 |
public function getDateAddMonthExpression($date, $months) |
|
|
768 |
{ |
|
|
769 |
throw DBALException::notSupported(__METHOD__); |
|
|
770 |
} |
|
|
771 |
|
|
|
772 |
/** |
|
|
773 |
* Substract the number of given months to a date. |
|
|
774 |
* |
|
|
775 |
* @param string $date |
|
|
776 |
* @param int $months |
|
|
777 |
* @return string |
|
|
778 |
*/ |
|
|
779 |
public function getDateSubMonthExpression($date, $months) |
|
|
780 |
{ |
|
|
781 |
throw DBALException::notSupported(__METHOD__); |
|
|
782 |
} |
|
|
783 |
|
|
|
784 |
public function getForUpdateSQL() |
|
|
785 |
{ |
|
|
786 |
return 'FOR UPDATE'; |
|
|
787 |
} |
|
|
788 |
|
|
|
789 |
/** |
|
|
790 |
* Honors that some SQL vendors such as MsSql use table hints for locking instead of the ANSI SQL FOR UPDATE specification. |
|
|
791 |
* |
|
|
792 |
* @param string $fromClause |
|
|
793 |
* @param int $lockMode |
|
|
794 |
* @return string |
|
|
795 |
*/ |
|
|
796 |
public function appendLockHint($fromClause, $lockMode) |
|
|
797 |
{ |
|
|
798 |
return $fromClause; |
|
|
799 |
} |
|
|
800 |
|
|
|
801 |
/** |
|
|
802 |
* Get the sql snippet to append to any SELECT statement which locks rows in shared read lock. |
|
|
803 |
* |
|
|
804 |
* This defaults to the ASNI SQL "FOR UPDATE", which is an exclusive lock (Write). Some database |
|
|
805 |
* vendors allow to lighten this constraint up to be a real read lock. |
|
|
806 |
* |
|
|
807 |
* @return string |
|
|
808 |
*/ |
|
|
809 |
public function getReadLockSQL() |
|
|
810 |
{ |
|
|
811 |
return $this->getForUpdateSQL(); |
|
|
812 |
} |
|
|
813 |
|
|
|
814 |
/** |
|
|
815 |
* Get the SQL snippet to append to any SELECT statement which obtains an exclusive lock on the rows. |
|
|
816 |
* |
|
|
817 |
* The semantics of this lock mode should equal the SELECT .. FOR UPDATE of the ASNI SQL standard. |
|
|
818 |
* |
|
|
819 |
* @return string |
|
|
820 |
*/ |
|
|
821 |
public function getWriteLockSQL() |
|
|
822 |
{ |
|
|
823 |
return $this->getForUpdateSQL(); |
|
|
824 |
} |
|
|
825 |
|
|
|
826 |
public function getDropDatabaseSQL($database) |
|
|
827 |
{ |
|
|
828 |
return 'DROP DATABASE ' . $database; |
|
|
829 |
} |
|
|
830 |
|
|
|
831 |
/** |
|
|
832 |
* Drop a Table |
|
|
833 |
* |
|
|
834 |
* @param Table|string $table |
|
|
835 |
* @return string |
|
|
836 |
*/ |
|
|
837 |
public function getDropTableSQL($table) |
|
|
838 |
{ |
|
|
839 |
if ($table instanceof \Doctrine\DBAL\Schema\Table) { |
|
|
840 |
$table = $table->getQuotedName($this); |
|
|
841 |
} |
|
|
842 |
|
|
|
843 |
return 'DROP TABLE ' . $table; |
|
|
844 |
} |
|
|
845 |
|
|
|
846 |
/** |
|
|
847 |
* Drop index from a table |
|
|
848 |
* |
|
|
849 |
* @param Index|string $name |
|
|
850 |
* @param string|Table $table |
|
|
851 |
* @return string |
|
|
852 |
*/ |
|
|
853 |
public function getDropIndexSQL($index, $table=null) |
|
|
854 |
{ |
|
|
855 |
if($index instanceof \Doctrine\DBAL\Schema\Index) { |
|
|
856 |
$index = $index->getQuotedName($this); |
|
|
857 |
} else if(!is_string($index)) { |
|
|
858 |
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); |
|
|
859 |
} |
|
|
860 |
|
|
|
861 |
return 'DROP INDEX ' . $index; |
|
|
862 |
} |
|
|
863 |
|
|
|
864 |
/** |
|
|
865 |
* Get drop constraint sql |
|
|
866 |
* |
|
|
867 |
* @param \Doctrine\DBAL\Schema\Constraint $constraint |
|
|
868 |
* @param string|Table $table |
|
|
869 |
* @return string |
|
|
870 |
*/ |
|
|
871 |
public function getDropConstraintSQL($constraint, $table) |
|
|
872 |
{ |
|
|
873 |
if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) { |
|
|
874 |
$constraint = $constraint->getQuotedName($this); |
|
|
875 |
} |
|
|
876 |
|
|
|
877 |
if ($table instanceof \Doctrine\DBAL\Schema\Table) { |
|
|
878 |
$table = $table->getQuotedName($this); |
|
|
879 |
} |
|
|
880 |
|
|
|
881 |
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint; |
|
|
882 |
} |
|
|
883 |
|
|
|
884 |
/** |
|
|
885 |
* @param ForeignKeyConstraint|string $foreignKey |
|
|
886 |
* @param Table|string $table |
|
|
887 |
* @return string |
|
|
888 |
*/ |
|
|
889 |
public function getDropForeignKeySQL($foreignKey, $table) |
|
|
890 |
{ |
|
|
891 |
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { |
|
|
892 |
$foreignKey = $foreignKey->getQuotedName($this); |
|
|
893 |
} |
|
|
894 |
|
|
|
895 |
if ($table instanceof \Doctrine\DBAL\Schema\Table) { |
|
|
896 |
$table = $table->getQuotedName($this); |
|
|
897 |
} |
|
|
898 |
|
|
|
899 |
return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey; |
|
|
900 |
} |
|
|
901 |
|
|
|
902 |
/** |
|
|
903 |
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints |
|
|
904 |
* on this platform. |
|
|
905 |
* |
|
|
906 |
* @param string $table The name of the table. |
|
|
907 |
* @param int $createFlags |
|
|
908 |
* @return array The sequence of SQL statements. |
|
|
909 |
*/ |
|
|
910 |
public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES) |
|
|
911 |
{ |
|
|
912 |
if ( ! is_int($createFlags)) { |
|
|
913 |
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."); |
|
|
914 |
} |
|
|
915 |
|
|
|
916 |
if (count($table->getColumns()) == 0) { |
|
|
917 |
throw DBALException::noColumnsSpecifiedForTable($table->getName()); |
|
|
918 |
} |
|
|
919 |
|
|
|
920 |
$tableName = $table->getQuotedName($this); |
|
|
921 |
$options = $table->getOptions(); |
|
|
922 |
$options['uniqueConstraints'] = array(); |
|
|
923 |
$options['indexes'] = array(); |
|
|
924 |
$options['primary'] = array(); |
|
|
925 |
|
|
|
926 |
if (($createFlags&self::CREATE_INDEXES) > 0) { |
|
|
927 |
foreach ($table->getIndexes() AS $index) { |
|
|
928 |
/* @var $index Index */ |
|
|
929 |
if ($index->isPrimary()) { |
|
|
930 |
$options['primary'] = $index->getColumns(); |
|
|
931 |
} else { |
|
|
932 |
$options['indexes'][$index->getName()] = $index; |
|
|
933 |
} |
|
|
934 |
} |
|
|
935 |
} |
|
|
936 |
|
|
|
937 |
$columns = array(); |
|
|
938 |
foreach ($table->getColumns() AS $column) { |
|
|
939 |
/* @var \Doctrine\DBAL\Schema\Column $column */ |
|
|
940 |
$columnData = array(); |
|
|
941 |
$columnData['name'] = $column->getQuotedName($this); |
|
|
942 |
$columnData['type'] = $column->getType(); |
|
|
943 |
$columnData['length'] = $column->getLength(); |
|
|
944 |
$columnData['notnull'] = $column->getNotNull(); |
|
|
945 |
$columnData['fixed'] = $column->getFixed(); |
|
|
946 |
$columnData['unique'] = false; // TODO: what do we do about this? |
|
|
947 |
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false; |
|
|
948 |
if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) { |
|
|
949 |
$columnData['length'] = 255; |
|
|
950 |
} |
|
|
951 |
$columnData['unsigned'] = $column->getUnsigned(); |
|
|
952 |
$columnData['precision'] = $column->getPrecision(); |
|
|
953 |
$columnData['scale'] = $column->getScale(); |
|
|
954 |
$columnData['default'] = $column->getDefault(); |
|
|
955 |
$columnData['columnDefinition'] = $column->getColumnDefinition(); |
|
|
956 |
$columnData['autoincrement'] = $column->getAutoincrement(); |
|
|
957 |
$columnData['comment'] = $this->getColumnComment($column); |
|
|
958 |
|
|
|
959 |
if(in_array($column->getName(), $options['primary'])) { |
|
|
960 |
$columnData['primary'] = true; |
|
|
961 |
} |
|
|
962 |
|
|
|
963 |
$columns[$columnData['name']] = $columnData; |
|
|
964 |
} |
|
|
965 |
|
|
|
966 |
if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) { |
|
|
967 |
$options['foreignKeys'] = array(); |
|
|
968 |
foreach ($table->getForeignKeys() AS $fkConstraint) { |
|
|
969 |
$options['foreignKeys'][] = $fkConstraint; |
|
|
970 |
} |
|
|
971 |
} |
|
|
972 |
|
|
|
973 |
$sql = $this->_getCreateTableSQL($tableName, $columns, $options); |
|
|
974 |
if ($this->supportsCommentOnStatement()) { |
|
|
975 |
foreach ($table->getColumns() AS $column) { |
|
|
976 |
if ($column->getComment()) { |
|
|
977 |
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column)); |
|
|
978 |
} |
|
|
979 |
} |
|
|
980 |
} |
|
|
981 |
return $sql; |
|
|
982 |
} |
|
|
983 |
|
|
|
984 |
public function getCommentOnColumnSQL($tableName, $columnName, $comment) |
|
|
985 |
{ |
|
|
986 |
return "COMMENT ON COLUMN " . $tableName . "." . $columnName . " IS '" . $comment . "'"; |
|
|
987 |
} |
|
|
988 |
|
|
|
989 |
/** |
|
|
990 |
* @param string $tableName |
|
|
991 |
* @param array $columns |
|
|
992 |
* @param array $options |
|
|
993 |
* @return array |
|
|
994 |
*/ |
|
|
995 |
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) |
|
|
996 |
{ |
|
|
997 |
$columnListSql = $this->getColumnDeclarationListSQL($columns); |
|
|
998 |
|
|
|
999 |
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { |
|
|
1000 |
foreach ($options['uniqueConstraints'] as $name => $definition) { |
|
|
1001 |
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); |
|
|
1002 |
} |
|
|
1003 |
} |
|
|
1004 |
|
|
|
1005 |
if (isset($options['primary']) && ! empty($options['primary'])) { |
|
|
1006 |
$columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')'; |
|
|
1007 |
} |
|
|
1008 |
|
|
|
1009 |
if (isset($options['indexes']) && ! empty($options['indexes'])) { |
|
|
1010 |
foreach($options['indexes'] as $index => $definition) { |
|
|
1011 |
$columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition); |
|
|
1012 |
} |
|
|
1013 |
} |
|
|
1014 |
|
|
|
1015 |
$query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; |
|
|
1016 |
|
|
|
1017 |
$check = $this->getCheckDeclarationSQL($columns); |
|
|
1018 |
if ( ! empty($check)) { |
|
|
1019 |
$query .= ', ' . $check; |
|
|
1020 |
} |
|
|
1021 |
$query .= ')'; |
|
|
1022 |
|
|
|
1023 |
$sql[] = $query; |
|
|
1024 |
|
|
|
1025 |
if (isset($options['foreignKeys'])) { |
|
|
1026 |
foreach ((array) $options['foreignKeys'] AS $definition) { |
|
|
1027 |
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName); |
|
|
1028 |
} |
|
|
1029 |
} |
|
|
1030 |
|
|
|
1031 |
return $sql; |
|
|
1032 |
} |
|
|
1033 |
|
|
|
1034 |
public function getCreateTemporaryTableSnippetSQL() |
|
|
1035 |
{ |
|
|
1036 |
return "CREATE TEMPORARY TABLE"; |
|
|
1037 |
} |
|
|
1038 |
|
|
|
1039 |
/** |
|
|
1040 |
* Gets the SQL to create a sequence on this platform. |
|
|
1041 |
* |
|
|
1042 |
* @param \Doctrine\DBAL\Schema\Sequence $sequence |
|
|
1043 |
* @throws DBALException |
|
|
1044 |
*/ |
|
|
1045 |
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) |
|
|
1046 |
{ |
|
|
1047 |
throw DBALException::notSupported(__METHOD__); |
|
|
1048 |
} |
|
|
1049 |
|
|
|
1050 |
/** |
|
|
1051 |
* Gets the SQL statement to change a sequence on this platform. |
|
|
1052 |
* |
|
|
1053 |
* @param \Doctrine\DBAL\Schema\Sequence $sequence |
|
|
1054 |
* @return string |
|
|
1055 |
*/ |
|
|
1056 |
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) |
|
|
1057 |
{ |
|
|
1058 |
throw DBALException::notSupported(__METHOD__); |
|
|
1059 |
} |
|
|
1060 |
|
|
|
1061 |
/** |
|
|
1062 |
* Gets the SQL to create a constraint on a table on this platform. |
|
|
1063 |
* |
|
|
1064 |
* @param Constraint $constraint |
|
|
1065 |
* @param string|Table $table |
|
|
1066 |
* @return string |
|
|
1067 |
*/ |
|
|
1068 |
public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table) |
|
|
1069 |
{ |
|
|
1070 |
if ($table instanceof \Doctrine\DBAL\Schema\Table) { |
|
|
1071 |
$table = $table->getQuotedName($this); |
|
|
1072 |
} |
|
|
1073 |
|
|
|
1074 |
$query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this); |
|
|
1075 |
|
|
|
1076 |
$columns = array(); |
|
|
1077 |
foreach ($constraint->getColumns() as $column) { |
|
|
1078 |
$columns[] = $column; |
|
|
1079 |
} |
|
|
1080 |
$columnList = '('. implode(', ', $columns) . ')'; |
|
|
1081 |
|
|
|
1082 |
$referencesClause = ''; |
|
|
1083 |
if ($constraint instanceof \Doctrine\DBAL\Schema\Index) { |
|
|
1084 |
if($constraint->isPrimary()) { |
|
|
1085 |
$query .= ' PRIMARY KEY'; |
|
|
1086 |
} elseif ($constraint->isUnique()) { |
|
|
1087 |
$query .= ' UNIQUE'; |
|
|
1088 |
} else { |
|
|
1089 |
throw new \InvalidArgumentException( |
|
|
1090 |
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' |
|
|
1091 |
); |
|
|
1092 |
} |
|
|
1093 |
} else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { |
|
|
1094 |
$query .= ' FOREIGN KEY'; |
|
|
1095 |
|
|
|
1096 |
$foreignColumns = array(); |
|
|
1097 |
foreach ($constraint->getForeignColumns() AS $column) { |
|
|
1098 |
$foreignColumns[] = $column; |
|
|
1099 |
} |
|
|
1100 |
|
|
|
1101 |
$referencesClause = ' REFERENCES '.$constraint->getForeignTableName(). ' ('.implode(', ', $foreignColumns).')'; |
|
|
1102 |
} |
|
|
1103 |
$query .= ' '.$columnList.$referencesClause; |
|
|
1104 |
|
|
|
1105 |
return $query; |
|
|
1106 |
} |
|
|
1107 |
|
|
|
1108 |
/** |
|
|
1109 |
* Gets the SQL to create an index on a table on this platform. |
|
|
1110 |
* |
|
|
1111 |
* @param Index $index |
|
|
1112 |
* @param string|Table $table name of the table on which the index is to be created |
|
|
1113 |
* @return string |
|
|
1114 |
*/ |
|
|
1115 |
public function getCreateIndexSQL(Index $index, $table) |
|
|
1116 |
{ |
|
|
1117 |
if ($table instanceof Table) { |
|
|
1118 |
$table = $table->getQuotedName($this); |
|
|
1119 |
} |
|
|
1120 |
$name = $index->getQuotedName($this); |
|
|
1121 |
$columns = $index->getColumns(); |
|
|
1122 |
|
|
|
1123 |
if (count($columns) == 0) { |
|
|
1124 |
throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); |
|
|
1125 |
} |
|
|
1126 |
|
|
|
1127 |
if ($index->isPrimary()) { |
|
|
1128 |
return $this->getCreatePrimaryKeySQL($index, $table); |
|
|
1129 |
} else { |
|
|
1130 |
$type = ''; |
|
|
1131 |
if ($index->isUnique()) { |
|
|
1132 |
$type = 'UNIQUE '; |
|
|
1133 |
} |
|
|
1134 |
|
|
|
1135 |
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table; |
|
|
1136 |
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')'; |
|
|
1137 |
} |
|
|
1138 |
|
|
|
1139 |
return $query; |
|
|
1140 |
} |
|
|
1141 |
|
|
|
1142 |
/** |
|
|
1143 |
* Get SQL to create an unnamed primary key constraint. |
|
|
1144 |
* |
|
|
1145 |
* @param Index $index |
|
|
1146 |
* @param string|Table $table |
|
|
1147 |
* @return string |
|
|
1148 |
*/ |
|
|
1149 |
public function getCreatePrimaryKeySQL(Index $index, $table) |
|
|
1150 |
{ |
|
|
1151 |
return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getColumns()) . ')'; |
|
|
1152 |
} |
|
|
1153 |
|
|
|
1154 |
/** |
|
|
1155 |
* Quotes a string so that it can be safely used as a table or column name, |
|
|
1156 |
* even if it is a reserved word of the platform. |
|
|
1157 |
* |
|
|
1158 |
* NOTE: Just because you CAN use quoted identifiers doesn't mean |
|
|
1159 |
* you SHOULD use them. In general, they end up causing way more |
|
|
1160 |
* problems than they solve. |
|
|
1161 |
* |
|
|
1162 |
* @param string $str identifier name to be quoted |
|
|
1163 |
* @return string quoted identifier string |
|
|
1164 |
*/ |
|
|
1165 |
public function quoteIdentifier($str) |
|
|
1166 |
{ |
|
|
1167 |
$c = $this->getIdentifierQuoteCharacter(); |
|
|
1168 |
|
|
|
1169 |
return $c . $str . $c; |
|
|
1170 |
} |
|
|
1171 |
|
|
|
1172 |
/** |
|
|
1173 |
* Create a new foreign key |
|
|
1174 |
* |
|
|
1175 |
* @param ForeignKeyConstraint $foreignKey ForeignKey instance |
|
|
1176 |
* @param string|Table $table name of the table on which the foreign key is to be created |
|
|
1177 |
* @return string |
|
|
1178 |
*/ |
|
|
1179 |
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) |
|
|
1180 |
{ |
|
|
1181 |
if ($table instanceof \Doctrine\DBAL\Schema\Table) { |
|
|
1182 |
$table = $table->getQuotedName($this); |
|
|
1183 |
} |
|
|
1184 |
|
|
|
1185 |
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey); |
|
|
1186 |
|
|
|
1187 |
return $query; |
|
|
1188 |
} |
|
|
1189 |
|
|
|
1190 |
/** |
|
|
1191 |
* Gets the sql statements for altering an existing table. |
|
|
1192 |
* |
|
|
1193 |
* The method returns an array of sql statements, since some platforms need several statements. |
|
|
1194 |
* |
|
|
1195 |
* @param TableDiff $diff |
|
|
1196 |
* @return array |
|
|
1197 |
*/ |
|
|
1198 |
public function getAlterTableSQL(TableDiff $diff) |
|
|
1199 |
{ |
|
|
1200 |
throw DBALException::notSupported(__METHOD__); |
|
|
1201 |
} |
|
|
1202 |
|
|
|
1203 |
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) |
|
|
1204 |
{ |
|
|
1205 |
$tableName = $diff->name; |
|
|
1206 |
|
|
|
1207 |
$sql = array(); |
|
|
1208 |
if ($this->supportsForeignKeyConstraints()) { |
|
|
1209 |
foreach ($diff->removedForeignKeys AS $foreignKey) { |
|
|
1210 |
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); |
|
|
1211 |
} |
|
|
1212 |
foreach ($diff->changedForeignKeys AS $foreignKey) { |
|
|
1213 |
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); |
|
|
1214 |
} |
|
|
1215 |
} |
|
|
1216 |
|
|
|
1217 |
foreach ($diff->removedIndexes AS $index) { |
|
|
1218 |
$sql[] = $this->getDropIndexSQL($index, $tableName); |
|
|
1219 |
} |
|
|
1220 |
foreach ($diff->changedIndexes AS $index) { |
|
|
1221 |
$sql[] = $this->getDropIndexSQL($index, $tableName); |
|
|
1222 |
} |
|
|
1223 |
|
|
|
1224 |
return $sql; |
|
|
1225 |
} |
|
|
1226 |
|
|
|
1227 |
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) |
|
|
1228 |
{ |
|
|
1229 |
if ($diff->newName !== false) { |
|
|
1230 |
$tableName = $diff->newName; |
|
|
1231 |
} else { |
|
|
1232 |
$tableName = $diff->name; |
|
|
1233 |
} |
|
|
1234 |
|
|
|
1235 |
$sql = array(); |
|
|
1236 |
if ($this->supportsForeignKeyConstraints()) { |
|
|
1237 |
foreach ($diff->addedForeignKeys AS $foreignKey) { |
|
|
1238 |
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); |
|
|
1239 |
} |
|
|
1240 |
foreach ($diff->changedForeignKeys AS $foreignKey) { |
|
|
1241 |
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); |
|
|
1242 |
} |
|
|
1243 |
} |
|
|
1244 |
|
|
|
1245 |
foreach ($diff->addedIndexes AS $index) { |
|
|
1246 |
$sql[] = $this->getCreateIndexSQL($index, $tableName); |
|
|
1247 |
} |
|
|
1248 |
foreach ($diff->changedIndexes AS $index) { |
|
|
1249 |
$sql[] = $this->getCreateIndexSQL($index, $tableName); |
|
|
1250 |
} |
|
|
1251 |
|
|
|
1252 |
return $sql; |
|
|
1253 |
} |
|
|
1254 |
|
|
|
1255 |
/** |
|
|
1256 |
* Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. |
|
|
1257 |
* |
|
|
1258 |
* @param TableDiff $diff |
|
|
1259 |
* @return array |
|
|
1260 |
*/ |
|
|
1261 |
protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) |
|
|
1262 |
{ |
|
|
1263 |
return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff)); |
|
|
1264 |
} |
|
|
1265 |
|
|
|
1266 |
/** |
|
|
1267 |
* Get declaration of a number of fields in bulk |
|
|
1268 |
* |
|
|
1269 |
* @param array $fields a multidimensional associative array. |
|
|
1270 |
* The first dimension determines the field name, while the second |
|
|
1271 |
* dimension is keyed with the name of the properties |
|
|
1272 |
* of the field being declared as array indexes. Currently, the types |
|
|
1273 |
* of supported field properties are as follows: |
|
|
1274 |
* |
|
|
1275 |
* length |
|
|
1276 |
* Integer value that determines the maximum length of the text |
|
|
1277 |
* field. If this argument is missing the field should be |
|
|
1278 |
* declared to have the longest length allowed by the DBMS. |
|
|
1279 |
* |
|
|
1280 |
* default |
|
|
1281 |
* Text value to be used as default for this field. |
|
|
1282 |
* |
|
|
1283 |
* notnull |
|
|
1284 |
* Boolean flag that indicates whether this field is constrained |
|
|
1285 |
* to not be set to null. |
|
|
1286 |
* charset |
|
|
1287 |
* Text value with the default CHARACTER SET for this field. |
|
|
1288 |
* collation |
|
|
1289 |
* Text value with the default COLLATION for this field. |
|
|
1290 |
* unique |
|
|
1291 |
* unique constraint |
|
|
1292 |
* |
|
|
1293 |
* @return string |
|
|
1294 |
*/ |
|
|
1295 |
public function getColumnDeclarationListSQL(array $fields) |
|
|
1296 |
{ |
|
|
1297 |
$queryFields = array(); |
|
|
1298 |
foreach ($fields as $fieldName => $field) { |
|
|
1299 |
$query = $this->getColumnDeclarationSQL($fieldName, $field); |
|
|
1300 |
$queryFields[] = $query; |
|
|
1301 |
} |
|
|
1302 |
return implode(', ', $queryFields); |
|
|
1303 |
} |
|
|
1304 |
|
|
|
1305 |
/** |
|
|
1306 |
* Obtain DBMS specific SQL code portion needed to declare a generic type |
|
|
1307 |
* field to be used in statements like CREATE TABLE. |
|
|
1308 |
* |
|
|
1309 |
* @param string $name name the field to be declared. |
|
|
1310 |
* @param array $field associative array with the name of the properties |
|
|
1311 |
* of the field being declared as array indexes. Currently, the types |
|
|
1312 |
* of supported field properties are as follows: |
|
|
1313 |
* |
|
|
1314 |
* length |
|
|
1315 |
* Integer value that determines the maximum length of the text |
|
|
1316 |
* field. If this argument is missing the field should be |
|
|
1317 |
* declared to have the longest length allowed by the DBMS. |
|
|
1318 |
* |
|
|
1319 |
* default |
|
|
1320 |
* Text value to be used as default for this field. |
|
|
1321 |
* |
|
|
1322 |
* notnull |
|
|
1323 |
* Boolean flag that indicates whether this field is constrained |
|
|
1324 |
* to not be set to null. |
|
|
1325 |
* charset |
|
|
1326 |
* Text value with the default CHARACTER SET for this field. |
|
|
1327 |
* collation |
|
|
1328 |
* Text value with the default COLLATION for this field. |
|
|
1329 |
* unique |
|
|
1330 |
* unique constraint |
|
|
1331 |
* check |
|
|
1332 |
* column check constraint |
|
|
1333 |
* columnDefinition |
|
|
1334 |
* a string that defines the complete column |
|
|
1335 |
* |
|
|
1336 |
* @return string DBMS specific SQL code portion that should be used to declare the column. |
|
|
1337 |
*/ |
|
|
1338 |
public function getColumnDeclarationSQL($name, array $field) |
|
|
1339 |
{ |
|
|
1340 |
if (isset($field['columnDefinition'])) { |
|
|
1341 |
$columnDef = $this->getCustomTypeDeclarationSQL($field); |
|
|
1342 |
} else { |
|
|
1343 |
$default = $this->getDefaultValueDeclarationSQL($field); |
|
|
1344 |
|
|
|
1345 |
$charset = (isset($field['charset']) && $field['charset']) ? |
|
|
1346 |
' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : ''; |
|
|
1347 |
|
|
|
1348 |
$collation = (isset($field['collation']) && $field['collation']) ? |
|
|
1349 |
' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; |
|
|
1350 |
|
|
|
1351 |
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; |
|
|
1352 |
|
|
|
1353 |
$unique = (isset($field['unique']) && $field['unique']) ? |
|
|
1354 |
' ' . $this->getUniqueFieldDeclarationSQL() : ''; |
|
|
1355 |
|
|
|
1356 |
$check = (isset($field['check']) && $field['check']) ? |
|
|
1357 |
' ' . $field['check'] : ''; |
|
|
1358 |
|
|
|
1359 |
$typeDecl = $field['type']->getSqlDeclaration($field, $this); |
|
|
1360 |
$columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; |
|
|
1361 |
} |
|
|
1362 |
|
|
|
1363 |
if ($this->supportsInlineColumnComments() && isset($field['comment']) && $field['comment']) { |
|
|
1364 |
$columnDef .= " COMMENT '" . $field['comment'] . "'"; |
|
|
1365 |
} |
|
|
1366 |
|
|
|
1367 |
return $name . ' ' . $columnDef; |
|
|
1368 |
} |
|
|
1369 |
|
|
|
1370 |
/** |
|
|
1371 |
* Gets the SQL snippet that declares a floating point column of arbitrary precision. |
|
|
1372 |
* |
|
|
1373 |
* @param array $columnDef |
|
|
1374 |
* @return string |
|
|
1375 |
*/ |
|
|
1376 |
public function getDecimalTypeDeclarationSQL(array $columnDef) |
|
|
1377 |
{ |
|
|
1378 |
$columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision'])) |
|
|
1379 |
? 10 : $columnDef['precision']; |
|
|
1380 |
$columnDef['scale'] = ( ! isset($columnDef['scale']) || empty($columnDef['scale'])) |
|
|
1381 |
? 0 : $columnDef['scale']; |
|
|
1382 |
|
|
|
1383 |
return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')'; |
|
|
1384 |
} |
|
|
1385 |
|
|
|
1386 |
/** |
|
|
1387 |
* Obtain DBMS specific SQL code portion needed to set a default value |
|
|
1388 |
* declaration to be used in statements like CREATE TABLE. |
|
|
1389 |
* |
|
|
1390 |
* @param array $field field definition array |
|
|
1391 |
* @return string DBMS specific SQL code portion needed to set a default value |
|
|
1392 |
*/ |
|
|
1393 |
public function getDefaultValueDeclarationSQL($field) |
|
|
1394 |
{ |
|
|
1395 |
$default = empty($field['notnull']) ? ' DEFAULT NULL' : ''; |
|
|
1396 |
|
|
|
1397 |
if (isset($field['default'])) { |
|
|
1398 |
$default = " DEFAULT '".$field['default']."'"; |
|
|
1399 |
if (isset($field['type'])) { |
|
|
1400 |
if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) { |
|
|
1401 |
$default = " DEFAULT ".$field['default']; |
|
|
1402 |
} else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) { |
|
|
1403 |
$default = " DEFAULT ".$this->getCurrentTimestampSQL(); |
|
|
1404 |
} |
|
|
1405 |
} |
|
|
1406 |
} |
|
|
1407 |
return $default; |
|
|
1408 |
} |
|
|
1409 |
|
|
|
1410 |
/** |
|
|
1411 |
* Obtain DBMS specific SQL code portion needed to set a CHECK constraint |
|
|
1412 |
* declaration to be used in statements like CREATE TABLE. |
|
|
1413 |
* |
|
|
1414 |
* @param array $definition check definition |
|
|
1415 |
* @return string DBMS specific SQL code portion needed to set a CHECK constraint |
|
|
1416 |
*/ |
|
|
1417 |
public function getCheckDeclarationSQL(array $definition) |
|
|
1418 |
{ |
|
|
1419 |
$constraints = array(); |
|
|
1420 |
foreach ($definition as $field => $def) { |
|
|
1421 |
if (is_string($def)) { |
|
|
1422 |
$constraints[] = 'CHECK (' . $def . ')'; |
|
|
1423 |
} else { |
|
|
1424 |
if (isset($def['min'])) { |
|
|
1425 |
$constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')'; |
|
|
1426 |
} |
|
|
1427 |
|
|
|
1428 |
if (isset($def['max'])) { |
|
|
1429 |
$constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')'; |
|
|
1430 |
} |
|
|
1431 |
} |
|
|
1432 |
} |
|
|
1433 |
|
|
|
1434 |
return implode(', ', $constraints); |
|
|
1435 |
} |
|
|
1436 |
|
|
|
1437 |
/** |
|
|
1438 |
* Obtain DBMS specific SQL code portion needed to set a unique |
|
|
1439 |
* constraint declaration to be used in statements like CREATE TABLE. |
|
|
1440 |
* |
|
|
1441 |
* @param string $name name of the unique constraint |
|
|
1442 |
* @param Index $index index definition |
|
|
1443 |
* @return string DBMS specific SQL code portion needed |
|
|
1444 |
* to set a constraint |
|
|
1445 |
*/ |
|
|
1446 |
public function getUniqueConstraintDeclarationSQL($name, Index $index) |
|
|
1447 |
{ |
|
|
1448 |
if (count($index->getColumns()) == 0) { |
|
|
1449 |
throw \InvalidArgumentException("Incomplete definition. 'columns' required."); |
|
|
1450 |
} |
|
|
1451 |
|
|
|
1452 |
return 'CONSTRAINT ' . $name . ' UNIQUE (' |
|
|
1453 |
. $this->getIndexFieldDeclarationListSQL($index->getColumns()) |
|
|
1454 |
. ')'; |
|
|
1455 |
} |
|
|
1456 |
|
|
|
1457 |
/** |
|
|
1458 |
* Obtain DBMS specific SQL code portion needed to set an index |
|
|
1459 |
* declaration to be used in statements like CREATE TABLE. |
|
|
1460 |
* |
|
|
1461 |
* @param string $name name of the index |
|
|
1462 |
* @param Index $index index definition |
|
|
1463 |
* @return string DBMS specific SQL code portion needed to set an index |
|
|
1464 |
*/ |
|
|
1465 |
public function getIndexDeclarationSQL($name, Index $index) |
|
|
1466 |
{ |
|
|
1467 |
$type = ''; |
|
|
1468 |
|
|
|
1469 |
if($index->isUnique()) { |
|
|
1470 |
$type = 'UNIQUE '; |
|
|
1471 |
} |
|
|
1472 |
|
|
|
1473 |
if (count($index->getColumns()) == 0) { |
|
|
1474 |
throw \InvalidArgumentException("Incomplete definition. 'columns' required."); |
|
|
1475 |
} |
|
|
1476 |
|
|
|
1477 |
return $type . 'INDEX ' . $name . ' (' |
|
|
1478 |
. $this->getIndexFieldDeclarationListSQL($index->getColumns()) |
|
|
1479 |
. ')'; |
|
|
1480 |
} |
|
|
1481 |
|
|
|
1482 |
/** |
|
|
1483 |
* getCustomTypeDeclarationSql |
|
|
1484 |
* Obtail SQL code portion needed to create a custom column, |
|
|
1485 |
* e.g. when a field has the "columnDefinition" keyword. |
|
|
1486 |
* Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate. |
|
|
1487 |
* |
|
|
1488 |
* @return string |
|
|
1489 |
*/ |
|
|
1490 |
public function getCustomTypeDeclarationSQL(array $columnDef) |
|
|
1491 |
{ |
|
|
1492 |
return $columnDef['columnDefinition']; |
|
|
1493 |
} |
|
|
1494 |
|
|
|
1495 |
/** |
|
|
1496 |
* getIndexFieldDeclarationList |
|
|
1497 |
* Obtain DBMS specific SQL code portion needed to set an index |
|
|
1498 |
* declaration to be used in statements like CREATE TABLE. |
|
|
1499 |
* |
|
|
1500 |
* @return string |
|
|
1501 |
*/ |
|
|
1502 |
public function getIndexFieldDeclarationListSQL(array $fields) |
|
|
1503 |
{ |
|
|
1504 |
$ret = array(); |
|
|
1505 |
foreach ($fields as $field => $definition) { |
|
|
1506 |
if (is_array($definition)) { |
|
|
1507 |
$ret[] = $field; |
|
|
1508 |
} else { |
|
|
1509 |
$ret[] = $definition; |
|
|
1510 |
} |
|
|
1511 |
} |
|
|
1512 |
return implode(', ', $ret); |
|
|
1513 |
} |
|
|
1514 |
|
|
|
1515 |
/** |
|
|
1516 |
* A method to return the required SQL string that fits between CREATE ... TABLE |
|
|
1517 |
* to create the table as a temporary table. |
|
|
1518 |
* |
|
|
1519 |
* Should be overridden in driver classes to return the correct string for the |
|
|
1520 |
* specific database type. |
|
|
1521 |
* |
|
|
1522 |
* The default is to return the string "TEMPORARY" - this will result in a |
|
|
1523 |
* SQL error for any database that does not support temporary tables, or that |
|
|
1524 |
* requires a different SQL command from "CREATE TEMPORARY TABLE". |
|
|
1525 |
* |
|
|
1526 |
* @return string The string required to be placed between "CREATE" and "TABLE" |
|
|
1527 |
* to generate a temporary table, if possible. |
|
|
1528 |
*/ |
|
|
1529 |
public function getTemporaryTableSQL() |
|
|
1530 |
{ |
|
|
1531 |
return 'TEMPORARY'; |
|
|
1532 |
} |
|
|
1533 |
|
|
|
1534 |
/** |
|
|
1535 |
* Some vendors require temporary table names to be qualified specially. |
|
|
1536 |
* |
|
|
1537 |
* @param string $tableName |
|
|
1538 |
* @return string |
|
|
1539 |
*/ |
|
|
1540 |
public function getTemporaryTableName($tableName) |
|
|
1541 |
{ |
|
|
1542 |
return $tableName; |
|
|
1543 |
} |
|
|
1544 |
|
|
|
1545 |
/** |
|
|
1546 |
* Get sql query to show a list of database. |
|
|
1547 |
* |
|
|
1548 |
* @return string |
|
|
1549 |
*/ |
|
|
1550 |
public function getShowDatabasesSQL() |
|
|
1551 |
{ |
|
|
1552 |
throw DBALException::notSupported(__METHOD__); |
|
|
1553 |
} |
|
|
1554 |
|
|
|
1555 |
/** |
|
|
1556 |
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
|
|
1557 |
* of a field declaration to be used in statements like CREATE TABLE. |
|
|
1558 |
* |
|
|
1559 |
* @param array $definition an associative array with the following structure: |
|
|
1560 |
* name optional constraint name |
|
|
1561 |
* |
|
|
1562 |
* local the local field(s) |
|
|
1563 |
* |
|
|
1564 |
* foreign the foreign reference field(s) |
|
|
1565 |
* |
|
|
1566 |
* foreignTable the name of the foreign table |
|
|
1567 |
* |
|
|
1568 |
* onDelete referential delete action |
|
|
1569 |
* |
|
|
1570 |
* onUpdate referential update action |
|
|
1571 |
* |
|
|
1572 |
* deferred deferred constraint checking |
|
|
1573 |
* |
|
|
1574 |
* The onDelete and onUpdate keys accept the following values: |
|
|
1575 |
* |
|
|
1576 |
* CASCADE: Delete or update the row from the parent table and automatically delete or |
|
|
1577 |
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. |
|
|
1578 |
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column |
|
|
1579 |
* in the parent table or in the child table. |
|
|
1580 |
* |
|
|
1581 |
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the |
|
|
1582 |
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier |
|
|
1583 |
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported. |
|
|
1584 |
* |
|
|
1585 |
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary |
|
|
1586 |
* key value is not allowed to proceed if there is a related foreign key value in the referenced table. |
|
|
1587 |
* |
|
|
1588 |
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as |
|
|
1589 |
* omitting the ON DELETE or ON UPDATE clause. |
|
|
1590 |
* |
|
|
1591 |
* SET DEFAULT |
|
|
1592 |
* |
|
|
1593 |
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
|
|
1594 |
* of a field declaration. |
|
|
1595 |
*/ |
|
|
1596 |
public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) |
|
|
1597 |
{ |
|
|
1598 |
$sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey); |
|
|
1599 |
$sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey); |
|
|
1600 |
|
|
|
1601 |
return $sql; |
|
|
1602 |
} |
|
|
1603 |
|
|
|
1604 |
/** |
|
|
1605 |
* Return the FOREIGN KEY query section dealing with non-standard options |
|
|
1606 |
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... |
|
|
1607 |
* |
|
|
1608 |
* @param ForeignKeyConstraint $foreignKey foreign key definition |
|
|
1609 |
* @return string |
|
|
1610 |
*/ |
|
|
1611 |
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) |
|
|
1612 |
{ |
|
|
1613 |
$query = ''; |
|
|
1614 |
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) { |
|
|
1615 |
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate')); |
|
|
1616 |
} |
|
|
1617 |
if ($foreignKey->hasOption('onDelete')) { |
|
|
1618 |
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete')); |
|
|
1619 |
} |
|
|
1620 |
return $query; |
|
|
1621 |
} |
|
|
1622 |
|
|
|
1623 |
/** |
|
|
1624 |
* returns given referential action in uppercase if valid, otherwise throws |
|
|
1625 |
* an exception |
|
|
1626 |
* |
|
|
1627 |
* @throws Doctrine_Exception_Exception if unknown referential action given |
|
|
1628 |
* @param string $action foreign key referential action |
|
|
1629 |
* @param string foreign key referential action in uppercase |
|
|
1630 |
*/ |
|
|
1631 |
public function getForeignKeyReferentialActionSQL($action) |
|
|
1632 |
{ |
|
|
1633 |
$upper = strtoupper($action); |
|
|
1634 |
switch ($upper) { |
|
|
1635 |
case 'CASCADE': |
|
|
1636 |
case 'SET NULL': |
|
|
1637 |
case 'NO ACTION': |
|
|
1638 |
case 'RESTRICT': |
|
|
1639 |
case 'SET DEFAULT': |
|
|
1640 |
return $upper; |
|
|
1641 |
break; |
|
|
1642 |
default: |
|
|
1643 |
throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper); |
|
|
1644 |
} |
|
|
1645 |
} |
|
|
1646 |
|
|
|
1647 |
/** |
|
|
1648 |
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
|
|
1649 |
* of a field declaration to be used in statements like CREATE TABLE. |
|
|
1650 |
* |
|
|
1651 |
* @param ForeignKeyConstraint $foreignKey |
|
|
1652 |
* @return string |
|
|
1653 |
*/ |
|
|
1654 |
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) |
|
|
1655 |
{ |
|
|
1656 |
$sql = ''; |
|
|
1657 |
if (strlen($foreignKey->getName())) { |
|
|
1658 |
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; |
|
|
1659 |
} |
|
|
1660 |
$sql .= 'FOREIGN KEY ('; |
|
|
1661 |
|
|
|
1662 |
if (count($foreignKey->getLocalColumns()) == 0) { |
|
|
1663 |
throw new \InvalidArgumentException("Incomplete definition. 'local' required."); |
|
|
1664 |
} |
|
|
1665 |
if (count($foreignKey->getForeignColumns()) == 0) { |
|
|
1666 |
throw new \InvalidArgumentException("Incomplete definition. 'foreign' required."); |
|
|
1667 |
} |
|
|
1668 |
if (strlen($foreignKey->getForeignTableName()) == 0) { |
|
|
1669 |
throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required."); |
|
|
1670 |
} |
|
|
1671 |
|
|
|
1672 |
$sql .= implode(', ', $foreignKey->getLocalColumns()) |
|
|
1673 |
. ') REFERENCES ' |
|
|
1674 |
. $foreignKey->getForeignTableName() . '(' |
|
|
1675 |
. implode(', ', $foreignKey->getForeignColumns()) . ')'; |
|
|
1676 |
|
|
|
1677 |
return $sql; |
|
|
1678 |
} |
|
|
1679 |
|
|
|
1680 |
/** |
|
|
1681 |
* Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint |
|
|
1682 |
* of a field declaration to be used in statements like CREATE TABLE. |
|
|
1683 |
* |
|
|
1684 |
* @return string DBMS specific SQL code portion needed to set the UNIQUE constraint |
|
|
1685 |
* of a field declaration. |
|
|
1686 |
*/ |
|
|
1687 |
public function getUniqueFieldDeclarationSQL() |
|
|
1688 |
{ |
|
|
1689 |
return 'UNIQUE'; |
|
|
1690 |
} |
|
|
1691 |
|
|
|
1692 |
/** |
|
|
1693 |
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET |
|
|
1694 |
* of a field declaration to be used in statements like CREATE TABLE. |
|
|
1695 |
* |
|
|
1696 |
* @param string $charset name of the charset |
|
|
1697 |
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET |
|
|
1698 |
* of a field declaration. |
|
|
1699 |
*/ |
|
|
1700 |
public function getColumnCharsetDeclarationSQL($charset) |
|
|
1701 |
{ |
|
|
1702 |
return ''; |
|
|
1703 |
} |
|
|
1704 |
|
|
|
1705 |
/** |
|
|
1706 |
* Obtain DBMS specific SQL code portion needed to set the COLLATION |
|
|
1707 |
* of a field declaration to be used in statements like CREATE TABLE. |
|
|
1708 |
* |
|
|
1709 |
* @param string $collation name of the collation |
|
|
1710 |
* @return string DBMS specific SQL code portion needed to set the COLLATION |
|
|
1711 |
* of a field declaration. |
|
|
1712 |
*/ |
|
|
1713 |
public function getColumnCollationDeclarationSQL($collation) |
|
|
1714 |
{ |
|
|
1715 |
return ''; |
|
|
1716 |
} |
|
|
1717 |
|
|
|
1718 |
/** |
|
|
1719 |
* Whether the platform prefers sequences for ID generation. |
|
|
1720 |
* Subclasses should override this method to return TRUE if they prefer sequences. |
|
|
1721 |
* |
|
|
1722 |
* @return boolean |
|
|
1723 |
*/ |
|
|
1724 |
public function prefersSequences() |
|
|
1725 |
{ |
|
|
1726 |
return false; |
|
|
1727 |
} |
|
|
1728 |
|
|
|
1729 |
/** |
|
|
1730 |
* Whether the platform prefers identity columns (eg. autoincrement) for ID generation. |
|
|
1731 |
* Subclasses should override this method to return TRUE if they prefer identity columns. |
|
|
1732 |
* |
|
|
1733 |
* @return boolean |
|
|
1734 |
*/ |
|
|
1735 |
public function prefersIdentityColumns() |
|
|
1736 |
{ |
|
|
1737 |
return false; |
|
|
1738 |
} |
|
|
1739 |
|
|
|
1740 |
/** |
|
|
1741 |
* Some platforms need the boolean values to be converted. |
|
|
1742 |
* |
|
|
1743 |
* The default conversion in this implementation converts to integers (false => 0, true => 1). |
|
|
1744 |
* |
|
|
1745 |
* @param mixed $item |
|
|
1746 |
*/ |
|
|
1747 |
public function convertBooleans($item) |
|
|
1748 |
{ |
|
|
1749 |
if (is_array($item)) { |
|
|
1750 |
foreach ($item as $k => $value) { |
|
|
1751 |
if (is_bool($value)) { |
|
|
1752 |
$item[$k] = (int) $value; |
|
|
1753 |
} |
|
|
1754 |
} |
|
|
1755 |
} else if (is_bool($item)) { |
|
|
1756 |
$item = (int) $item; |
|
|
1757 |
} |
|
|
1758 |
return $item; |
|
|
1759 |
} |
|
|
1760 |
|
|
|
1761 |
/** |
|
|
1762 |
* Gets the SQL statement specific for the platform to set the charset. |
|
|
1763 |
* |
|
|
1764 |
* This function is MySQL specific and required by |
|
|
1765 |
* {@see \Doctrine\DBAL\Connection::setCharset($charset)} |
|
|
1766 |
* |
|
|
1767 |
* @param string $charset |
|
|
1768 |
* @return string |
|
|
1769 |
*/ |
|
|
1770 |
public function getSetCharsetSQL($charset) |
|
|
1771 |
{ |
|
|
1772 |
return "SET NAMES '".$charset."'"; |
|
|
1773 |
} |
|
|
1774 |
|
|
|
1775 |
/** |
|
|
1776 |
* Gets the SQL specific for the platform to get the current date. |
|
|
1777 |
* |
|
|
1778 |
* @return string |
|
|
1779 |
*/ |
|
|
1780 |
public function getCurrentDateSQL() |
|
|
1781 |
{ |
|
|
1782 |
return 'CURRENT_DATE'; |
|
|
1783 |
} |
|
|
1784 |
|
|
|
1785 |
/** |
|
|
1786 |
* Gets the SQL specific for the platform to get the current time. |
|
|
1787 |
* |
|
|
1788 |
* @return string |
|
|
1789 |
*/ |
|
|
1790 |
public function getCurrentTimeSQL() |
|
|
1791 |
{ |
|
|
1792 |
return 'CURRENT_TIME'; |
|
|
1793 |
} |
|
|
1794 |
|
|
|
1795 |
/** |
|
|
1796 |
* Gets the SQL specific for the platform to get the current timestamp |
|
|
1797 |
* |
|
|
1798 |
* @return string |
|
|
1799 |
*/ |
|
|
1800 |
public function getCurrentTimestampSQL() |
|
|
1801 |
{ |
|
|
1802 |
return 'CURRENT_TIMESTAMP'; |
|
|
1803 |
} |
|
|
1804 |
|
|
|
1805 |
/** |
|
|
1806 |
* Get sql for transaction isolation level Connection constant |
|
|
1807 |
* |
|
|
1808 |
* @param integer $level |
|
|
1809 |
*/ |
|
|
1810 |
protected function _getTransactionIsolationLevelSQL($level) |
|
|
1811 |
{ |
|
|
1812 |
switch ($level) { |
|
|
1813 |
case Connection::TRANSACTION_READ_UNCOMMITTED: |
|
|
1814 |
return 'READ UNCOMMITTED'; |
|
|
1815 |
case Connection::TRANSACTION_READ_COMMITTED: |
|
|
1816 |
return 'READ COMMITTED'; |
|
|
1817 |
case Connection::TRANSACTION_REPEATABLE_READ: |
|
|
1818 |
return 'REPEATABLE READ'; |
|
|
1819 |
case Connection::TRANSACTION_SERIALIZABLE: |
|
|
1820 |
return 'SERIALIZABLE'; |
|
|
1821 |
default: |
|
|
1822 |
throw new \InvalidArgumentException('Invalid isolation level:' . $level); |
|
|
1823 |
} |
|
|
1824 |
} |
|
|
1825 |
|
|
|
1826 |
public function getListDatabasesSQL() |
|
|
1827 |
{ |
|
|
1828 |
throw DBALException::notSupported(__METHOD__); |
|
|
1829 |
} |
|
|
1830 |
|
|
|
1831 |
public function getListSequencesSQL($database) |
|
|
1832 |
{ |
|
|
1833 |
throw DBALException::notSupported(__METHOD__); |
|
|
1834 |
} |
|
|
1835 |
|
|
|
1836 |
public function getListTableConstraintsSQL($table) |
|
|
1837 |
{ |
|
|
1838 |
throw DBALException::notSupported(__METHOD__); |
|
|
1839 |
} |
|
|
1840 |
|
|
|
1841 |
public function getListTableColumnsSQL($table, $database = null) |
|
|
1842 |
{ |
|
|
1843 |
throw DBALException::notSupported(__METHOD__); |
|
|
1844 |
} |
|
|
1845 |
|
|
|
1846 |
public function getListTablesSQL() |
|
|
1847 |
{ |
|
|
1848 |
throw DBALException::notSupported(__METHOD__); |
|
|
1849 |
} |
|
|
1850 |
|
|
|
1851 |
public function getListUsersSQL() |
|
|
1852 |
{ |
|
|
1853 |
throw DBALException::notSupported(__METHOD__); |
|
|
1854 |
} |
|
|
1855 |
|
|
|
1856 |
/** |
|
|
1857 |
* Get the SQL to list all views of a database or user. |
|
|
1858 |
* |
|
|
1859 |
* @param string $database |
|
|
1860 |
* @return string |
|
|
1861 |
*/ |
|
|
1862 |
public function getListViewsSQL($database) |
|
|
1863 |
{ |
|
|
1864 |
throw DBALException::notSupported(__METHOD__); |
|
|
1865 |
} |
|
|
1866 |
|
|
|
1867 |
/** |
|
|
1868 |
* Get the list of indexes for the current database. |
|
|
1869 |
* |
|
|
1870 |
* The current database parameter is optional but will always be passed |
|
|
1871 |
* when using the SchemaManager API and is the database the given table is in. |
|
|
1872 |
* |
|
|
1873 |
* Attention: Some platforms only support currentDatabase when they |
|
|
1874 |
* are connected with that database. Cross-database information schema |
|
|
1875 |
* requests may be impossible. |
|
|
1876 |
* |
|
|
1877 |
* @param string $table |
|
|
1878 |
* @param string $currentDatabase |
|
|
1879 |
*/ |
|
|
1880 |
public function getListTableIndexesSQL($table, $currentDatabase = null) |
|
|
1881 |
{ |
|
|
1882 |
throw DBALException::notSupported(__METHOD__); |
|
|
1883 |
} |
|
|
1884 |
|
|
|
1885 |
public function getListTableForeignKeysSQL($table) |
|
|
1886 |
{ |
|
|
1887 |
throw DBALException::notSupported(__METHOD__); |
|
|
1888 |
} |
|
|
1889 |
|
|
|
1890 |
public function getCreateViewSQL($name, $sql) |
|
|
1891 |
{ |
|
|
1892 |
throw DBALException::notSupported(__METHOD__); |
|
|
1893 |
} |
|
|
1894 |
|
|
|
1895 |
public function getDropViewSQL($name) |
|
|
1896 |
{ |
|
|
1897 |
throw DBALException::notSupported(__METHOD__); |
|
|
1898 |
} |
|
|
1899 |
|
|
|
1900 |
public function getDropSequenceSQL($sequence) |
|
|
1901 |
{ |
|
|
1902 |
throw DBALException::notSupported(__METHOD__); |
|
|
1903 |
} |
|
|
1904 |
|
|
|
1905 |
public function getSequenceNextValSQL($sequenceName) |
|
|
1906 |
{ |
|
|
1907 |
throw DBALException::notSupported(__METHOD__); |
|
|
1908 |
} |
|
|
1909 |
|
|
|
1910 |
public function getCreateDatabaseSQL($database) |
|
|
1911 |
{ |
|
|
1912 |
throw DBALException::notSupported(__METHOD__); |
|
|
1913 |
} |
|
|
1914 |
|
|
|
1915 |
/** |
|
|
1916 |
* Get sql to set the transaction isolation level |
|
|
1917 |
* |
|
|
1918 |
* @param integer $level |
|
|
1919 |
*/ |
|
|
1920 |
public function getSetTransactionIsolationSQL($level) |
|
|
1921 |
{ |
|
|
1922 |
throw DBALException::notSupported(__METHOD__); |
|
|
1923 |
} |
|
|
1924 |
|
|
|
1925 |
/** |
|
|
1926 |
* Obtain DBMS specific SQL to be used to create datetime fields in |
|
|
1927 |
* statements like CREATE TABLE |
|
|
1928 |
* |
|
|
1929 |
* @param array $fieldDeclaration |
|
|
1930 |
* @return string |
|
|
1931 |
*/ |
|
|
1932 |
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) |
|
|
1933 |
{ |
|
|
1934 |
throw DBALException::notSupported(__METHOD__); |
|
|
1935 |
} |
|
|
1936 |
|
|
|
1937 |
/** |
|
|
1938 |
* Obtain DBMS specific SQL to be used to create datetime with timezone offset fields. |
|
|
1939 |
* |
|
|
1940 |
* @param array $fieldDeclaration |
|
|
1941 |
*/ |
|
|
1942 |
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) |
|
|
1943 |
{ |
|
|
1944 |
return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration); |
|
|
1945 |
} |
|
|
1946 |
|
|
|
1947 |
|
|
|
1948 |
/** |
|
|
1949 |
* Obtain DBMS specific SQL to be used to create date fields in statements |
|
|
1950 |
* like CREATE TABLE. |
|
|
1951 |
* |
|
|
1952 |
* @param array $fieldDeclaration |
|
|
1953 |
* @return string |
|
|
1954 |
*/ |
|
|
1955 |
public function getDateTypeDeclarationSQL(array $fieldDeclaration) |
|
|
1956 |
{ |
|
|
1957 |
throw DBALException::notSupported(__METHOD__); |
|
|
1958 |
} |
|
|
1959 |
|
|
|
1960 |
/** |
|
|
1961 |
* Obtain DBMS specific SQL to be used to create time fields in statements |
|
|
1962 |
* like CREATE TABLE. |
|
|
1963 |
* |
|
|
1964 |
* @param array $fieldDeclaration |
|
|
1965 |
* @return string |
|
|
1966 |
*/ |
|
|
1967 |
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) |
|
|
1968 |
{ |
|
|
1969 |
throw DBALException::notSupported(__METHOD__); |
|
|
1970 |
} |
|
|
1971 |
|
|
|
1972 |
public function getFloatDeclarationSQL(array $fieldDeclaration) |
|
|
1973 |
{ |
|
|
1974 |
return 'DOUBLE PRECISION'; |
|
|
1975 |
} |
|
|
1976 |
|
|
|
1977 |
/** |
|
|
1978 |
* Gets the default transaction isolation level of the platform. |
|
|
1979 |
* |
|
|
1980 |
* @return integer The default isolation level. |
|
|
1981 |
* @see Doctrine\DBAL\Connection\TRANSACTION_* constants. |
|
|
1982 |
*/ |
|
|
1983 |
public function getDefaultTransactionIsolationLevel() |
|
|
1984 |
{ |
|
|
1985 |
return Connection::TRANSACTION_READ_COMMITTED; |
|
|
1986 |
} |
|
|
1987 |
|
|
|
1988 |
/* supports*() metods */ |
|
|
1989 |
|
|
|
1990 |
/** |
|
|
1991 |
* Whether the platform supports sequences. |
|
|
1992 |
* |
|
|
1993 |
* @return boolean |
|
|
1994 |
*/ |
|
|
1995 |
public function supportsSequences() |
|
|
1996 |
{ |
|
|
1997 |
return false; |
|
|
1998 |
} |
|
|
1999 |
|
|
|
2000 |
/** |
|
|
2001 |
* Whether the platform supports identity columns. |
|
|
2002 |
* Identity columns are columns that recieve an auto-generated value from the |
|
|
2003 |
* database on insert of a row. |
|
|
2004 |
* |
|
|
2005 |
* @return boolean |
|
|
2006 |
*/ |
|
|
2007 |
public function supportsIdentityColumns() |
|
|
2008 |
{ |
|
|
2009 |
return false; |
|
|
2010 |
} |
|
|
2011 |
|
|
|
2012 |
/** |
|
|
2013 |
* Whether the platform supports indexes. |
|
|
2014 |
* |
|
|
2015 |
* @return boolean |
|
|
2016 |
*/ |
|
|
2017 |
public function supportsIndexes() |
|
|
2018 |
{ |
|
|
2019 |
return true; |
|
|
2020 |
} |
|
|
2021 |
|
|
|
2022 |
public function supportsAlterTable() |
|
|
2023 |
{ |
|
|
2024 |
return true; |
|
|
2025 |
} |
|
|
2026 |
|
|
|
2027 |
/** |
|
|
2028 |
* Whether the platform supports transactions. |
|
|
2029 |
* |
|
|
2030 |
* @return boolean |
|
|
2031 |
*/ |
|
|
2032 |
public function supportsTransactions() |
|
|
2033 |
{ |
|
|
2034 |
return true; |
|
|
2035 |
} |
|
|
2036 |
|
|
|
2037 |
/** |
|
|
2038 |
* Whether the platform supports savepoints. |
|
|
2039 |
* |
|
|
2040 |
* @return boolean |
|
|
2041 |
*/ |
|
|
2042 |
public function supportsSavepoints() |
|
|
2043 |
{ |
|
|
2044 |
return true; |
|
|
2045 |
} |
|
|
2046 |
|
|
|
2047 |
/** |
|
|
2048 |
* Whether the platform supports releasing savepoints. |
|
|
2049 |
* |
|
|
2050 |
* @return boolean |
|
|
2051 |
*/ |
|
|
2052 |
public function supportsReleaseSavepoints() |
|
|
2053 |
{ |
|
|
2054 |
return $this->supportsSavepoints(); |
|
|
2055 |
} |
|
|
2056 |
|
|
|
2057 |
/** |
|
|
2058 |
* Whether the platform supports primary key constraints. |
|
|
2059 |
* |
|
|
2060 |
* @return boolean |
|
|
2061 |
*/ |
|
|
2062 |
public function supportsPrimaryConstraints() |
|
|
2063 |
{ |
|
|
2064 |
return true; |
|
|
2065 |
} |
|
|
2066 |
|
|
|
2067 |
/** |
|
|
2068 |
* Does the platform supports foreign key constraints? |
|
|
2069 |
* |
|
|
2070 |
* @return boolean |
|
|
2071 |
*/ |
|
|
2072 |
public function supportsForeignKeyConstraints() |
|
|
2073 |
{ |
|
|
2074 |
return true; |
|
|
2075 |
} |
|
|
2076 |
|
|
|
2077 |
/** |
|
|
2078 |
* Does this platform supports onUpdate in foreign key constraints? |
|
|
2079 |
* |
|
|
2080 |
* @return bool |
|
|
2081 |
*/ |
|
|
2082 |
public function supportsForeignKeyOnUpdate() |
|
|
2083 |
{ |
|
|
2084 |
return ($this->supportsForeignKeyConstraints() && true); |
|
|
2085 |
} |
|
|
2086 |
|
|
|
2087 |
/** |
|
|
2088 |
* Whether the platform supports database schemas. |
|
|
2089 |
* |
|
|
2090 |
* @return boolean |
|
|
2091 |
*/ |
|
|
2092 |
public function supportsSchemas() |
|
|
2093 |
{ |
|
|
2094 |
return false; |
|
|
2095 |
} |
|
|
2096 |
|
|
|
2097 |
/** |
|
|
2098 |
* Some databases don't allow to create and drop databases at all or only with certain tools. |
|
|
2099 |
* |
|
|
2100 |
* @return bool |
|
|
2101 |
*/ |
|
|
2102 |
public function supportsCreateDropDatabase() |
|
|
2103 |
{ |
|
|
2104 |
return true; |
|
|
2105 |
} |
|
|
2106 |
|
|
|
2107 |
/** |
|
|
2108 |
* Whether the platform supports getting the affected rows of a recent |
|
|
2109 |
* update/delete type query. |
|
|
2110 |
* |
|
|
2111 |
* @return boolean |
|
|
2112 |
*/ |
|
|
2113 |
public function supportsGettingAffectedRows() |
|
|
2114 |
{ |
|
|
2115 |
return true; |
|
|
2116 |
} |
|
|
2117 |
|
|
|
2118 |
/** |
|
|
2119 |
* Does this plaform support to add inline column comments as postfix. |
|
|
2120 |
* |
|
|
2121 |
* @return bool |
|
|
2122 |
*/ |
|
|
2123 |
public function supportsInlineColumnComments() |
|
|
2124 |
{ |
|
|
2125 |
return false; |
|
|
2126 |
} |
|
|
2127 |
|
|
|
2128 |
/** |
|
|
2129 |
* Does this platform support the propriortary synatx "COMMENT ON asset" |
|
|
2130 |
* |
|
|
2131 |
* @return bool |
|
|
2132 |
*/ |
|
|
2133 |
public function supportsCommentOnStatement() |
|
|
2134 |
{ |
|
|
2135 |
return false; |
|
|
2136 |
} |
|
|
2137 |
|
|
|
2138 |
public function getIdentityColumnNullInsertSQL() |
|
|
2139 |
{ |
|
|
2140 |
return ""; |
|
|
2141 |
} |
|
|
2142 |
|
|
|
2143 |
/** |
|
|
2144 |
* Gets the format string, as accepted by the date() function, that describes |
|
|
2145 |
* the format of a stored datetime value of this platform. |
|
|
2146 |
* |
|
|
2147 |
* @return string The format string. |
|
|
2148 |
*/ |
|
|
2149 |
public function getDateTimeFormatString() |
|
|
2150 |
{ |
|
|
2151 |
return 'Y-m-d H:i:s'; |
|
|
2152 |
} |
|
|
2153 |
|
|
|
2154 |
/** |
|
|
2155 |
* Gets the format string, as accepted by the date() function, that describes |
|
|
2156 |
* the format of a stored datetime with timezone value of this platform. |
|
|
2157 |
* |
|
|
2158 |
* @return string The format string. |
|
|
2159 |
*/ |
|
|
2160 |
public function getDateTimeTzFormatString() |
|
|
2161 |
{ |
|
|
2162 |
return 'Y-m-d H:i:s'; |
|
|
2163 |
} |
|
|
2164 |
|
|
|
2165 |
/** |
|
|
2166 |
* Gets the format string, as accepted by the date() function, that describes |
|
|
2167 |
* the format of a stored date value of this platform. |
|
|
2168 |
* |
|
|
2169 |
* @return string The format string. |
|
|
2170 |
*/ |
|
|
2171 |
public function getDateFormatString() |
|
|
2172 |
{ |
|
|
2173 |
return 'Y-m-d'; |
|
|
2174 |
} |
|
|
2175 |
|
|
|
2176 |
/** |
|
|
2177 |
* Gets the format string, as accepted by the date() function, that describes |
|
|
2178 |
* the format of a stored time value of this platform. |
|
|
2179 |
* |
|
|
2180 |
* @return string The format string. |
|
|
2181 |
*/ |
|
|
2182 |
public function getTimeFormatString() |
|
|
2183 |
{ |
|
|
2184 |
return 'H:i:s'; |
|
|
2185 |
} |
|
|
2186 |
|
|
|
2187 |
/** |
|
|
2188 |
* Modify limit query |
|
|
2189 |
* |
|
|
2190 |
* @param string $query |
|
|
2191 |
* @param int $limit |
|
|
2192 |
* @param int $offset |
|
|
2193 |
* @return string |
|
|
2194 |
*/ |
|
|
2195 |
final public function modifyLimitQuery($query, $limit, $offset = null) |
|
|
2196 |
{ |
|
|
2197 |
if ( $limit !== null) { |
|
|
2198 |
$limit = (int)$limit; |
|
|
2199 |
} |
|
|
2200 |
|
|
|
2201 |
if ( $offset !== null) { |
|
|
2202 |
$offset = (int)$offset; |
|
|
2203 |
} |
|
|
2204 |
|
|
|
2205 |
return $this->doModifyLimitQuery($query, $limit, $offset); |
|
|
2206 |
} |
|
|
2207 |
|
|
|
2208 |
/** |
|
|
2209 |
* @param string $query |
|
|
2210 |
* @param int $limit |
|
|
2211 |
* @param int $offset |
|
|
2212 |
* @return string |
|
|
2213 |
*/ |
|
|
2214 |
protected function doModifyLimitQuery($query, $limit, $offset) |
|
|
2215 |
{ |
|
|
2216 |
if ( $limit !== null) { |
|
|
2217 |
$query .= ' LIMIT ' . $limit; |
|
|
2218 |
} |
|
|
2219 |
|
|
|
2220 |
if ( $offset !== null) { |
|
|
2221 |
$query .= ' OFFSET ' . $offset; |
|
|
2222 |
} |
|
|
2223 |
|
|
|
2224 |
return $query; |
|
|
2225 |
} |
|
|
2226 |
|
|
|
2227 |
/** |
|
|
2228 |
* Gets the character casing of a column in an SQL result set of this platform. |
|
|
2229 |
* |
|
|
2230 |
* @param string $column The column name for which to get the correct character casing. |
|
|
2231 |
* @return string The column name in the character casing used in SQL result sets. |
|
|
2232 |
*/ |
|
|
2233 |
public function getSQLResultCasing($column) |
|
|
2234 |
{ |
|
|
2235 |
return $column; |
|
|
2236 |
} |
|
|
2237 |
|
|
|
2238 |
/** |
|
|
2239 |
* Makes any fixes to a name of a schema element (table, sequence, ...) that are required |
|
|
2240 |
* by restrictions of the platform, like a maximum length. |
|
|
2241 |
* |
|
|
2242 |
* @param string $schemaName |
|
|
2243 |
* @return string |
|
|
2244 |
*/ |
|
|
2245 |
public function fixSchemaElementName($schemaElementName) |
|
|
2246 |
{ |
|
|
2247 |
return $schemaElementName; |
|
|
2248 |
} |
|
|
2249 |
|
|
|
2250 |
/** |
|
|
2251 |
* Maximum length of any given databse identifier, like tables or column names. |
|
|
2252 |
* |
|
|
2253 |
* @return int |
|
|
2254 |
*/ |
|
|
2255 |
public function getMaxIdentifierLength() |
|
|
2256 |
{ |
|
|
2257 |
return 63; |
|
|
2258 |
} |
|
|
2259 |
|
|
|
2260 |
/** |
|
|
2261 |
* Get the insert sql for an empty insert statement |
|
|
2262 |
* |
|
|
2263 |
* @param string $tableName |
|
|
2264 |
* @param string $identifierColumnName |
|
|
2265 |
* @return string $sql |
|
|
2266 |
*/ |
|
|
2267 |
public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) |
|
|
2268 |
{ |
|
|
2269 |
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)'; |
|
|
2270 |
} |
|
|
2271 |
|
|
|
2272 |
/** |
|
|
2273 |
* Generate a Truncate Table SQL statement for a given table. |
|
|
2274 |
* |
|
|
2275 |
* Cascade is not supported on many platforms but would optionally cascade the truncate by |
|
|
2276 |
* following the foreign keys. |
|
|
2277 |
* |
|
|
2278 |
* @param string $tableName |
|
|
2279 |
* @param bool $cascade |
|
|
2280 |
* @return string |
|
|
2281 |
*/ |
|
|
2282 |
public function getTruncateTableSQL($tableName, $cascade = false) |
|
|
2283 |
{ |
|
|
2284 |
return 'TRUNCATE '.$tableName; |
|
|
2285 |
} |
|
|
2286 |
|
|
|
2287 |
/** |
|
|
2288 |
* This is for test reasons, many vendors have special requirements for dummy statements. |
|
|
2289 |
* |
|
|
2290 |
* @return string |
|
|
2291 |
*/ |
|
|
2292 |
public function getDummySelectSQL() |
|
|
2293 |
{ |
|
|
2294 |
return 'SELECT 1'; |
|
|
2295 |
} |
|
|
2296 |
|
|
|
2297 |
/** |
|
|
2298 |
* Generate SQL to create a new savepoint |
|
|
2299 |
* |
|
|
2300 |
* @param string $savepoint |
|
|
2301 |
* @return string |
|
|
2302 |
*/ |
|
|
2303 |
public function createSavePoint($savepoint) |
|
|
2304 |
{ |
|
|
2305 |
return 'SAVEPOINT ' . $savepoint; |
|
|
2306 |
} |
|
|
2307 |
|
|
|
2308 |
/** |
|
|
2309 |
* Generate SQL to release a savepoint |
|
|
2310 |
* |
|
|
2311 |
* @param string $savepoint |
|
|
2312 |
* @return string |
|
|
2313 |
*/ |
|
|
2314 |
public function releaseSavePoint($savepoint) |
|
|
2315 |
{ |
|
|
2316 |
return 'RELEASE SAVEPOINT ' . $savepoint; |
|
|
2317 |
} |
|
|
2318 |
|
|
|
2319 |
/** |
|
|
2320 |
* Generate SQL to rollback a savepoint |
|
|
2321 |
* |
|
|
2322 |
* @param string $savepoint |
|
|
2323 |
* @return string |
|
|
2324 |
*/ |
|
|
2325 |
public function rollbackSavePoint($savepoint) |
|
|
2326 |
{ |
|
|
2327 |
return 'ROLLBACK TO SAVEPOINT ' . $savepoint; |
|
|
2328 |
} |
|
|
2329 |
|
|
|
2330 |
/** |
|
|
2331 |
* Return the keyword list instance of this platform. |
|
|
2332 |
* |
|
|
2333 |
* Throws exception if no keyword list is specified. |
|
|
2334 |
* |
|
|
2335 |
* @throws DBALException |
|
|
2336 |
* @return KeywordList |
|
|
2337 |
*/ |
|
|
2338 |
final public function getReservedKeywordsList() |
|
|
2339 |
{ |
|
|
2340 |
$class = $this->getReservedKeywordsClass(); |
|
|
2341 |
$keywords = new $class; |
|
|
2342 |
if (!$keywords instanceof \Doctrine\DBAL\Platforms\Keywords\KeywordList) { |
|
|
2343 |
throw DBALException::notSupported(__METHOD__); |
|
|
2344 |
} |
|
|
2345 |
return $keywords; |
|
|
2346 |
} |
|
|
2347 |
|
|
|
2348 |
/** |
|
|
2349 |
* The class name of the reserved keywords list. |
|
|
2350 |
* |
|
|
2351 |
* @return string |
|
|
2352 |
*/ |
|
|
2353 |
protected function getReservedKeywordsClass() |
|
|
2354 |
{ |
|
|
2355 |
throw DBALException::notSupported(__METHOD__); |
|
|
2356 |
} |
|
|
2357 |
} |