/**
* Override DatabaseSchema::$defaultSchema
+ *
+ * @var string
*/
protected $defaultSchema = 'main';
+ /**
+ * {@inheritdoc}
+ */
public function tableExists($table) {
$info = $this->getPrefixInfo($table);
return (bool) $this->connection->query('SELECT 1 FROM ' . $info['schema'] . '.sqlite_master WHERE type = :type AND name = :name', [':type' => 'table', ':name' => $info['table']])->fetchField();
}
+ /**
+ * {@inheritdoc}
+ */
public function fieldExists($table, $column) {
$schema = $this->introspectSchema($table);
return !empty($schema['fields'][$column]);
* to be processed by db_processField().
*
* @param $name
- * Name of the field.
+ * Name of the field.
* @param $spec
- * The field specification, as per the schema data structure format.
+ * The field specification, as per the schema data structure format.
*/
protected function createFieldSql($name, $spec) {
if (!empty($spec['auto_increment'])) {
}
/**
- * This maps a generic data type in combination with its data size
- * to the engine-specific data type.
+ * {@inheritdoc}
*/
public function getFieldTypeMap() {
// Put :normal last so it gets preserved by array_flip. This makes
return $map;
}
+ /**
+ * {@inheritdoc}
+ */
public function renameTable($table, $new_name) {
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", ['@table' => $table, '@table_new' => $new_name]));
}
}
+ /**
+ * {@inheritdoc}
+ */
public function dropTable($table) {
if (!$this->tableExists($table)) {
return FALSE;
return TRUE;
}
+ /**
+ * {@inheritdoc}
+ */
public function addField($table, $field, $specification, $keys_new = []) {
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", ['@field' => $field, '@table' => $table]));
return $schema;
}
+ /**
+ * {@inheritdoc}
+ */
public function dropField($table, $field) {
if (!$this->fieldExists($table, $field)) {
return FALSE;
return TRUE;
}
+ /**
+ * {@inheritdoc}
+ */
public function changeField($table, $field, $field_new, $spec, $keys_new = []) {
if (!$this->fieldExists($table, $field)) {
throw new SchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", ['@table' => $table, '@name' => $field]));
}
}
+ /**
+ * {@inheritdoc}
+ */
public function indexExists($table, $name) {
$info = $this->getPrefixInfo($table);
return $this->connection->query('PRAGMA ' . $info['schema'] . '.index_info(' . $info['table'] . '_' . $name . ')')->fetchField() != '';
}
+ /**
+ * {@inheritdoc}
+ */
public function dropIndex($table, $name) {
if (!$this->indexExists($table, $name)) {
return FALSE;
return TRUE;
}
+ /**
+ * {@inheritdoc}
+ */
public function addUniqueKey($table, $name, $fields) {
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException(t("Cannot add unique key @name to table @table: table doesn't exist.", ['@table' => $table, '@name' => $name]));
}
}
+ /**
+ * {@inheritdoc}
+ */
public function dropUniqueKey($table, $name) {
if (!$this->indexExists($table, $name)) {
return FALSE;
return TRUE;
}
+ /**
+ * {@inheritdoc}
+ */
public function addPrimaryKey($table, $fields) {
if (!$this->tableExists($table)) {
throw new SchemaObjectDoesNotExistException(t("Cannot add primary key to table @table: table doesn't exist.", ['@table' => $table]));
$this->alterTable($table, $old_schema, $new_schema);
}
+ /**
+ * {@inheritdoc}
+ */
public function dropPrimaryKey($table) {
$old_schema = $this->introspectSchema($table);
$new_schema = $old_schema;
return TRUE;
}
+ /**
+ * {@inheritdoc}
+ */
public function fieldSetDefault($table, $field, $default) {
if (!$this->fieldExists($table, $field)) {
throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field]));
$this->alterTable($table, $old_schema, $new_schema);
}
+ /**
+ * {@inheritdoc}
+ */
public function fieldSetNoDefault($table, $field) {
if (!$this->fieldExists($table, $field)) {
throw new SchemaObjectDoesNotExistException(t("Cannot remove default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field]));