SqlServerGrammar.php 22 KB

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