-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathAbstractPlatform.php
4727 lines (4168 loc) · 137 KB
/
AbstractPlatform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Doctrine\DBAL\Platforms;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs;
use Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs;
use Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs;
use Doctrine\DBAL\Event\SchemaCreateTableEventArgs;
use Doctrine\DBAL\Event\SchemaDropTableEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\InvalidLockMode;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Constraint;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder;
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
use Doctrine\DBAL\SQL\Parser;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;
use UnexpectedValueException;
use function addcslashes;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
use function assert;
use function count;
use function explode;
use function func_get_arg;
use function func_get_args;
use function func_num_args;
use function implode;
use function in_array;
use function is_array;
use function is_bool;
use function is_int;
use function is_string;
use function preg_quote;
use function preg_replace;
use function sprintf;
use function str_replace;
use function strlen;
use function strpos;
use function strtolower;
use function strtoupper;
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
* point of abstraction of platform-specific behaviors, features and SQL dialects.
* They are a passive source of information.
*
* @todo Remove any unnecessary methods.
*/
abstract class AbstractPlatform
{
public const CREATE_INDEXES = 1;
public const CREATE_FOREIGNKEYS = 2;
/** @var string[]|null */
protected $doctrineTypeMapping;
/**
* Contains a list of all columns that should generate parseable column comments for type-detection
* in reverse engineering scenarios.
*
* @deprecated This property is deprecated and will be removed in Doctrine DBAL 4.0.
*
* @var string[]|null
*/
protected $doctrineTypeComments;
/**
* @deprecated
*
* @var EventManager|null
*/
protected $_eventManager;
/**
* Holds the KeywordList instance for the current platform.
*
* @var KeywordList|null
*/
protected $_keywords;
private bool $disableTypeComments = false;
/** @internal */
final public function setDisableTypeComments(bool $value): void
{
$this->disableTypeComments = $value;
}
/**
* Sets the EventManager used by the Platform.
*
* @deprecated
*
* @return void
*/
public function setEventManager(EventManager $eventManager)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'%s is deprecated.',
__METHOD__,
);
$this->_eventManager = $eventManager;
}
/**
* Gets the EventManager used by the Platform.
*
* @deprecated
*
* @return EventManager|null
*/
public function getEventManager()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/5784',
'%s is deprecated.',
__METHOD__,
);
return $this->_eventManager;
}
/**
* Returns the SQL snippet that declares a boolean column.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getBooleanTypeDeclarationSQL(array $column);
/**
* Returns the SQL snippet that declares a 4 byte integer column.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getIntegerTypeDeclarationSQL(array $column);
/**
* Returns the SQL snippet that declares an 8 byte integer column.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getBigIntTypeDeclarationSQL(array $column);
/**
* Returns the SQL snippet that declares a 2 byte integer column.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getSmallIntTypeDeclarationSQL(array $column);
/**
* Returns the SQL snippet that declares common properties of an integer column.
*
* @param mixed[] $column
*
* @return string
*/
abstract protected function _getCommonIntegerTypeDeclarationSQL(array $column);
/**
* Lazy load Doctrine Type Mappings.
*
* @return void
*/
abstract protected function initializeDoctrineTypeMappings();
/**
* Initializes Doctrine Type Mappings with the platform defaults
* and with all additional type mappings.
*/
private function initializeAllDoctrineTypeMappings(): void
{
$this->initializeDoctrineTypeMappings();
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
}
/**
* Returns the SQL snippet used to declare a column that can
* store characters in the ASCII character set
*
* @param mixed[] $column
*/
public function getAsciiStringTypeDeclarationSQL(array $column): string
{
return $this->getStringTypeDeclarationSQL($column);
}
/**
* Returns the SQL snippet used to declare a VARCHAR column type.
*
* @deprecated Use {@link getStringTypeDeclarationSQL()} instead.
*
* @param mixed[] $column
*
* @return string
*/
public function getVarcharTypeDeclarationSQL(array $column)
{
if (isset($column['length'])) {
$lengthOmitted = false;
} else {
$column['length'] = $this->getVarcharDefaultLength();
$lengthOmitted = true;
}
$fixed = $column['fixed'] ?? false;
$maxLength = $fixed
? $this->getCharMaxLength()
: $this->getVarcharMaxLength();
if ($column['length'] > $maxLength) {
return $this->getClobTypeDeclarationSQL($column);
}
return $this->getVarcharTypeDeclarationSQLSnippet($column['length'], $fixed, $lengthOmitted);
}
/**
* Returns the SQL snippet used to declare a string column type.
*
* @param mixed[] $column
*
* @return string
*/
public function getStringTypeDeclarationSQL(array $column)
{
return $this->getVarcharTypeDeclarationSQL($column);
}
/**
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type.
*
* @param mixed[] $column The column definition.
*
* @return string
*/
public function getBinaryTypeDeclarationSQL(array $column)
{
if (isset($column['length'])) {
$lengthOmitted = false;
} else {
$column['length'] = $this->getBinaryDefaultLength();
$lengthOmitted = true;
}
$fixed = $column['fixed'] ?? false;
$maxLength = $this->getBinaryMaxLength();
if ($column['length'] > $maxLength) {
if ($maxLength > 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3187',
'Binary column length %d is greater than supported by the platform (%d).'
. ' Reduce the column length or use a BLOB column instead.',
$column['length'],
$maxLength,
);
}
return $this->getBlobTypeDeclarationSQL($column);
}
return $this->getBinaryTypeDeclarationSQLSnippet($column['length'], $fixed, $lengthOmitted);
}
/**
* Returns the SQL snippet to declare a GUID/UUID column.
*
* By default this maps directly to a CHAR(36) and only maps to more
* special datatypes when the underlying databases support this datatype.
*
* @param mixed[] $column
*
* @return string
*/
public function getGuidTypeDeclarationSQL(array $column)
{
$column['length'] = 36;
$column['fixed'] = true;
return $this->getStringTypeDeclarationSQL($column);
}
/**
* Returns the SQL snippet to declare a JSON column.
*
* By default this maps directly to a CLOB and only maps to more
* special datatypes when the underlying databases support this datatype.
*
* @param mixed[] $column
*
* @return string
*/
public function getJsonTypeDeclarationSQL(array $column)
{
return $this->getClobTypeDeclarationSQL($column);
}
/**
* @param int|false $length
* @param bool $fixed
*
* @return string
*
* @throws Exception If not supported on this platform.
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed/*, $lengthOmitted = false*/)
{
throw Exception::notSupported('VARCHARs not supported by Platform.');
}
/**
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type.
*
* @param int|false $length The length of the column.
* @param bool $fixed Whether the column length is fixed.
*
* @return string
*
* @throws Exception If not supported on this platform.
*/
protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed/*, $lengthOmitted = false*/)
{
throw Exception::notSupported('BINARY/VARBINARY column types are not supported by this platform.');
}
/**
* Returns the SQL snippet used to declare a CLOB column type.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getClobTypeDeclarationSQL(array $column);
/**
* Returns the SQL Snippet used to declare a BLOB column type.
*
* @param mixed[] $column
*
* @return string
*/
abstract public function getBlobTypeDeclarationSQL(array $column);
/**
* Gets the name of the platform.
*
* @deprecated Identify platforms by their class.
*
* @return string
*/
abstract public function getName();
/**
* Registers a doctrine type to be used in conjunction with a column type of this platform.
*
* @param string $dbType
* @param string $doctrineType
*
* @return void
*
* @throws Exception If the type is not found.
*/
public function registerDoctrineTypeMapping($dbType, $doctrineType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
if (! Types\Type::hasType($doctrineType)) {
throw Exception::typeNotFound($doctrineType);
}
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $doctrineType;
$doctrineType = Type::getType($doctrineType);
if (! $doctrineType->requiresSQLCommentHint($this)) {
return;
}
$this->markDoctrineTypeCommented($doctrineType);
}
/**
* Gets the Doctrine type that is mapped for the given database column type.
*
* @param string $dbType
*
* @return string
*
* @throws Exception
*/
public function getDoctrineTypeMapping($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
if (! isset($this->doctrineTypeMapping[$dbType])) {
throw new Exception(
'Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.',
);
}
return $this->doctrineTypeMapping[$dbType];
}
/**
* Checks if a database type is currently supported by this platform.
*
* @param string $dbType
*
* @return bool
*/
public function hasDoctrineTypeMappingFor($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
return isset($this->doctrineTypeMapping[$dbType]);
}
/**
* Initializes the Doctrine Type comments instance variable for in_array() checks.
*
* @deprecated This API will be removed in Doctrine DBAL 4.0.
*
* @return void
*/
protected function initializeCommentedDoctrineTypes()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5058',
'%s is deprecated and will be removed in Doctrine DBAL 4.0.',
__METHOD__,
);
$this->doctrineTypeComments = [];
foreach (Type::getTypesMap() as $typeName => $className) {
$type = Type::getType($typeName);
if (! $type->requiresSQLCommentHint($this)) {
continue;
}
$this->doctrineTypeComments[] = $typeName;
}
}
/**
* Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type?
*
* @deprecated Use {@link Type::requiresSQLCommentHint()} instead.
*
* @return bool
*/
public function isCommentedDoctrineType(Type $doctrineType)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5058',
'%s is deprecated and will be removed in Doctrine DBAL 4.0. Use Type::requiresSQLCommentHint() instead.',
__METHOD__,
);
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
return $doctrineType->requiresSQLCommentHint($this);
}
/**
* Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements.
*
* @param string|Type $doctrineType
*
* @return void
*/
public function markDoctrineTypeCommented($doctrineType)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5058',
'%s is deprecated and will be removed in Doctrine DBAL 4.0. Use Type::requiresSQLCommentHint() instead.',
__METHOD__,
);
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
assert(is_array($this->doctrineTypeComments));
$this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType;
}
/**
* Gets the comment to append to a column comment that helps parsing this type in reverse engineering.
*
* @deprecated This method will be removed without replacement.
*
* @return string
*/
public function getDoctrineTypeComment(Type $doctrineType)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5107',
'%s is deprecated and will be removed in Doctrine DBAL 4.0.',
__METHOD__,
);
return '(DC2Type:' . $doctrineType->getName() . ')';
}
/**
* Gets the comment of a passed column modified by potential doctrine type comment hints.
*
* @deprecated This method will be removed without replacement.
*
* @return string|null
*/
protected function getColumnComment(Column $column)
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5107',
'%s is deprecated and will be removed in Doctrine DBAL 4.0.',
__METHOD__,
);
$comment = $column->getComment();
if (! $this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) {
$comment .= $this->getDoctrineTypeComment($column->getType());
}
return $comment;
}
/**
* Gets the character used for identifier quoting.
*
* @deprecated Use {@see quoteIdentifier()} to quote identifiers instead.
*
* @return string
*/
public function getIdentifierQuoteCharacter()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5388',
'AbstractPlatform::getIdentifierQuoteCharacter() is deprecated. Use quoteIdentifier() instead.',
);
return '"';
}
/**
* Gets the string portion that starts an SQL comment.
*
* @deprecated
*
* @return string
*/
public function getSqlCommentStartString()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getSqlCommentStartString() is deprecated.',
);
return '--';
}
/**
* Gets the string portion that ends an SQL comment.
*
* @deprecated
*
* @return string
*/
public function getSqlCommentEndString()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getSqlCommentEndString() is deprecated.',
);
return "\n";
}
/**
* Gets the maximum length of a char column.
*
* @deprecated
*/
public function getCharMaxLength(): int
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3263',
'AbstractPlatform::getCharMaxLength() is deprecated.',
);
return $this->getVarcharMaxLength();
}
/**
* Gets the maximum length of a varchar column.
*
* @deprecated
*
* @return int
*/
public function getVarcharMaxLength()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3263',
'AbstractPlatform::getVarcharMaxLength() is deprecated.',
);
return 4000;
}
/**
* Gets the default length of a varchar column.
*
* @deprecated
*
* @return int
*/
public function getVarcharDefaultLength()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3263',
'Relying on the default varchar column length is deprecated, specify the length explicitly.',
);
return 255;
}
/**
* Gets the maximum length of a binary column.
*
* @deprecated
*
* @return int
*/
public function getBinaryMaxLength()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3263',
'AbstractPlatform::getBinaryMaxLength() is deprecated.',
);
return 4000;
}
/**
* Gets the default length of a binary column.
*
* @deprecated
*
* @return int
*/
public function getBinaryDefaultLength()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/3263',
'Relying on the default binary column length is deprecated, specify the length explicitly.',
);
return 255;
}
/**
* Gets all SQL wildcard characters of the platform.
*
* @deprecated Use {@see AbstractPlatform::getLikeWildcardCharacters()} instead.
*
* @return string[]
*/
public function getWildcards()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getWildcards() is deprecated.'
. ' Use AbstractPlatform::getLikeWildcardCharacters() instead.',
);
return ['%', '_'];
}
/**
* Returns the regular expression operator.
*
* @return string
*
* @throws Exception If not supported on this platform.
*/
public function getRegexpExpression()
{
throw Exception::notSupported(__METHOD__);
}
/**
* Returns the SQL snippet to get the average value of a column.
*
* @deprecated Use AVG() in SQL instead.
*
* @param string $column The column to use.
*
* @return string Generated SQL including an AVG aggregate function.
*/
public function getAvgExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getAvgExpression() is deprecated. Use AVG() in SQL instead.',
);
return 'AVG(' . $column . ')';
}
/**
* Returns the SQL snippet to get the number of rows (without a NULL value) of a column.
*
* If a '*' is used instead of a column the number of selected rows is returned.
*
* @deprecated Use COUNT() in SQL instead.
*
* @param string|int $column The column to use.
*
* @return string Generated SQL including a COUNT aggregate function.
*/
public function getCountExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getCountExpression() is deprecated. Use COUNT() in SQL instead.',
);
return 'COUNT(' . $column . ')';
}
/**
* Returns the SQL snippet to get the highest value of a column.
*
* @deprecated Use MAX() in SQL instead.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a MAX aggregate function.
*/
public function getMaxExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getMaxExpression() is deprecated. Use MAX() in SQL instead.',
);
return 'MAX(' . $column . ')';
}
/**
* Returns the SQL snippet to get the lowest value of a column.
*
* @deprecated Use MIN() in SQL instead.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a MIN aggregate function.
*/
public function getMinExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getMinExpression() is deprecated. Use MIN() in SQL instead.',
);
return 'MIN(' . $column . ')';
}
/**
* Returns the SQL snippet to get the total sum of a column.
*
* @deprecated Use SUM() in SQL instead.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a SUM aggregate function.
*/
public function getSumExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getSumExpression() is deprecated. Use SUM() in SQL instead.',
);
return 'SUM(' . $column . ')';
}
// scalar functions
/**
* Returns the SQL snippet to get the md5 sum of a column.
*
* Note: Not SQL92, but common functionality.
*
* @deprecated
*
* @param string $column
*
* @return string
*/
public function getMd5Expression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getMd5Expression() is deprecated.',
);
return 'MD5(' . $column . ')';
}
/**
* Returns the SQL snippet to get the length of a text column in characters.
*
* @param string $column
*
* @return string
*/
public function getLengthExpression($column)
{
return 'LENGTH(' . $column . ')';
}
/**
* Returns the SQL snippet to get the squared value of a column.
*
* @deprecated Use SQRT() in SQL instead.
*
* @param string $column The column to use.
*
* @return string Generated SQL including an SQRT aggregate function.
*/
public function getSqrtExpression($column)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getSqrtExpression() is deprecated. Use SQRT() in SQL instead.',
);
return 'SQRT(' . $column . ')';
}
/**
* Returns the SQL snippet to round a numeric column to the number of decimals specified.
*
* @deprecated Use ROUND() in SQL instead.
*
* @param string $column
* @param string|int $decimals
*
* @return string
*/
public function getRoundExpression($column, $decimals = 0)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4724',
'AbstractPlatform::getRoundExpression() is deprecated. Use ROUND() in SQL instead.',
);
return 'ROUND(' . $column . ', ' . $decimals . ')';
}
/**
* Returns the SQL snippet to get the remainder of the division operation $expression1 / $expression2.
*
* @param string $expression1
* @param string $expression2
*
* @return string
*/
public function getModExpression($expression1, $expression2)
{
return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
}
/**
* Returns the SQL snippet to trim a string.
*
* @param string $str The expression to apply the trim to.
* @param int $mode The position of the trim (leading/trailing/both).
* @param string|bool $char The char to trim, has to be quoted already. Defaults to space.
*
* @return string
*/
public function getTrimExpression($str, $mode = TrimMode::UNSPECIFIED, $char = false)
{
$expression = '';
switch ($mode) {
case TrimMode::LEADING:
$expression = 'LEADING ';
break;
case TrimMode::TRAILING:
$expression = 'TRAILING ';
break;
case TrimMode::BOTH:
$expression = 'BOTH ';
break;
}
if ($char !== false) {
$expression .= $char . ' ';
}
if ($mode !== TrimMode::UNSPECIFIED || $char !== false) {
$expression .= 'FROM ';
}
return 'TRIM(' . $expression . $str . ')';
}