Class SqliteSchema
Schema management/reflection features for Sqlite
Property Summary
- 
        $_constraintsIdMap protectedarrayArray containing the foreign keys constraints names Necessary for composite foreign keys to be handled 
- 
        $_driver protectedCake\Database\DriverThe driver instance being used. 
Method Summary
- 
          __construct() publicConstructor 
- 
          _convertColumn() protectedConvert a column definition to the abstract types. 
- 
          _convertConstraintColumns() protectedConvert foreign key constraints references to a valid stringified list 
- 
          _convertOnClause() protectedConvert string on clauses to the abstract ones. 
- 
          _defaultValue() protectedManipulate the default value. 
- 
          _foreignOnClause() protectedGenerate an ON clause for a foreign key. 
- 
          addConstraintSql() publicGenerate the SQL queries needed to add foreign key constraints to the table 
- 
          columnSql() publicGenerate the SQL fragment for a single column in a table. 
- 
          constraintSql() publicGenerate the SQL fragments for defining table constraints. 
- 
          convertColumnDescription() publicConvert field description results into abstract schema fields. 
- 
          convertForeignKeyDescription() publicConvert a foreign key description into constraints on the Table object. 
- 
          convertIndexDescription() publicConvert an index description results into abstract schema indexes or constraints. 
- 
          convertOptionsDescription() publicConvert options data into table options. 
- 
          createTableSql() publicGenerate the SQL to create a table. 
- 
          describeColumnSql() publicGenerate the SQL to describe a table. 
- 
          describeForeignKeySql() publicGenerate the SQL to describe the foreign keys in a table. 
- 
          describeIndexSql() publicGenerate the SQL to describe the indexes in a table. 
- 
          describeOptionsSql() publicGenerate the SQL to describe table options 
- 
          dropConstraintSql() publicGenerate the SQL queries needed to drop foreign key constraints from the table 
- 
          dropTableSql() publicGenerate the SQL to drop a table. 
- 
          hasSequences() publicReturns whether there is any table in this connection to SQLite containing sequences 
- 
          indexSql() publicGenerate the SQL fragment for a single index in a table. 
- 
          listTablesSql() publicGenerate the SQL to list the tables. 
- 
          truncateTableSql() publicGenerate the SQL to truncate a table. 
Method Detail
__construct() ¶ public
__construct(Cake\Database\Driver $driver)Constructor
This constructor will connect the driver so that methods like columnSql() and others will fail when the driver has not been connected.
Parameters
- 
                Cake\Database\Driver$driver
- The driver to use. 
_convertColumn() ¶ protected
_convertColumn(string $column): arrayConvert a column definition to the abstract types.
The returned type will be a type that Cake\Database\Type can handle.
Parameters
- 
                string$column
- The column type + length 
Returns
arrayArray of column information.
Throws
Cake\Database\Exceptionwhen unable to parse column type
_convertConstraintColumns() ¶ protected
_convertConstraintColumns(string|array $references): stringConvert foreign key constraints references to a valid stringified list
Parameters
- 
                string|array$references
- The referenced columns of a foreign key constraint statement 
Returns
string_convertOnClause() ¶ protected
_convertOnClause(string $clause): string|nullConvert string on clauses to the abstract ones.
Parameters
- 
                string$clause
- The on clause to convert. 
Returns
string|null_defaultValue() ¶ protected
_defaultValue(string|null $default): string|nullManipulate the default value.
Sqlite includes quotes and bared NULLs in default values. We need to remove those.
Parameters
- 
                string|null$default
- The default value. 
Returns
string|null_foreignOnClause() ¶ protected
_foreignOnClause(string|null $on): stringGenerate an ON clause for a foreign key.
Parameters
- 
                string|null$on
- The on clause 
Returns
stringaddConstraintSql() ¶ public
addConstraintSql(Cake\Database\Schema\Table $table): arrayGenerate the SQL queries needed to add foreign key constraints to the table
SQLite can not properly handle adding a constraint to an existing table. This method is no-op
Parameters
- 
                Cake\Database\Schema\Table$table
Returns
arraycolumnSql() ¶ public
columnSql(Cake\Database\Schema\Table $table, string $name): stringGenerate the SQL fragment for a single column in a table.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                string$name
Returns
stringThrows
Cake\Database\Exceptionwhen the column type is unknown
constraintSql() ¶ public
constraintSql(Cake\Database\Schema\Table $table, string $name): stringGenerate the SQL fragments for defining table constraints.
Note integer primary keys will return ''. This is intentional as Sqlite requires that integer primary keys be defined in the column definition.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                string$name
Returns
stringconvertColumnDescription() ¶ public
convertColumnDescription(Cake\Database\Schema\Table $table, array $row): voidConvert field description results into abstract schema fields.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                array$row
Returns
voidconvertForeignKeyDescription() ¶ public
convertForeignKeyDescription(Cake\Database\Schema\Table $table, array $row): voidConvert a foreign key description into constraints on the Table object.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                array$row
Returns
voidconvertIndexDescription() ¶ public
convertIndexDescription(Cake\Database\Schema\Table $table, array $row): voidConvert an index description results into abstract schema indexes or constraints.
Since SQLite does not have a way to get metadata about all indexes at once, additional queries are done here. Sqlite constraint names are not stable, and the names for constraints will not match those used to create the table. This is a limitation in Sqlite's metadata features.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                array$row
Returns
voidconvertOptionsDescription() ¶ public
convertOptionsDescription(Cake\Database\Schema\Table $table, array $row): voidConvert options data into table options.
Parameters
- 
                Cake\Database\Schema\Table$table
- Table instance. 
- 
                array$row
- The row of data. 
Returns
voidcreateTableSql() ¶ public
createTableSql(Cake\Database\Schema\Table $table, array $columns, array $constraints, array $indexes): arrayGenerate the SQL to create a table.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                array$columns
- 
                array$constraints
- 
                array$indexes
Returns
arraydescribeColumnSql() ¶ public
describeColumnSql(string $tableName, array $config): arrayGenerate the SQL to describe a table.
Parameters
- 
                string$tableName
- 
                array$config
Returns
arraydescribeForeignKeySql() ¶ public
describeForeignKeySql(string $tableName, array $config): arrayGenerate the SQL to describe the foreign keys in a table.
Parameters
- 
                string$tableName
- 
                array$config
Returns
arraydescribeIndexSql() ¶ public
describeIndexSql(string $tableName, array $config): arrayGenerate the SQL to describe the indexes in a table.
Parameters
- 
                string$tableName
- 
                array$config
Returns
arraydescribeOptionsSql() ¶ public
describeOptionsSql(string $tableName, array $config): arrayGenerate the SQL to describe table options
Parameters
- 
                string$tableName
- Table name. 
- 
                array$config
- The connection configuration. 
Returns
arraySQL statements to get options for a table.
dropConstraintSql() ¶ public
dropConstraintSql(Cake\Database\Schema\Table $table): arrayGenerate the SQL queries needed to drop foreign key constraints from the table
SQLite can not properly handle dropping a constraint to an existing table. This method is no-op
Parameters
- 
                Cake\Database\Schema\Table$table
Returns
arraydropTableSql() ¶ public
dropTableSql(Cake\Database\Schema\Table $table): arrayGenerate the SQL to drop a table.
Parameters
- 
                Cake\Database\Schema\Table$table
- Table instance 
Returns
arraySQL statements to drop a table.
hasSequences() ¶ public
hasSequences(): boolReturns whether there is any table in this connection to SQLite containing sequences
Returns
boolindexSql() ¶ public
indexSql(Cake\Database\Schema\Table $table, string $name): stringGenerate the SQL fragment for a single index in a table.
Parameters
- 
                Cake\Database\Schema\Table$table
- 
                string$name
Returns
stringlistTablesSql() ¶ public
listTablesSql(array $config): arrayGenerate the SQL to list the tables.
Parameters
- 
                array$config
Returns
arraytruncateTableSql() ¶ public
truncateTableSql(Cake\Database\Schema\Table $table): arrayGenerate the SQL to truncate a table.
Parameters
- 
                Cake\Database\Schema\Table$table
Returns
array