Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Schema\Grammars;
4
 
5
use Illuminate\Database\Connection;
6
use Illuminate\Database\Schema\Blueprint;
7
use Illuminate\Support\Fluent;
8
 
9
class SqlServerGrammar extends Grammar
10
{
11
    /**
12
     * If this Grammar supports schema changes wrapped in a transaction.
13
     *
14
     * @var bool
15
     */
16
    protected $transactions = true;
17
 
18
    /**
19
     * The possible column modifiers.
20
     *
21
     * @var string[]
22
     */
23
    protected $modifiers = ['Increment', 'Collate', 'Nullable', 'Default', 'Persisted'];
24
 
25
    /**
26
     * The columns available as serials.
27
     *
28
     * @var string[]
29
     */
30
    protected $serials = ['tinyInteger', 'smallInteger', 'mediumInteger', 'integer', 'bigInteger'];
31
 
32
    /**
33
     * Compile a create database command.
34
     *
35
     * @param  string  $name
36
     * @param  \Illuminate\Database\Connection  $connection
37
     * @return string
38
     */
39
    public function compileCreateDatabase($name, $connection)
40
    {
41
        return sprintf(
42
            'create database %s',
43
            $this->wrapValue($name),
44
        );
45
    }
46
 
47
    /**
48
     * Compile a drop database if exists command.
49
     *
50
     * @param  string  $name
51
     * @return string
52
     */
53
    public function compileDropDatabaseIfExists($name)
54
    {
55
        return sprintf(
56
            'drop database if exists %s',
57
            $this->wrapValue($name)
58
        );
59
    }
60
 
61
    /**
62
     * Compile the query to determine if a table exists.
63
     *
64
     * @return string
65
     */
66
    public function compileTableExists()
67
    {
68
        return "select * from sys.sysobjects where id = object_id(?) and xtype in ('U', 'V')";
69
    }
70
 
71
    /**
72
     * Compile the query to determine the list of columns.
73
     *
74
     * @param  string  $table
75
     * @return string
76
     */
77
    public function compileColumnListing($table)
78
    {
79
        return "select name from sys.columns where object_id = object_id('$table')";
80
    }
81
 
82
    /**
83
     * Compile a create table command.
84
     *
85
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
86
     * @param  \Illuminate\Support\Fluent  $command
87
     * @return string
88
     */
89
    public function compileCreate(Blueprint $blueprint, Fluent $command)
90
    {
91
        $columns = implode(', ', $this->getColumns($blueprint));
92
 
93
        return 'create table '.$this->wrapTable($blueprint)." ($columns)";
94
    }
95
 
96
    /**
97
     * Compile a column addition table command.
98
     *
99
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
100
     * @param  \Illuminate\Support\Fluent  $command
101
     * @return string
102
     */
103
    public function compileAdd(Blueprint $blueprint, Fluent $command)
104
    {
105
        return sprintf('alter table %s add %s',
106
            $this->wrapTable($blueprint),
107
            implode(', ', $this->getColumns($blueprint))
108
        );
109
    }
110
 
111
    /**
112
     * Compile a rename column command.
113
     *
114
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
115
     * @param  \Illuminate\Support\Fluent  $command
116
     * @param  \Illuminate\Database\Connection  $connection
117
     * @return array|string
118
     */
119
    public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
120
    {
121
        return $connection->usingNativeSchemaOperations()
122
            ? sprintf("sp_rename '%s', %s, 'COLUMN'",
123
                $this->wrap($blueprint->getTable().'.'.$command->from),
124
                $this->wrap($command->to)
125
            )
126
            : parent::compileRenameColumn($blueprint, $command, $connection);
127
    }
128
 
129
    /**
130
     * Compile a primary key command.
131
     *
132
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
133
     * @param  \Illuminate\Support\Fluent  $command
134
     * @return string
135
     */
136
    public function compilePrimary(Blueprint $blueprint, Fluent $command)
137
    {
138
        return sprintf('alter table %s add constraint %s primary key (%s)',
139
            $this->wrapTable($blueprint),
140
            $this->wrap($command->index),
141
            $this->columnize($command->columns)
142
        );
143
    }
144
 
145
    /**
146
     * Compile a unique key command.
147
     *
148
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
149
     * @param  \Illuminate\Support\Fluent  $command
150
     * @return string
151
     */
152
    public function compileUnique(Blueprint $blueprint, Fluent $command)
153
    {
154
        return sprintf('create unique index %s on %s (%s)',
155
            $this->wrap($command->index),
156
            $this->wrapTable($blueprint),
157
            $this->columnize($command->columns)
158
        );
159
    }
160
 
161
    /**
162
     * Compile a plain index key command.
163
     *
164
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
165
     * @param  \Illuminate\Support\Fluent  $command
166
     * @return string
167
     */
168
    public function compileIndex(Blueprint $blueprint, Fluent $command)
169
    {
170
        return sprintf('create index %s on %s (%s)',
171
            $this->wrap($command->index),
172
            $this->wrapTable($blueprint),
173
            $this->columnize($command->columns)
174
        );
175
    }
176
 
177
    /**
178
     * Compile a spatial index key command.
179
     *
180
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
181
     * @param  \Illuminate\Support\Fluent  $command
182
     * @return string
183
     */
184
    public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
185
    {
186
        return sprintf('create spatial index %s on %s (%s)',
187
            $this->wrap($command->index),
188
            $this->wrapTable($blueprint),
189
            $this->columnize($command->columns)
190
        );
191
    }
192
 
193
    /**
194
     * Compile a drop table command.
195
     *
196
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
197
     * @param  \Illuminate\Support\Fluent  $command
198
     * @return string
199
     */
200
    public function compileDrop(Blueprint $blueprint, Fluent $command)
201
    {
202
        return 'drop table '.$this->wrapTable($blueprint);
203
    }
204
 
205
    /**
206
     * Compile a drop table (if exists) command.
207
     *
208
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
209
     * @param  \Illuminate\Support\Fluent  $command
210
     * @return string
211
     */
212
    public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
213
    {
214
        return sprintf('if exists (select * from sys.sysobjects where id = object_id(%s, \'U\')) drop table %s',
215
            "'".str_replace("'", "''", $this->getTablePrefix().$blueprint->getTable())."'",
216
            $this->wrapTable($blueprint)
217
        );
218
    }
219
 
220
    /**
221
     * Compile the SQL needed to drop all tables.
222
     *
223
     * @return string
224
     */
225
    public function compileDropAllTables()
226
    {
227
        return "EXEC sp_msforeachtable 'DROP TABLE ?'";
228
    }
229
 
230
    /**
231
     * Compile a drop column command.
232
     *
233
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
234
     * @param  \Illuminate\Support\Fluent  $command
235
     * @return string
236
     */
237
    public function compileDropColumn(Blueprint $blueprint, Fluent $command)
238
    {
239
        $columns = $this->wrapArray($command->columns);
240
 
241
        $dropExistingConstraintsSql = $this->compileDropDefaultConstraint($blueprint, $command).';';
242
 
243
        return $dropExistingConstraintsSql.'alter table '.$this->wrapTable($blueprint).' drop column '.implode(', ', $columns);
244
    }
245
 
246
    /**
247
     * Compile a drop default constraint command.
248
     *
249
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
250
     * @param  \Illuminate\Support\Fluent  $command
251
     * @return string
252
     */
253
    public function compileDropDefaultConstraint(Blueprint $blueprint, Fluent $command)
254
    {
255
        $columns = "'".implode("','", $command->columns)."'";
256
 
257
        $tableName = $this->getTablePrefix().$blueprint->getTable();
258
 
259
        $sql = "DECLARE @sql NVARCHAR(MAX) = '';";
260
        $sql .= "SELECT @sql += 'ALTER TABLE [dbo].[{$tableName}] DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' ";
261
        $sql .= 'FROM sys.columns ';
262
        $sql .= "WHERE [object_id] = OBJECT_ID('[dbo].[{$tableName}]') AND [name] in ({$columns}) AND [default_object_id] <> 0;";
263
        $sql .= 'EXEC(@sql)';
264
 
265
        return $sql;
266
    }
267
 
268
    /**
269
     * Compile a drop primary key command.
270
     *
271
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
272
     * @param  \Illuminate\Support\Fluent  $command
273
     * @return string
274
     */
275
    public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
276
    {
277
        $index = $this->wrap($command->index);
278
 
279
        return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
280
    }
281
 
282
    /**
283
     * Compile a drop unique key command.
284
     *
285
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
286
     * @param  \Illuminate\Support\Fluent  $command
287
     * @return string
288
     */
289
    public function compileDropUnique(Blueprint $blueprint, Fluent $command)
290
    {
291
        $index = $this->wrap($command->index);
292
 
293
        return "drop index {$index} on {$this->wrapTable($blueprint)}";
294
    }
295
 
296
    /**
297
     * Compile a drop index command.
298
     *
299
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
300
     * @param  \Illuminate\Support\Fluent  $command
301
     * @return string
302
     */
303
    public function compileDropIndex(Blueprint $blueprint, Fluent $command)
304
    {
305
        $index = $this->wrap($command->index);
306
 
307
        return "drop index {$index} on {$this->wrapTable($blueprint)}";
308
    }
309
 
310
    /**
311
     * Compile a drop spatial index command.
312
     *
313
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
314
     * @param  \Illuminate\Support\Fluent  $command
315
     * @return string
316
     */
317
    public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
318
    {
319
        return $this->compileDropIndex($blueprint, $command);
320
    }
321
 
322
    /**
323
     * Compile a drop foreign key command.
324
     *
325
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
326
     * @param  \Illuminate\Support\Fluent  $command
327
     * @return string
328
     */
329
    public function compileDropForeign(Blueprint $blueprint, Fluent $command)
330
    {
331
        $index = $this->wrap($command->index);
332
 
333
        return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
334
    }
335
 
336
    /**
337
     * Compile a rename table command.
338
     *
339
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
340
     * @param  \Illuminate\Support\Fluent  $command
341
     * @return string
342
     */
343
    public function compileRename(Blueprint $blueprint, Fluent $command)
344
    {
345
        $from = $this->wrapTable($blueprint);
346
 
347
        return "sp_rename {$from}, ".$this->wrapTable($command->to);
348
    }
349
 
350
    /**
351
     * Compile a rename index command.
352
     *
353
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
354
     * @param  \Illuminate\Support\Fluent  $command
355
     * @return string
356
     */
357
    public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
358
    {
359
        return sprintf("sp_rename N'%s', %s, N'INDEX'",
360
            $this->wrap($blueprint->getTable().'.'.$command->from),
361
            $this->wrap($command->to)
362
        );
363
    }
364
 
365
    /**
366
     * Compile the command to enable foreign key constraints.
367
     *
368
     * @return string
369
     */
370
    public function compileEnableForeignKeyConstraints()
371
    {
372
        return 'EXEC sp_msforeachtable @command1="print \'?\'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all";';
373
    }
374
 
375
    /**
376
     * Compile the command to disable foreign key constraints.
377
     *
378
     * @return string
379
     */
380
    public function compileDisableForeignKeyConstraints()
381
    {
382
        return 'EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";';
383
    }
384
 
385
    /**
386
     * Compile the command to drop all foreign keys.
387
     *
388
     * @return string
389
     */
390
    public function compileDropAllForeignKeys()
391
    {
392
        return "DECLARE @sql NVARCHAR(MAX) = N'';
393
            SELECT @sql += 'ALTER TABLE '
394
                + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' + + QUOTENAME(OBJECT_NAME(parent_object_id))
395
                + ' DROP CONSTRAINT ' + QUOTENAME(name) + ';'
396
            FROM sys.foreign_keys;
397
 
398
            EXEC sp_executesql @sql;";
399
    }
400
 
401
    /**
402
     * Compile the command to drop all views.
403
     *
404
     * @return string
405
     */
406
    public function compileDropAllViews()
407
    {
408
        return "DECLARE @sql NVARCHAR(MAX) = N'';
409
            SELECT @sql += 'DROP VIEW ' + QUOTENAME(OBJECT_SCHEMA_NAME(object_id)) + '.' + QUOTENAME(name) + ';'
410
            FROM sys.views;
411
 
412
            EXEC sp_executesql @sql;";
413
    }
414
 
415
    /**
416
     * Compile the SQL needed to retrieve all table names.
417
     *
418
     * @return string
419
     */
420
    public function compileGetAllTables()
421
    {
422
        return "select name, type from sys.tables where type = 'U'";
423
    }
424
 
425
    /**
426
     * Compile the SQL needed to retrieve all view names.
427
     *
428
     * @return string
429
     */
430
    public function compileGetAllViews()
431
    {
432
        return "select name, type from sys.objects where type = 'V'";
433
    }
434
 
435
    /**
436
     * Create the column definition for a char type.
437
     *
438
     * @param  \Illuminate\Support\Fluent  $column
439
     * @return string
440
     */
441
    protected function typeChar(Fluent $column)
442
    {
443
        return "nchar({$column->length})";
444
    }
445
 
446
    /**
447
     * Create the column definition for a string type.
448
     *
449
     * @param  \Illuminate\Support\Fluent  $column
450
     * @return string
451
     */
452
    protected function typeString(Fluent $column)
453
    {
454
        return "nvarchar({$column->length})";
455
    }
456
 
457
    /**
458
     * Create the column definition for a tiny text type.
459
     *
460
     * @param  \Illuminate\Support\Fluent  $column
461
     * @return string
462
     */
463
    protected function typeTinyText(Fluent $column)
464
    {
465
        return 'nvarchar(255)';
466
    }
467
 
468
    /**
469
     * Create the column definition for a text type.
470
     *
471
     * @param  \Illuminate\Support\Fluent  $column
472
     * @return string
473
     */
474
    protected function typeText(Fluent $column)
475
    {
476
        return 'nvarchar(max)';
477
    }
478
 
479
    /**
480
     * Create the column definition for a medium text type.
481
     *
482
     * @param  \Illuminate\Support\Fluent  $column
483
     * @return string
484
     */
485
    protected function typeMediumText(Fluent $column)
486
    {
487
        return 'nvarchar(max)';
488
    }
489
 
490
    /**
491
     * Create the column definition for a long text type.
492
     *
493
     * @param  \Illuminate\Support\Fluent  $column
494
     * @return string
495
     */
496
    protected function typeLongText(Fluent $column)
497
    {
498
        return 'nvarchar(max)';
499
    }
500
 
501
    /**
502
     * Create the column definition for an integer type.
503
     *
504
     * @param  \Illuminate\Support\Fluent  $column
505
     * @return string
506
     */
507
    protected function typeInteger(Fluent $column)
508
    {
509
        return 'int';
510
    }
511
 
512
    /**
513
     * Create the column definition for a big integer type.
514
     *
515
     * @param  \Illuminate\Support\Fluent  $column
516
     * @return string
517
     */
518
    protected function typeBigInteger(Fluent $column)
519
    {
520
        return 'bigint';
521
    }
522
 
523
    /**
524
     * Create the column definition for a medium integer type.
525
     *
526
     * @param  \Illuminate\Support\Fluent  $column
527
     * @return string
528
     */
529
    protected function typeMediumInteger(Fluent $column)
530
    {
531
        return 'int';
532
    }
533
 
534
    /**
535
     * Create the column definition for a tiny integer type.
536
     *
537
     * @param  \Illuminate\Support\Fluent  $column
538
     * @return string
539
     */
540
    protected function typeTinyInteger(Fluent $column)
541
    {
542
        return 'tinyint';
543
    }
544
 
545
    /**
546
     * Create the column definition for a small integer type.
547
     *
548
     * @param  \Illuminate\Support\Fluent  $column
549
     * @return string
550
     */
551
    protected function typeSmallInteger(Fluent $column)
552
    {
553
        return 'smallint';
554
    }
555
 
556
    /**
557
     * Create the column definition for a float type.
558
     *
559
     * @param  \Illuminate\Support\Fluent  $column
560
     * @return string
561
     */
562
    protected function typeFloat(Fluent $column)
563
    {
564
        return 'float';
565
    }
566
 
567
    /**
568
     * Create the column definition for a double type.
569
     *
570
     * @param  \Illuminate\Support\Fluent  $column
571
     * @return string
572
     */
573
    protected function typeDouble(Fluent $column)
574
    {
575
        return 'float';
576
    }
577
 
578
    /**
579
     * Create the column definition for a decimal type.
580
     *
581
     * @param  \Illuminate\Support\Fluent  $column
582
     * @return string
583
     */
584
    protected function typeDecimal(Fluent $column)
585
    {
586
        return "decimal({$column->total}, {$column->places})";
587
    }
588
 
589
    /**
590
     * Create the column definition for a boolean type.
591
     *
592
     * @param  \Illuminate\Support\Fluent  $column
593
     * @return string
594
     */
595
    protected function typeBoolean(Fluent $column)
596
    {
597
        return 'bit';
598
    }
599
 
600
    /**
601
     * Create the column definition for an enumeration type.
602
     *
603
     * @param  \Illuminate\Support\Fluent  $column
604
     * @return string
605
     */
606
    protected function typeEnum(Fluent $column)
607
    {
608
        return sprintf(
609
            'nvarchar(255) check ("%s" in (%s))',
610
            $column->name,
611
            $this->quoteString($column->allowed)
612
        );
613
    }
614
 
615
    /**
616
     * Create the column definition for a json type.
617
     *
618
     * @param  \Illuminate\Support\Fluent  $column
619
     * @return string
620
     */
621
    protected function typeJson(Fluent $column)
622
    {
623
        return 'nvarchar(max)';
624
    }
625
 
626
    /**
627
     * Create the column definition for a jsonb type.
628
     *
629
     * @param  \Illuminate\Support\Fluent  $column
630
     * @return string
631
     */
632
    protected function typeJsonb(Fluent $column)
633
    {
634
        return 'nvarchar(max)';
635
    }
636
 
637
    /**
638
     * Create the column definition for a date type.
639
     *
640
     * @param  \Illuminate\Support\Fluent  $column
641
     * @return string
642
     */
643
    protected function typeDate(Fluent $column)
644
    {
645
        return 'date';
646
    }
647
 
648
    /**
649
     * Create the column definition for a date-time type.
650
     *
651
     * @param  \Illuminate\Support\Fluent  $column
652
     * @return string
653
     */
654
    protected function typeDateTime(Fluent $column)
655
    {
656
        return $this->typeTimestamp($column);
657
    }
658
 
659
    /**
660
     * Create the column definition for a date-time (with time zone) type.
661
     *
662
     * @param  \Illuminate\Support\Fluent  $column
663
     * @return string
664
     */
665
    protected function typeDateTimeTz(Fluent $column)
666
    {
667
        return $this->typeTimestampTz($column);
668
    }
669
 
670
    /**
671
     * Create the column definition for a time type.
672
     *
673
     * @param  \Illuminate\Support\Fluent  $column
674
     * @return string
675
     */
676
    protected function typeTime(Fluent $column)
677
    {
678
        return $column->precision ? "time($column->precision)" : 'time';
679
    }
680
 
681
    /**
682
     * Create the column definition for a time (with time zone) type.
683
     *
684
     * @param  \Illuminate\Support\Fluent  $column
685
     * @return string
686
     */
687
    protected function typeTimeTz(Fluent $column)
688
    {
689
        return $this->typeTime($column);
690
    }
691
 
692
    /**
693
     * Create the column definition for a timestamp type.
694
     *
695
     * @param  \Illuminate\Support\Fluent  $column
696
     * @return string
697
     */
698
    protected function typeTimestamp(Fluent $column)
699
    {
700
        $columnType = $column->precision ? "datetime2($column->precision)" : 'datetime';
701
 
702
        return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
703
    }
704
 
705
    /**
706
     * Create the column definition for a timestamp (with time zone) type.
707
     *
708
     * @link https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-ver15
709
     *
710
     * @param  \Illuminate\Support\Fluent  $column
711
     * @return string
712
     */
713
    protected function typeTimestampTz(Fluent $column)
714
    {
715
        $columnType = $column->precision ? "datetimeoffset($column->precision)" : 'datetimeoffset';
716
 
717
        return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
718
    }
719
 
720
    /**
721
     * Create the column definition for a year type.
722
     *
723
     * @param  \Illuminate\Support\Fluent  $column
724
     * @return string
725
     */
726
    protected function typeYear(Fluent $column)
727
    {
728
        return $this->typeInteger($column);
729
    }
730
 
731
    /**
732
     * Create the column definition for a binary type.
733
     *
734
     * @param  \Illuminate\Support\Fluent  $column
735
     * @return string
736
     */
737
    protected function typeBinary(Fluent $column)
738
    {
739
        return 'varbinary(max)';
740
    }
741
 
742
    /**
743
     * Create the column definition for a uuid type.
744
     *
745
     * @param  \Illuminate\Support\Fluent  $column
746
     * @return string
747
     */
748
    protected function typeUuid(Fluent $column)
749
    {
750
        return 'uniqueidentifier';
751
    }
752
 
753
    /**
754
     * Create the column definition for an IP address type.
755
     *
756
     * @param  \Illuminate\Support\Fluent  $column
757
     * @return string
758
     */
759
    protected function typeIpAddress(Fluent $column)
760
    {
761
        return 'nvarchar(45)';
762
    }
763
 
764
    /**
765
     * Create the column definition for a MAC address type.
766
     *
767
     * @param  \Illuminate\Support\Fluent  $column
768
     * @return string
769
     */
770
    protected function typeMacAddress(Fluent $column)
771
    {
772
        return 'nvarchar(17)';
773
    }
774
 
775
    /**
776
     * Create the column definition for a spatial Geometry type.
777
     *
778
     * @param  \Illuminate\Support\Fluent  $column
779
     * @return string
780
     */
781
    public function typeGeometry(Fluent $column)
782
    {
783
        return 'geography';
784
    }
785
 
786
    /**
787
     * Create the column definition for a spatial Point type.
788
     *
789
     * @param  \Illuminate\Support\Fluent  $column
790
     * @return string
791
     */
792
    public function typePoint(Fluent $column)
793
    {
794
        return 'geography';
795
    }
796
 
797
    /**
798
     * Create the column definition for a spatial LineString type.
799
     *
800
     * @param  \Illuminate\Support\Fluent  $column
801
     * @return string
802
     */
803
    public function typeLineString(Fluent $column)
804
    {
805
        return 'geography';
806
    }
807
 
808
    /**
809
     * Create the column definition for a spatial Polygon type.
810
     *
811
     * @param  \Illuminate\Support\Fluent  $column
812
     * @return string
813
     */
814
    public function typePolygon(Fluent $column)
815
    {
816
        return 'geography';
817
    }
818
 
819
    /**
820
     * Create the column definition for a spatial GeometryCollection type.
821
     *
822
     * @param  \Illuminate\Support\Fluent  $column
823
     * @return string
824
     */
825
    public function typeGeometryCollection(Fluent $column)
826
    {
827
        return 'geography';
828
    }
829
 
830
    /**
831
     * Create the column definition for a spatial MultiPoint type.
832
     *
833
     * @param  \Illuminate\Support\Fluent  $column
834
     * @return string
835
     */
836
    public function typeMultiPoint(Fluent $column)
837
    {
838
        return 'geography';
839
    }
840
 
841
    /**
842
     * Create the column definition for a spatial MultiLineString type.
843
     *
844
     * @param  \Illuminate\Support\Fluent  $column
845
     * @return string
846
     */
847
    public function typeMultiLineString(Fluent $column)
848
    {
849
        return 'geography';
850
    }
851
 
852
    /**
853
     * Create the column definition for a spatial MultiPolygon type.
854
     *
855
     * @param  \Illuminate\Support\Fluent  $column
856
     * @return string
857
     */
858
    public function typeMultiPolygon(Fluent $column)
859
    {
860
        return 'geography';
861
    }
862
 
863
    /**
864
     * Create the column definition for a generated, computed column type.
865
     *
866
     * @param  \Illuminate\Support\Fluent  $column
867
     * @return string|null
868
     */
869
    protected function typeComputed(Fluent $column)
870
    {
871
        return "as ({$column->expression})";
872
    }
873
 
874
    /**
875
     * Get the SQL for a collation column modifier.
876
     *
877
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
878
     * @param  \Illuminate\Support\Fluent  $column
879
     * @return string|null
880
     */
881
    protected function modifyCollate(Blueprint $blueprint, Fluent $column)
882
    {
883
        if (! is_null($column->collation)) {
884
            return ' collate '.$column->collation;
885
        }
886
    }
887
 
888
    /**
889
     * Get the SQL for a nullable column modifier.
890
     *
891
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
892
     * @param  \Illuminate\Support\Fluent  $column
893
     * @return string|null
894
     */
895
    protected function modifyNullable(Blueprint $blueprint, Fluent $column)
896
    {
897
        if ($column->type !== 'computed') {
898
            return $column->nullable ? ' null' : ' not null';
899
        }
900
    }
901
 
902
    /**
903
     * Get the SQL for a default column modifier.
904
     *
905
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
906
     * @param  \Illuminate\Support\Fluent  $column
907
     * @return string|null
908
     */
909
    protected function modifyDefault(Blueprint $blueprint, Fluent $column)
910
    {
911
        if (! is_null($column->default)) {
912
            return ' default '.$this->getDefaultValue($column->default);
913
        }
914
    }
915
 
916
    /**
917
     * Get the SQL for an auto-increment column modifier.
918
     *
919
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
920
     * @param  \Illuminate\Support\Fluent  $column
921
     * @return string|null
922
     */
923
    protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
924
    {
925
        if (in_array($column->type, $this->serials) && $column->autoIncrement) {
926
            return ' identity primary key';
927
        }
928
    }
929
 
930
    /**
931
     * Get the SQL for a generated stored column modifier.
932
     *
933
     * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
934
     * @param  \Illuminate\Support\Fluent  $column
935
     * @return string|null
936
     */
937
    protected function modifyPersisted(Blueprint $blueprint, Fluent $column)
938
    {
939
        if ($column->persisted) {
940
            return ' persisted';
941
        }
942
    }
943
 
944
    /**
945
     * Wrap a table in keyword identifiers.
946
     *
947
     * @param  \Illuminate\Database\Query\Expression|string  $table
948
     * @return string
949
     */
950
    public function wrapTable($table)
951
    {
952
        if ($table instanceof Blueprint && $table->temporary) {
953
            $this->setTablePrefix('#');
954
        }
955
 
956
        return parent::wrapTable($table);
957
    }
958
 
959
    /**
960
     * Quote the given string literal.
961
     *
962
     * @param  string|array  $value
963
     * @return string
964
     */
965
    public function quoteString($value)
966
    {
967
        if (is_array($value)) {
968
            return implode(', ', array_map([$this, __FUNCTION__], $value));
969
        }
970
 
971
        return "N'$value'";
972
    }
973
}