12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046 |
- <?php
- namespace Illuminate\Database\Schema\Grammars;
- use RuntimeException;
- use Illuminate\Support\Fluent;
- use Illuminate\Database\Connection;
- use Illuminate\Database\Schema\Blueprint;
- class MySqlGrammar extends Grammar
- {
- /**
- * The possible column modifiers.
- *
- * @var array
- */
- protected $modifiers = [
- 'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
- 'Default', 'Increment', 'Comment', 'After', 'First', 'Srid',
- ];
- /**
- * The possible column serials.
- *
- * @var array
- */
- protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
- /**
- * Compile the query to determine the list of tables.
- *
- * @return string
- */
- public function compileTableExists()
- {
- return "select * from information_schema.tables where table_schema = ? and table_name = ? and table_type = 'BASE TABLE'";
- }
- /**
- * Compile the query to determine the list of columns.
- *
- * @return string
- */
- public function compileColumnListing()
- {
- return 'select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?';
- }
- /**
- * Compile a create table command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @param \Illuminate\Database\Connection $connection
- * @return string
- */
- public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
- {
- $sql = $this->compileCreateTable(
- $blueprint, $command, $connection
- );
- // Once we have the primary SQL, we can add the encoding option to the SQL for
- // the table. Then, we can check if a storage engine has been supplied for
- // the table. If so, we will add the engine declaration to the SQL query.
- $sql = $this->compileCreateEncoding(
- $sql, $connection, $blueprint
- );
- // Finally, we will append the engine configuration onto this SQL statement as
- // the final thing we do before returning this finished SQL. Once this gets
- // added the query will be ready to execute against the real connections.
- return $this->compileCreateEngine(
- $sql, $connection, $blueprint
- );
- }
- /**
- * Create the main create table clause.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @param \Illuminate\Database\Connection $connection
- * @return string
- */
- protected function compileCreateTable($blueprint, $command, $connection)
- {
- return sprintf('%s table %s (%s)',
- $blueprint->temporary ? 'create temporary' : 'create',
- $this->wrapTable($blueprint),
- implode(', ', $this->getColumns($blueprint))
- );
- }
- /**
- * Append the character set specifications to a command.
- *
- * @param string $sql
- * @param \Illuminate\Database\Connection $connection
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @return string
- */
- protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
- {
- // First we will set the character set if one has been set on either the create
- // blueprint itself or on the root configuration for the connection that the
- // table is being created on. We will add these to the create table query.
- if (isset($blueprint->charset)) {
- $sql .= ' default character set '.$blueprint->charset;
- } elseif (! is_null($charset = $connection->getConfig('charset'))) {
- $sql .= ' default character set '.$charset;
- }
- // Next we will add the collation to the create table statement if one has been
- // added to either this create table blueprint or the configuration for this
- // connection that the query is targeting. We'll add it to this SQL query.
- if (isset($blueprint->collation)) {
- $sql .= " collate '{$blueprint->collation}'";
- } elseif (! is_null($collation = $connection->getConfig('collation'))) {
- $sql .= " collate '{$collation}'";
- }
- return $sql;
- }
- /**
- * Append the engine specifications to a command.
- *
- * @param string $sql
- * @param \Illuminate\Database\Connection $connection
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @return string
- */
- protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint)
- {
- if (isset($blueprint->engine)) {
- return $sql.' engine = '.$blueprint->engine;
- } elseif (! is_null($engine = $connection->getConfig('engine'))) {
- return $sql.' engine = '.$engine;
- }
- return $sql;
- }
- /**
- * Compile an add column command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileAdd(Blueprint $blueprint, Fluent $command)
- {
- $columns = $this->prefixArray('add', $this->getColumns($blueprint));
- return 'alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns);
- }
- /**
- * Compile a primary key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compilePrimary(Blueprint $blueprint, Fluent $command)
- {
- $command->name(null);
- return $this->compileKey($blueprint, $command, 'primary key');
- }
- /**
- * Compile a unique key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileUnique(Blueprint $blueprint, Fluent $command)
- {
- return $this->compileKey($blueprint, $command, 'unique');
- }
- /**
- * Compile a plain index key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileIndex(Blueprint $blueprint, Fluent $command)
- {
- return $this->compileKey($blueprint, $command, 'index');
- }
- /**
- * Compile a spatial index key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
- {
- return $this->compileKey($blueprint, $command, 'spatial index');
- }
- /**
- * Compile an index creation command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @param string $type
- * @return string
- */
- protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
- {
- return sprintf('alter table %s add %s %s%s(%s)',
- $this->wrapTable($blueprint),
- $type,
- $this->wrap($command->index),
- $command->algorithm ? ' using '.$command->algorithm : '',
- $this->columnize($command->columns)
- );
- }
- /**
- * Compile a drop table command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDrop(Blueprint $blueprint, Fluent $command)
- {
- return 'drop table '.$this->wrapTable($blueprint);
- }
- /**
- * Compile a drop table (if exists) command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
- {
- return 'drop table if exists '.$this->wrapTable($blueprint);
- }
- /**
- * Compile a drop column command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropColumn(Blueprint $blueprint, Fluent $command)
- {
- $columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
- return 'alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns);
- }
- /**
- * Compile a drop primary key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
- {
- return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
- }
- /**
- * Compile a drop unique key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropUnique(Blueprint $blueprint, Fluent $command)
- {
- $index = $this->wrap($command->index);
- return "alter table {$this->wrapTable($blueprint)} drop index {$index}";
- }
- /**
- * Compile a drop index command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropIndex(Blueprint $blueprint, Fluent $command)
- {
- $index = $this->wrap($command->index);
- return "alter table {$this->wrapTable($blueprint)} drop index {$index}";
- }
- /**
- * Compile a drop spatial index command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
- {
- return $this->compileDropIndex($blueprint, $command);
- }
- /**
- * Compile a drop foreign key command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileDropForeign(Blueprint $blueprint, Fluent $command)
- {
- $index = $this->wrap($command->index);
- return "alter table {$this->wrapTable($blueprint)} drop foreign key {$index}";
- }
- /**
- * Compile a rename table command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileRename(Blueprint $blueprint, Fluent $command)
- {
- $from = $this->wrapTable($blueprint);
- return "rename table {$from} to ".$this->wrapTable($command->to);
- }
- /**
- * Compile a rename index command.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $command
- * @return string
- */
- public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
- {
- return sprintf('alter table %s rename index %s to %s',
- $this->wrapTable($blueprint),
- $this->wrap($command->from),
- $this->wrap($command->to)
- );
- }
- /**
- * Compile the SQL needed to drop all tables.
- *
- * @param array $tables
- * @return string
- */
- public function compileDropAllTables($tables)
- {
- return 'drop table '.implode(',', $this->wrapArray($tables));
- }
- /**
- * Compile the SQL needed to drop all views.
- *
- * @param array $views
- * @return string
- */
- public function compileDropAllViews($views)
- {
- return 'drop view '.implode(',', $this->wrapArray($views));
- }
- /**
- * Compile the SQL needed to retrieve all table names.
- *
- * @return string
- */
- public function compileGetAllTables()
- {
- return 'SHOW FULL TABLES WHERE table_type = \'BASE TABLE\'';
- }
- /**
- * Compile the SQL needed to retrieve all view names.
- *
- * @return string
- */
- public function compileGetAllViews()
- {
- return 'SHOW FULL TABLES WHERE table_type = \'VIEW\'';
- }
- /**
- * Compile the command to enable foreign key constraints.
- *
- * @return string
- */
- public function compileEnableForeignKeyConstraints()
- {
- return 'SET FOREIGN_KEY_CHECKS=1;';
- }
- /**
- * Compile the command to disable foreign key constraints.
- *
- * @return string
- */
- public function compileDisableForeignKeyConstraints()
- {
- return 'SET FOREIGN_KEY_CHECKS=0;';
- }
- /**
- * Create the column definition for a char type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeChar(Fluent $column)
- {
- return "char({$column->length})";
- }
- /**
- * Create the column definition for a string type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeString(Fluent $column)
- {
- return "varchar({$column->length})";
- }
- /**
- * Create the column definition for a text type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeText(Fluent $column)
- {
- return 'text';
- }
- /**
- * Create the column definition for a medium text type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeMediumText(Fluent $column)
- {
- return 'mediumtext';
- }
- /**
- * Create the column definition for a long text type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeLongText(Fluent $column)
- {
- return 'longtext';
- }
- /**
- * Create the column definition for a big integer type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeBigInteger(Fluent $column)
- {
- return 'bigint';
- }
- /**
- * Create the column definition for an integer type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeInteger(Fluent $column)
- {
- return 'int';
- }
- /**
- * Create the column definition for a medium integer type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeMediumInteger(Fluent $column)
- {
- return 'mediumint';
- }
- /**
- * Create the column definition for a tiny integer type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeTinyInteger(Fluent $column)
- {
- return 'tinyint';
- }
- /**
- * Create the column definition for a small integer type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeSmallInteger(Fluent $column)
- {
- return 'smallint';
- }
- /**
- * Create the column definition for a float type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeFloat(Fluent $column)
- {
- return $this->typeDouble($column);
- }
- /**
- * Create the column definition for a double type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeDouble(Fluent $column)
- {
- if ($column->total && $column->places) {
- return "double({$column->total}, {$column->places})";
- }
- return 'double';
- }
- /**
- * Create the column definition for a decimal type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeDecimal(Fluent $column)
- {
- return "decimal({$column->total}, {$column->places})";
- }
- /**
- * Create the column definition for a boolean type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeBoolean(Fluent $column)
- {
- return 'tinyint(1)';
- }
- /**
- * Create the column definition for an enumeration type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeEnum(Fluent $column)
- {
- return sprintf('enum(%s)', $this->quoteString($column->allowed));
- }
- /**
- * Create the column definition for a set enumeration type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeSet(Fluent $column)
- {
- return sprintf('set(%s)', $this->quoteString($column->allowed));
- }
- /**
- * Create the column definition for a json type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeJson(Fluent $column)
- {
- return 'json';
- }
- /**
- * Create the column definition for a jsonb type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeJsonb(Fluent $column)
- {
- return 'json';
- }
- /**
- * Create the column definition for a date type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeDate(Fluent $column)
- {
- return 'date';
- }
- /**
- * Create the column definition for a date-time type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeDateTime(Fluent $column)
- {
- $columnType = $column->precision ? "datetime($column->precision)" : 'datetime';
- return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
- }
- /**
- * Create the column definition for a date-time (with time zone) type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeDateTimeTz(Fluent $column)
- {
- return $this->typeDateTime($column);
- }
- /**
- * Create the column definition for a time type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeTime(Fluent $column)
- {
- return $column->precision ? "time($column->precision)" : 'time';
- }
- /**
- * Create the column definition for a time (with time zone) type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeTimeTz(Fluent $column)
- {
- return $this->typeTime($column);
- }
- /**
- * Create the column definition for a timestamp type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeTimestamp(Fluent $column)
- {
- $columnType = $column->precision ? "timestamp($column->precision)" : 'timestamp';
- return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
- }
- /**
- * Create the column definition for a timestamp (with time zone) type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeTimestampTz(Fluent $column)
- {
- return $this->typeTimestamp($column);
- }
- /**
- * Create the column definition for a year type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeYear(Fluent $column)
- {
- return 'year';
- }
- /**
- * Create the column definition for a binary type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeBinary(Fluent $column)
- {
- return 'blob';
- }
- /**
- * Create the column definition for a uuid type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeUuid(Fluent $column)
- {
- return 'char(36)';
- }
- /**
- * Create the column definition for an IP address type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeIpAddress(Fluent $column)
- {
- return 'varchar(45)';
- }
- /**
- * Create the column definition for a MAC address type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- protected function typeMacAddress(Fluent $column)
- {
- return 'varchar(17)';
- }
- /**
- * Create the column definition for a spatial Geometry type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeGeometry(Fluent $column)
- {
- return 'geometry';
- }
- /**
- * Create the column definition for a spatial Point type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typePoint(Fluent $column)
- {
- return 'point';
- }
- /**
- * Create the column definition for a spatial LineString type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeLineString(Fluent $column)
- {
- return 'linestring';
- }
- /**
- * Create the column definition for a spatial Polygon type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typePolygon(Fluent $column)
- {
- return 'polygon';
- }
- /**
- * Create the column definition for a spatial GeometryCollection type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeGeometryCollection(Fluent $column)
- {
- return 'geometrycollection';
- }
- /**
- * Create the column definition for a spatial MultiPoint type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeMultiPoint(Fluent $column)
- {
- return 'multipoint';
- }
- /**
- * Create the column definition for a spatial MultiLineString type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeMultiLineString(Fluent $column)
- {
- return 'multilinestring';
- }
- /**
- * Create the column definition for a spatial MultiPolygon type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return string
- */
- public function typeMultiPolygon(Fluent $column)
- {
- return 'multipolygon';
- }
- /**
- * Create the column definition for a generated, computed column type.
- *
- * @param \Illuminate\Support\Fluent $column
- * @return void
- *
- * @throws \RuntimeException
- */
- protected function typeComputed(Fluent $column)
- {
- throw new RuntimeException('This database driver requires a type, see the virtualAs / storedAs modifiers.');
- }
- /**
- * Get the SQL for a generated virtual column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->virtualAs)) {
- return " as ({$column->virtualAs})";
- }
- }
- /**
- * Get the SQL for a generated stored column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->storedAs)) {
- return " as ({$column->storedAs}) stored";
- }
- }
- /**
- * Get the SQL for an unsigned column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
- {
- if ($column->unsigned) {
- return ' unsigned';
- }
- }
- /**
- * Get the SQL for a character set column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyCharset(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->charset)) {
- return ' character set '.$column->charset;
- }
- }
- /**
- * Get the SQL for a collation column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyCollate(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->collation)) {
- return " collate '{$column->collation}'";
- }
- }
- /**
- * Get the SQL for a nullable column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyNullable(Blueprint $blueprint, Fluent $column)
- {
- if (is_null($column->virtualAs) && is_null($column->storedAs)) {
- return $column->nullable ? ' null' : ' not null';
- }
- }
- /**
- * Get the SQL for a default column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyDefault(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->default)) {
- return ' default '.$this->getDefaultValue($column->default);
- }
- }
- /**
- * Get the SQL for an auto-increment column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
- {
- if (in_array($column->type, $this->serials) && $column->autoIncrement) {
- return ' auto_increment primary key';
- }
- }
- /**
- * Get the SQL for a "first" column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyFirst(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->first)) {
- return ' first';
- }
- }
- /**
- * Get the SQL for an "after" column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyAfter(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->after)) {
- return ' after '.$this->wrap($column->after);
- }
- }
- /**
- * Get the SQL for a "comment" column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifyComment(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->comment)) {
- return " comment '".addslashes($column->comment)."'";
- }
- }
- /**
- * Get the SQL for a SRID column modifier.
- *
- * @param \Illuminate\Database\Schema\Blueprint $blueprint
- * @param \Illuminate\Support\Fluent $column
- * @return string|null
- */
- protected function modifySrid(Blueprint $blueprint, Fluent $column)
- {
- if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
- return ' srid '.$column->srid;
- }
- }
- /**
- * Wrap a single string in keyword identifiers.
- *
- * @param string $value
- * @return string
- */
- protected function wrapValue($value)
- {
- if ($value !== '*') {
- return '`'.str_replace('`', '``', $value).'`';
- }
- return $value;
- }
- }
|