class MySQLSchemaManager extends DBSchemaManager

Represents schema management object for MySQL

Constants

ID

Identifier for this schema, used for configuring schema-specific table creation options

Methods

setDatabase(Database $database)

Injector injection point for database controller

quiet(bool $quiet = true)

Enable supression of database messages.

query(string $sql, int $errorLevel = E_USER_ERROR)

Execute the given SQL query.

preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)

Execute the given SQL parameterised query with the specified arguments

schemaUpdate(callable $callback)

Initiates a schema update within a single callback

cancelSchemaUpdate()

Cancels the schema updates requested during (but not after) schemaUpdate() call.

boolean
isSchemaUpdating()

Returns true if we are during a schema update.

boolean
doesSchemaNeedUpdating()

Returns true if schema modifications were requested during (but not after) schemaUpdate() call.

transCreateTable(string $table, array $options = null, array $advanced_options = null)

Instruct the schema manager to record a table creation to later execute

transAlterTable(string $table, array $options, array $advanced_options)

Instruct the schema manager to record a table alteration to later execute

transCreateField(string $table, string $field, string $schema)

Instruct the schema manager to record a field to be later created

transCreateIndex(string $table, string $index, array $schema)

Instruct the schema manager to record an index to be later created

transAlterField(string $table, string $field, string $schema)

Instruct the schema manager to record a field to be later updated

transAlterIndex(string $table, string $index, array $schema)

Instruct the schema manager to record an index to be later updated

requireTable(string $table, array $fieldSchema = null, array $indexSchema = null, boolean $hasAutoIncPK = true, array $options = array(), array|bool $extensions = false)

Generate the following table in the database, modifying whatever already exists as necessary.

dontRequireTable(string $table)

If the given table exists, move it out of the way by renaming it to obsolete(tablename).

requireIndex(string $table, string $index, string|array|boolean $spec)

Generate the given index in the database, modifying whatever already exists as necessary.

boolean
hasTable($table)

Returns true if the given table is exists in the current database

bool
hasField(string $tableName, string $fieldName)

Return true if the table exists and already has a the field specified

requireField(string $table, string $field, array|string $spec)

Generate the given field on the table, modifying whatever already exists as necessary.

dontRequireField(string $table, string $fieldName)

If the given field exists, move it out of the way by renaming it to obsolete(fieldname).

alterationMessage(string $message, string $type = "")

Show a message about database alteration

string
IdColumn(boolean $asDbValue = false, boolean $hasAutoIncPK = true)

This returns the data type for the id column which is the primary key for each table

boolean
checkAndRepairTable(string $tableName)

Checks a table's integrity and repairs it if necessary.

fixTableCase(string $tableName)

Ensure the given table has the correct case

array
enumValuesForField(string $tableName, string $fieldName)

Returns the values of the given enum field

dbDataType($type)

No description

array
databaseList()

Retrieves the list of all databases the user has access to

boolean
databaseExists(string $name)

Determine if the database with the specified name exists

boolean
createDatabase(string $name)

Create a database with the specified name

dropDatabase(string $name)

Drops a database with the specified name

alterIndex(string $tableName, string $indexName, array $indexSpec)

Alter an index on a table.

array[array]
indexList(string $table)

Return the list of indexes in a table.

array
tableList()

Returns a list of all tables in the database.

string
createTable(string $table, array $fields = null, array $indexes = null, array $options = null, array $advancedOptions = null)

Create a new table.

alterTable($tableName, array $newFields = null, array $newIndexes = null, array $alteredFields = null, array $alteredIndexes = null, array $alteredOptions = null, array $advancedOptions = null)

Alter a table's schema.

renameTable(string $oldTableName, string $newTableName)

Renames a table

createField($tableName, $fieldName, $fieldSpec)

Create a new field on a table.

renameField(string $tableName, string $oldName, string $newName)

Change the database column name of the given field.

array
fieldList(string $table)

Get a list of all the fields for the given table.

boolean
clearCachedFieldlist(string $tableName = null)

This allows the cached values for a table's field list to be erased.

string
boolean(array $values)

Return a boolean type-formatted string

string
date(array $values)

Return a date type-formatted string For MySQL, we simply return the word 'date', no other parameters are necessary

string
decimal(array $values)

Return a decimal type-formatted string

string
enum(array $values)

Return a enum type-formatted string

string
set(array $values)

Return a set type-formatted string

string
float(array $values)

Return a float type-formatted string For MySQL, we simply return the word 'date', no other parameters are necessary

string
int(array $values)

Return a int type-formatted string

string
datetime(array $values)

Return a datetime type-formatted string For MySQL, we simply return the word 'datetime', no other parameters are necessary

string
text(array $values)

Return a text type-formatted string

string
time(array $values)

Return a time type-formatted string For MySQL, we simply return the word 'time', no other parameters are necessary

string
varchar(array $values)

Return a varchar type-formatted string

year($values)

No description

isView($tableName)

No description

alterField(string $tableName, string $fieldName, string $fieldSpec)

Change the database type of the given field.

createIndex(string $tableName, string $indexName, string $indexSpec)

Create an index on a table.

string
bigint(array $values)

Return a bigint type-formatted string

Details

in DBSchemaManager at line 59
setDatabase(Database $database)

Injector injection point for database controller

Parameters

Database $database

in DBSchemaManager at line 91
quiet(bool $quiet = true)

Enable supression of database messages.

Parameters

bool $quiet

in DBSchemaManager at line 105
Query query(string $sql, int $errorLevel = E_USER_ERROR)

Execute the given SQL query.

This abstract function must be defined by subclasses as part of the actual implementation. It should return a subclass of SS_Query as the result.

Parameters

string $sql The SQL query to execute
int $errorLevel The level of error reporting to enable for the query

Return Value

Query

in DBSchemaManager at line 119
Query preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)

Execute the given SQL parameterised query with the specified arguments

Parameters

string $sql The SQL query to execute. The ? character will denote parameters.
array $parameters An ordered list of arguments.
int $errorLevel The level of error reporting to enable for the query

Return Value

Query

in DBSchemaManager at line 129
schemaUpdate(callable $callback)

Initiates a schema update within a single callback

Parameters

callable $callback

in DBSchemaManager at line 191
cancelSchemaUpdate()

Cancels the schema updates requested during (but not after) schemaUpdate() call.

in DBSchemaManager at line 202
boolean isSchemaUpdating()

Returns true if we are during a schema update.

Return Value

boolean

in DBSchemaManager at line 212
boolean doesSchemaNeedUpdating()

Returns true if schema modifications were requested during (but not after) schemaUpdate() call.

Return Value

boolean

in DBSchemaManager at line 226
transCreateTable(string $table, array $options = null, array $advanced_options = null)

Instruct the schema manager to record a table creation to later execute

Parameters

string $table Name of the table
array $options Create table options (ENGINE, etc.)
array $advanced_options Advanced table creation options

in DBSchemaManager at line 244
transAlterTable(string $table, array $options, array $advanced_options)

Instruct the schema manager to record a table alteration to later execute

Parameters

string $table Name of the table
array $options Create table options (ENGINE, etc.)
array $advanced_options Advanced table creation options

in DBSchemaManager at line 258
transCreateField(string $table, string $field, string $schema)

Instruct the schema manager to record a field to be later created

Parameters

string $table Name of the table to hold this field
string $field Name of the field to create
string $schema Field specification as a string

in DBSchemaManager at line 271
transCreateIndex(string $table, string $index, array $schema)

Instruct the schema manager to record an index to be later created

Parameters

string $table Name of the table to hold this index
string $index Name of the index to create
array $schema Already parsed index specification

in DBSchemaManager at line 284
transAlterField(string $table, string $field, string $schema)

Instruct the schema manager to record a field to be later updated

Parameters

string $table Name of the table to hold this field
string $field Name of the field to update
string $schema Field specification as a string

in DBSchemaManager at line 297
transAlterIndex(string $table, string $index, array $schema)

Instruct the schema manager to record an index to be later updated

Parameters

string $table Name of the table to hold this index
string $index Name of the index to update
array $schema Already parsed index specification

in DBSchemaManager at line 340
requireTable(string $table, array $fieldSchema = null, array $indexSchema = null, boolean $hasAutoIncPK = true, array $options = array(), array|bool $extensions = false)

Generate the following table in the database, modifying whatever already exists as necessary.

Parameters

string $table The name of the table
array $fieldSchema A list of the fields to create, in the same form as DataObject::$db
array $indexSchema A list of indexes to create. See {@link requireIndex()} The values of the array can be one of: - true: Create a single column index on the field named the same as the index. - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full control over the index.
boolean $hasAutoIncPK A flag indicating that the primary key on this table is an autoincrement type
array $options Create table options (ENGINE, etc.)
array|bool $extensions List of extensions

in DBSchemaManager at line 421
dontRequireTable(string $table)

If the given table exists, move it out of the way by renaming it to obsolete(tablename).

Parameters

string $table The table name.

in DBSchemaManager at line 454
requireIndex(string $table, string $index, string|array|boolean $spec)

Generate the given index in the database, modifying whatever already exists as necessary.

The keys of the array are the names of the index. The values of the array can be one of: - true: Create a single column index on the field named the same as the index. - array('type' => 'index|unique|fulltext', 'value' => 'FieldA, FieldB'): This gives you full control over the index.

Parameters

string $table The table name.
string $index The index name.
string|array|boolean $spec The specification of the index in any loose format. See requireTable() for more information.

at line 202
boolean hasTable($table)

Returns true if the given table is exists in the current database

Parameters

$table

Return Value

boolean Flag indicating existence of table

in DBSchemaManager at line 602
bool hasField(string $tableName, string $fieldName)

Return true if the table exists and already has a the field specified

Parameters

string $tableName
  • The table to check
string $fieldName
  • The field to check

Return Value

bool
  • True if the table exists and the field exists on the table

in DBSchemaManager at line 621
requireField(string $table, string $field, array|string $spec)

Generate the given field on the table, modifying whatever already exists as necessary.

Parameters

string $table The table name.
string $field The field name.
array|string $spec The field specification. If passed in array syntax, the specific database driver takes care of the ALTER TABLE syntax. If passed as a string, its assumed to be prepared as a direct SQL framgment ready for insertion into ALTER TABLE. In this case you'll need to take care of database abstraction in your DBField subclass.

in DBSchemaManager at line 728
dontRequireField(string $table, string $fieldName)

If the given field exists, move it out of the way by renaming it to obsolete(fieldname).

Parameters

string $table
string $fieldName

in DBSchemaManager at line 752
alterationMessage(string $message, string $type = "")

Show a message about database alteration

Parameters

string $message to display
string $type one of [created|changed|repaired|obsolete|deleted|error]

at line 644
string IdColumn(boolean $asDbValue = false, boolean $hasAutoIncPK = true)

This returns the data type for the id column which is the primary key for each table

Parameters

boolean $asDbValue
boolean $hasAutoIncPK

Return Value

string

at line 160
boolean checkAndRepairTable(string $tableName)

Checks a table's integrity and repairs it if necessary.

Parameters

string $tableName The name of the table.

Return Value

boolean Return true if the table has integrity after the method is complete.

in DBSchemaManager at line 831
fixTableCase(string $tableName)

Ensure the given table has the correct case

Parameters

string $tableName Name of table in desired case

at line 396
array enumValuesForField(string $tableName, string $fieldName)

Returns the values of the given enum field

Parameters

string $tableName Name of table to check
string $fieldName name of enum field to check

Return Value

array List of enum values

at line 409
dbDataType($type)

Parameters

$type

at line 215
array databaseList()

Retrieves the list of all databases the user has access to

Return Value

array List of database names

at line 220
boolean databaseExists(string $name)

Determine if the database with the specified name exists

Parameters

string $name Name of the database to check for

Return Value

boolean Flag indicating whether this database exists

at line 227
boolean createDatabase(string $name)

Create a database with the specified name

Parameters

string $name Name of the database to create

Return Value

boolean True if successful

at line 234
dropDatabase(string $name)

Drops a database with the specified name

Parameters

string $name Name of the database to drop

at line 332
alterIndex(string $tableName, string $indexName, array $indexSpec)

Alter an index on a table.

Parameters

string $tableName The name of the table.
string $indexName The name of the index.
array $indexSpec The specification of the index, see Database::requireIndex() for more details.

at line 350
array[array] indexList(string $table)

Return the list of indexes in a table.

Parameters

string $table The table name.

Return Value

array[array] List of current indexes in the table, each in standard array form. The key for this array should be predictable using the indexKey method

at line 386
array tableList()

Returns a list of all tables in the database.

Keys are table names in lower case, values are table names in case that database expects.

Return Value

array

at line 23
string createTable(string $table, array $fields = null, array $indexes = null, array $options = null, array $advancedOptions = null)

Create a new table.

Parameters

string $table The name of the table
array $fields A map of field names to field types
array $indexes A map of indexes
array $options An map of additional options. The available keys are as follows: - 'MSSQLDatabase'/'MySQLDatabase'/'PostgreSQLDatabase' - database-specific options such as "engine" for MySQL. - 'temporary' - If true, then a temporary table will be created
array $advancedOptions Advanced creation options

Return Value

string The table name generated. This may be different from the table name, for example with temporary tables.

at line 65
alterTable($tableName, array $newFields = null, array $newIndexes = null, array $alteredFields = null, array $alteredIndexes = null, array $alteredOptions = null, array $advancedOptions = null)

Alter a table's schema.

Parameters

$tableName
array $newFields New fields, a map of field name => field schema
array $newIndexes New indexes, a map of index name => index type
array $alteredFields Updated fields, a map of field name => field schema
array $alteredIndexes Updated indexes, a map of index name => index type
array $alteredOptions
array $advancedOptions

at line 151
renameTable(string $oldTableName, string $newTableName)

Renames a table

Parameters

string $oldTableName The old table name.
string $newTableName The new table name.

Exceptions

LogicException

at line 210
createField($tableName, $fieldName, $fieldSpec)

Create a new field on a table.

Parameters

$tableName
$fieldName
$fieldSpec

at line 257
renameField(string $tableName, string $oldName, string $newName)

Change the database column name of the given field.

Parameters

string $tableName The name of the tbale the field is in.
string $oldName The name of the field to change.
string $newName The new name of the field

at line 267
array fieldList(string $table)

Get a list of all the fields for the given table.

Returns a map of field name => field spec.

Parameters

string $table The table name.

Return Value

array

in DBSchemaManager at line 1033
boolean clearCachedFieldlist(string $tableName = null)

This allows the cached values for a table's field list to be erased.

If $tablename is empty, then the whole cache is erased.

Parameters

string $tableName

Return Value

boolean

at line 428
string boolean(array $values)

Return a boolean type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 445
string date(array $values)

Return a date type-formatted string For MySQL, we simply return the word 'date', no other parameters are necessary

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 459
string decimal(array $values)

Return a decimal type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 490
string enum(array $values)

Return a enum type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 509
string set(array $values)

Return a set type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 529
string float(array $values)

Return a float type-formatted string For MySQL, we simply return the word 'date', no other parameters are necessary

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 543
string int(array $values)

Return a int type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 575
string datetime(array $values)

Return a datetime type-formatted string For MySQL, we simply return the word 'datetime', no other parameters are necessary

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 589
string text(array $values)

Return a text type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 606
string time(array $values)

Return a time type-formatted string For MySQL, we simply return the word 'time', no other parameters are necessary

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 620
string varchar(array $values)

Return a varchar type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string

at line 639
year($values)

Parameters

$values

at line 137
isView($tableName)

Parameters

$tableName

at line 245
alterField(string $tableName, string $fieldName, string $fieldSpec)

Change the database type of the given field.

Parameters

string $tableName The name of the tbale the field is in.
string $fieldName The name of the field to change.
string $fieldSpec The new field specification

at line 307
createIndex(string $tableName, string $indexName, string $indexSpec)

Create an index on a table.

Parameters

string $tableName The name of the table.
string $indexName The name of the index.
string $indexSpec The specification of the index, see {@link SS_Database::requireIndex()} for more details.

at line 557
string bigint(array $values)

Return a bigint type-formatted string

Parameters

array $values Contains a tokenised list of info about this data type

Return Value

string