-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
AbstractPlatform.php
3602 lines (3193 loc) · 99.9 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\DBALException;
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\Platforms\Keywords\KeywordList;
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\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use InvalidArgumentException;
use const E_USER_DEPRECATED;
use function addcslashes;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
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;
use function trigger_error;
/**
* 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;
/**
* @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND.
*/
public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND;
/**
* @deprecated Use DateIntervalUnit::MINUTE.
*/
public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE;
/**
* @deprecated Use DateIntervalUnit::HOUR.
*/
public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR;
/**
* @deprecated Use DateIntervalUnit::DAY.
*/
public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY;
/**
* @deprecated Use DateIntervalUnit::WEEK.
*/
public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK;
/**
* @deprecated Use DateIntervalUnit::MONTH.
*/
public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH;
/**
* @deprecated Use DateIntervalUnit::QUARTER.
*/
public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER;
/**
* @deprecated Use DateIntervalUnit::QUARTER.
*/
public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR;
/**
* @deprecated Use TrimMode::UNSPECIFIED.
*/
public const TRIM_UNSPECIFIED = TrimMode::UNSPECIFIED;
/**
* @deprecated Use TrimMode::LEADING.
*/
public const TRIM_LEADING = TrimMode::LEADING;
/**
* @deprecated Use TrimMode::TRAILING.
*/
public const TRIM_TRAILING = TrimMode::TRAILING;
/**
* @deprecated Use TrimMode::BOTH.
*/
public const TRIM_BOTH = TrimMode::BOTH;
/** @var string[]|null */
protected $doctrineTypeMapping = null;
/**
* Contains a list of all columns that should generate parseable column comments for type-detection
* in reverse engineering scenarios.
*
* @var string[]|null
*/
protected $doctrineTypeComments = null;
/** @var EventManager */
protected $_eventManager;
/**
* Holds the KeywordList instance for the current platform.
*
* @var KeywordList
*/
protected $_keywords;
public function __construct()
{
}
/**
* Sets the EventManager used by the Platform.
*/
public function setEventManager(EventManager $eventManager)
{
$this->_eventManager = $eventManager;
}
/**
* Gets the EventManager used by the Platform.
*
* @return EventManager
*/
public function getEventManager()
{
return $this->_eventManager;
}
/**
* Returns the SQL snippet that declares a boolean column.
*
* @param mixed[] $columnDef
*
* @return string
*/
abstract public function getBooleanTypeDeclarationSQL(array $columnDef);
/**
* Returns the SQL snippet that declares a 4 byte integer column.
*
* @param mixed[] $columnDef
*
* @return string
*/
abstract public function getIntegerTypeDeclarationSQL(array $columnDef);
/**
* Returns the SQL snippet that declares an 8 byte integer column.
*
* @param mixed[] $columnDef
*
* @return string
*/
abstract public function getBigIntTypeDeclarationSQL(array $columnDef);
/**
* Returns the SQL snippet that declares a 2 byte integer column.
*
* @param mixed[] $columnDef
*
* @return string
*/
abstract public function getSmallIntTypeDeclarationSQL(array $columnDef);
/**
* Returns the SQL snippet that declares common properties of an integer column.
*
* @param mixed[] $columnDef
*
* @return string
*/
abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef);
/**
* 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.
*
* @return void
*/
private function initializeAllDoctrineTypeMappings()
{
$this->initializeDoctrineTypeMappings();
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
}
/**
* Returns the SQL snippet used to declare a VARCHAR column type.
*
* @param mixed[] $field
*
* @return string
*/
public function getVarcharTypeDeclarationSQL(array $field)
{
if (! isset($field['length'])) {
$field['length'] = $this->getVarcharDefaultLength();
}
$fixed = $field['fixed'] ?? false;
$maxLength = $fixed
? $this->getCharMaxLength()
: $this->getVarcharMaxLength();
if ($field['length'] > $maxLength) {
return $this->getClobTypeDeclarationSQL($field);
}
return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed);
}
/**
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type.
*
* @param mixed[] $field The column definition.
*
* @return string
*/
public function getBinaryTypeDeclarationSQL(array $field)
{
if (! isset($field['length'])) {
$field['length'] = $this->getBinaryDefaultLength();
}
$fixed = $field['fixed'] ?? false;
$maxLength = $this->getBinaryMaxLength();
if ($field['length'] > $maxLength) {
if ($maxLength > 0) {
@trigger_error(sprintf(
'Binary field length %d is greater than supported by the platform (%d). Reduce the field length or use a BLOB field instead.',
$field['length'],
$maxLength
), E_USER_DEPRECATED);
}
return $this->getBlobTypeDeclarationSQL($field);
}
return $this->getBinaryTypeDeclarationSQLSnippet($field['length'], $fixed);
}
/**
* Returns the SQL snippet to declare a GUID/UUID field.
*
* 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[] $field
*
* @return string
*/
public function getGuidTypeDeclarationSQL(array $field)
{
$field['length'] = 36;
$field['fixed'] = true;
return $this->getVarcharTypeDeclarationSQL($field);
}
/**
* Returns the SQL snippet to declare a JSON field.
*
* By default this maps directly to a CLOB and only maps to more
* special datatypes when the underlying databases support this datatype.
*
* @param mixed[] $field
*
* @return string
*/
public function getJsonTypeDeclarationSQL(array $field)
{
return $this->getClobTypeDeclarationSQL($field);
}
/**
* @param int $length
* @param bool $fixed
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
throw DBALException::notSupported('VARCHARs not supported by Platform.');
}
/**
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type.
*
* @param int $length The length of the column.
* @param bool $fixed Whether the column length is fixed.
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed)
{
throw DBALException::notSupported('BINARY/VARBINARY column types are not supported by this platform.');
}
/**
* Returns the SQL snippet used to declare a CLOB column type.
*
* @param mixed[] $field
*
* @return string
*/
abstract public function getClobTypeDeclarationSQL(array $field);
/**
* Returns the SQL Snippet used to declare a BLOB column type.
*
* @param mixed[] $field
*
* @return string
*/
abstract public function getBlobTypeDeclarationSQL(array $field);
/**
* Gets the name of the platform.
*
* @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
*
* @throws DBALException If the type is not found.
*/
public function registerDoctrineTypeMapping($dbType, $doctrineType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
if (! Types\Type::hasType($doctrineType)) {
throw DBALException::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 DBALException
*/
public function getDoctrineTypeMapping($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
if (! isset($this->doctrineTypeMapping[$dbType])) {
throw new DBALException('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.
*
* @return void
*/
protected function initializeCommentedDoctrineTypes()
{
$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?
*
* @return bool
*/
public function isCommentedDoctrineType(Type $doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
return in_array($doctrineType->getName(), $this->doctrineTypeComments);
}
/**
* Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements.
*
* @param string|Type $doctrineType
*
* @return void
*/
public function markDoctrineTypeCommented($doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
$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.
*
* @return string
*/
public function getDoctrineTypeComment(Type $doctrineType)
{
return '(DC2Type:' . $doctrineType->getName() . ')';
}
/**
* Gets the comment of a passed column modified by potential doctrine type comment hints.
*
* @return string
*/
protected function getColumnComment(Column $column)
{
$comment = $column->getComment();
if ($this->isCommentedDoctrineType($column->getType())) {
$comment .= $this->getDoctrineTypeComment($column->getType());
}
return $comment;
}
/**
* Gets the character used for identifier quoting.
*
* @return string
*/
public function getIdentifierQuoteCharacter()
{
return '"';
}
/**
* Gets the string portion that starts an SQL comment.
*
* @return string
*/
public function getSqlCommentStartString()
{
return '--';
}
/**
* Gets the string portion that ends an SQL comment.
*
* @return string
*/
public function getSqlCommentEndString()
{
return "\n";
}
/**
* Gets the maximum length of a char field.
*/
public function getCharMaxLength() : int
{
return $this->getVarcharMaxLength();
}
/**
* Gets the maximum length of a varchar field.
*
* @return int
*/
public function getVarcharMaxLength()
{
return 4000;
}
/**
* Gets the default length of a varchar field.
*
* @return int
*/
public function getVarcharDefaultLength()
{
return 255;
}
/**
* Gets the maximum length of a binary field.
*
* @return int
*/
public function getBinaryMaxLength()
{
return 4000;
}
/**
* Gets the default length of a binary field.
*
* @return int
*/
public function getBinaryDefaultLength()
{
return 255;
}
/**
* Gets all SQL wildcard characters of the platform.
*
* @return string[]
*/
public function getWildcards()
{
return ['%', '_'];
}
/**
* Returns the regular expression operator.
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
public function getRegexpExpression()
{
throw DBALException::notSupported(__METHOD__);
}
/**
* Returns the global unique identifier expression.
*
* @deprecated Use application-generated UUIDs instead
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
public function getGuidExpression()
{
throw DBALException::notSupported(__METHOD__);
}
/**
* Returns the SQL snippet to get the average value of a column.
*
* @param string $column The column to use.
*
* @return string Generated SQL including an AVG aggregate function.
*/
public function getAvgExpression($column)
{
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.
*
* @param string|int $column The column to use.
*
* @return string Generated SQL including a COUNT aggregate function.
*/
public function getCountExpression($column)
{
return 'COUNT(' . $column . ')';
}
/**
* Returns the SQL snippet to get the highest value of a column.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a MAX aggregate function.
*/
public function getMaxExpression($column)
{
return 'MAX(' . $column . ')';
}
/**
* Returns the SQL snippet to get the lowest value of a column.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a MIN aggregate function.
*/
public function getMinExpression($column)
{
return 'MIN(' . $column . ')';
}
/**
* Returns the SQL snippet to get the total sum of a column.
*
* @param string $column The column to use.
*
* @return string Generated SQL including a SUM aggregate function.
*/
public function getSumExpression($column)
{
return 'SUM(' . $column . ')';
}
// scalar functions
/**
* Returns the SQL snippet to get the md5 sum of a field.
*
* Note: Not SQL92, but common functionality.
*
* @param string $column
*
* @return string
*/
public function getMd5Expression($column)
{
return 'MD5(' . $column . ')';
}
/**
* Returns the SQL snippet to get the length of a text field.
*
* @param string $column
*
* @return string
*/
public function getLengthExpression($column)
{
return 'LENGTH(' . $column . ')';
}
/**
* Returns the SQL snippet to get the squared value of a column.
*
* @param string $column The column to use.
*
* @return string Generated SQL including an SQRT aggregate function.
*/
public function getSqrtExpression($column)
{
return 'SQRT(' . $column . ')';
}
/**
* Returns the SQL snippet to round a numeric field to the number of decimals specified.
*
* @param string $column
* @param int $decimals
*
* @return string
*/
public function getRoundExpression($column, $decimals = 0)
{
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 || $char !== false) {
$expression .= 'FROM ';
}
return 'TRIM(' . $expression . $str . ')';
}
/**
* Returns the SQL snippet to trim trailing space characters from the expression.
*
* @param string $str Literal string or column name.
*
* @return string
*/
public function getRtrimExpression($str)
{
return 'RTRIM(' . $str . ')';
}
/**
* Returns the SQL snippet to trim leading space characters from the expression.
*
* @param string $str Literal string or column name.
*
* @return string
*/
public function getLtrimExpression($str)
{
return 'LTRIM(' . $str . ')';
}
/**
* Returns the SQL snippet to change all characters from the expression to uppercase,
* according to the current character set mapping.
*
* @param string $str Literal string or column name.
*
* @return string
*/
public function getUpperExpression($str)
{
return 'UPPER(' . $str . ')';
}
/**
* Returns the SQL snippet to change all characters from the expression to lowercase,
* according to the current character set mapping.
*
* @param string $str Literal string or column name.
*
* @return string
*/
public function getLowerExpression($str)
{
return 'LOWER(' . $str . ')';
}
/**
* Returns the SQL snippet to get the position of the first occurrence of substring $substr in string $str.
*
* @param string $str Literal string.
* @param string $substr Literal string to find.
* @param int|bool $startPos Position to start at, beginning of string by default.
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
public function getLocateExpression($str, $substr, $startPos = false)
{
throw DBALException::notSupported(__METHOD__);
}
/**
* Returns the SQL snippet to get the current system date.
*
* @return string
*/
public function getNowExpression()
{
return 'NOW()';
}
/**
* Returns a SQL snippet to get a substring inside an SQL statement.
*
* Note: Not SQL92, but common functionality.
*
* SQLite only supports the 2 parameter variant of this function.
*
* @param string $value An sql string literal or column name/alias.
* @param int $from Where to start the substring portion.
* @param int|null $length The substring portion length.
*
* @return string
*/
public function getSubstringExpression($value, $from, $length = null)
{
if ($length === null) {
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
}
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $length . ')';
}
/**
* Returns a SQL snippet to concatenate the given expressions.
*
* Accepts an arbitrary number of string parameters. Each parameter must contain an expression.
*
* @return string
*/
public function getConcatExpression()
{
return implode(' || ', func_get_args());
}
/**
* Returns the SQL for a logical not.
*
* Example:
* <code>
* $q = new Doctrine_Query();
* $e = $q->expr;
* $q->select('*')->from('table')
* ->where($e->eq('id', $e->not('null'));
* </code>
*
* @param string $expression
*
* @return string The logical expression.
*/
public function getNotExpression($expression)
{
return 'NOT(' . $expression . ')';
}
/**
* Returns the SQL that checks if an expression is null.
*
* @param string $expression The expression that should be compared to null.
*
* @return string The logical expression.
*/
public function getIsNullExpression($expression)
{
return $expression . ' IS NULL';
}
/**
* Returns the SQL that checks if an expression is not null.
*
* @param string $expression The expression that should be compared to null.
*
* @return string The logical expression.
*/
public function getIsNotNullExpression($expression)
{
return $expression . ' IS NOT NULL';
}
/**
* Returns the SQL that checks if an expression evaluates to a value between two values.
*
* The parameter $expression is checked if it is between $value1 and $value2.
*
* Note: There is a slight difference in the way BETWEEN works on some databases.
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database
* independence you should avoid using between().
*
* @param string $expression The value to compare to.
* @param string $value1 The lower value to compare with.
* @param string $value2 The higher value to compare with.
*
* @return string The logical expression.
*/
public function getBetweenExpression($expression, $value1, $value2)
{
return $expression . ' BETWEEN ' . $value1 . ' AND ' . $value2;
}
/**
* Returns the SQL to get the arccosine of a value.
*
* @param string $value
*
* @return string
*/
public function getAcosExpression($value)
{
return 'ACOS(' . $value . ')';
}
/**