protected Schema::createFieldSql($name, $spec)
Create an SQL string for a field to be used in table creation or alteration.
Before passing a field out of a schema definition into this function it has to be processed by _db_process_field().
Parameters
string $name: Name of the field.
array $spec: The field specification, as per the schema data structure format.
File
- core/lib/Drupal/Core/Database/Driver/mysql/Schema.php, line 147
Class
- Schema
- MySQL implementation of \Drupal\Core\Database\Schema.
Namespace
Drupal\Core\Database\Driver\mysql
Code
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 | protected function createFieldSql( $name , $spec ) { $sql = "`" . $name . "` " . $spec [ 'mysql_type' ]; if (in_array( $spec [ 'mysql_type' ], $this ->mysqlStringTypes)) { if (isset( $spec [ 'length' ])) { $sql .= '(' . $spec [ 'length' ] . ')' ; } if (! empty ( $spec [ 'binary' ])) { $sql .= ' BINARY' ; } // Note we check for the "type" key here. "mysql_type" is VARCHAR: if (isset( $spec [ 'type' ]) && $spec [ 'type' ] == 'varchar_ascii' ) { $sql .= ' CHARACTER SET ascii COLLATE ascii_general_ci' ; } } elseif (isset( $spec [ 'precision' ]) && isset( $spec [ 'scale' ])) { $sql .= '(' . $spec [ 'precision' ] . ', ' . $spec [ 'scale' ] . ')' ; } if (! empty ( $spec [ 'unsigned' ])) { $sql .= ' unsigned' ; } if (isset( $spec [ 'not null' ])) { if ( $spec [ 'not null' ]) { $sql .= ' NOT NULL' ; } else { $sql .= ' NULL' ; } } if (! empty ( $spec [ 'auto_increment' ])) { $sql .= ' auto_increment' ; } // $spec['default'] can be NULL, so we explicitly check for the key here. if ( array_key_exists ( 'default' , $spec )) { $sql .= ' DEFAULT ' . $this ->escapeDefaultValue( $spec [ 'default' ]); } if ( empty ( $spec [ 'not null' ]) && !isset( $spec [ 'default' ])) { $sql .= ' DEFAULT NULL' ; } // Add column comment. if (! empty ( $spec [ 'description' ])) { $sql .= ' COMMENT ' . $this ->prepareComment( $spec [ 'description' ], self::COMMENT_MAX_COLUMN); } return $sql ; } |
Please login to continue.