protected function DatabaseSchema_sqlite::createFieldSql
protected DatabaseSchema_sqlite::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_processField().
Parameters
$name: Name of the field.
$spec: The field specification, as per the schema data structure format.
File
- includes/database/sqlite/schema.inc, line 147
- Database schema code for SQLite databases.
Class
Code
protected function createFieldSql($name, $spec) { if (!empty($spec['auto_increment'])) { $sql = $name . " INTEGER PRIMARY KEY AUTOINCREMENT"; if (!empty($spec['unsigned'])) { $sql .= ' CHECK (' . $name . '>= 0)'; } } else { $sql = $name . ' ' . $spec['sqlite_type']; if (in_array($spec['sqlite_type'], array('VARCHAR', 'TEXT')) && isset($spec['length'])) { $sql .= '(' . $spec['length'] . ')'; } if (isset($spec['not null'])) { if ($spec['not null']) { $sql .= ' NOT NULL'; } else { $sql .= ' NULL'; } } if (!empty($spec['unsigned'])) { $sql .= ' CHECK (' . $name . '>= 0)'; } if (isset($spec['default'])) { if (is_string($spec['default'])) { $spec['default'] = "'" . $spec['default'] . "'"; } $sql .= ' DEFAULT ' . $spec['default']; } if (empty($spec['not null']) && !isset($spec['default'])) { $sql .= ' DEFAULT NULL'; } } return $sql; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!database!sqlite!schema.inc/function/DatabaseSchema_sqlite::createFieldSql/7.x