MysqlSchema

Type
Class
Namespace
Craft
Inherits
Craft\MysqlSchema » CMysqlSchema » CDbSchema » CComponent
Since
1.0

Class MysqlSchema

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$columnTypesarray – The abstract column types mapped to physical column types.
$maxObjectNameLengthinteger – The maximum length that objects' names can be.

$maxObjectNameLength

Type
integer

The maximum length that objects' names can be.

View source

Signature

public integer $maxObjectNameLength = 64

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
addColumn()Builds a SQL statement for adding a new DB column.
addColumnAfter()
addColumnBefore()
addColumnFirst()
addForeignKey()Builds a SQL statement for adding a foreign key constraint to an existing table.
addPrimaryKey()Builds a SQL statement for adding a primary key constraint to an existing table.
alterColumn()
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
checkIntegrity()Enables or disables integrity check.
compareTableNames()Compares two table names.
createIndex()Builds a SQL statement for creating a new index.
createTable()
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
dropColumn()Builds a SQL statement for dropping a DB column.
dropForeignKey()Builds a SQL statement for dropping a foreign key constraint.
dropIndex()Builds a SQL statement for dropping an index.
dropPrimaryKey()Builds a SQL statement for removing a primary key constraint to an existing table.
dropTable()Builds a SQL statement for dropping a DB table.
dropTableIfExists()Builds a SQL statement for dropping a DB table if it exists.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
getColumnType()Converts an abstract column type into a physical column type.
getCommandBuilder()
getDbConnection()
getEventHandlers()Returns the list of attached event handlers for an event.
getTable()Obtains the metadata for the named table.
getTableNames()Returns all table names in the database.
getTables()Returns the metadata for all tables in the database.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
insertAll()
orderByColumnValues()Returns the SQL for ordering results by column values.
quoteColumnName()Quotes a column name for use in a query.
quoteDatabaseName()Quotes a database name for use in a query.
quoteSimpleColumnName()Quotes a simple column name for use in a query.
quoteSimpleTableName()Quotes a simple table name for use in a query.
quoteTableName()Quotes a table name for use in a query.
raiseEvent()Raises an event.
refresh()Refreshes the schema.
renameColumn()Builds a SQL statement for renaming a column.
renameTable()Builds a SQL statement for renaming a DB table.
replace()Returns the SQL for finding/replacing text.
resetSequence()Resets the sequence value of a table's primary key.
truncateTable()Builds a SQL statement for truncating a DB table.

__construct()

Constructor.

View source

Arguments

Signature

public void __construct ( $conn )

addColumnAfter()

View source

Arguments

  • $table
  • $column
  • $type
  • $after

Returns

string

Signature

public string addColumnAfter ( $table, $column, $type, $after )

addColumnBefore()

View source

Arguments

  • $table
  • $column
  • $type
  • $before

Returns

string

Signature

public string addColumnBefore ( $table, $column, $type, $before )

addColumnFirst()

View source

Arguments

  • $table
  • $column
  • $type

Returns

string

Signature

public string addColumnFirst ( $table, $column, $type )

alterColumn()

View source

Arguments

Returns

string

Signature

public string alterColumn ( $table, $column, $type, $newName = null, $after = null )

createTable()

View source

Arguments

  • $table (string) – The name of the table (including prefix, or wrapped in "{{" and "}}").
  • $columns (array) – An array of columns.
  • $options (string) – Any additional SQL to append to the end of the query.
  • $engine (string) – The engine the table should use ("InnoDb" or "MyISAM"). Default is "InnoDb".

Returns

string – The full SQL for creating a table.

Signature

public string createTable ( $table, $columns, $options = null, $engine = 'InnoDb' )

dropTableIfExists()

Builds a SQL statement for dropping a DB table if it exists.

View source

Arguments

Returns

string

Signature

public string dropTableIfExists ( $table )

insertAll()

View source

Arguments

  • $table
  • $columns
  • $rows

Returns

mixed

Signature

public mixed insertAll ( $table, $columns, $rows )

orderByColumnValues()

Returns the SQL for ordering results by column values.

View source

Arguments

Returns

string

Signature

public string orderByColumnValues ( $column, $values )

quoteDatabaseName()

Quotes a database name for use in a query.

View source

Arguments

  • $name

Returns

string

Signature

public string quoteDatabaseName ( $name )

replace()

Returns the SQL for finding/replacing text.

View source

Arguments

Returns

array

Signature

public array replace ( $table, $column, $find, $replace )

Protected Methods

MethodDescription
createColumn()Creates a table column.
createCommandBuilder()Creates a command builder for the database.
findColumns()Collects the table column metadata.
findConstraints()Collects the foreign key column details for the given table.
findTableNames()Returns all table names in the database which start with the tablePrefix.
getServerVersion()
loadTable()Loads the metadata for the specified table.
resolveTableNames()Generates various kinds of table names.

findTableNames()

Returns all table names in the database which start with the tablePrefix.

View source

Arguments

Returns

string

Signature

protected string findTableNames ( $schema = null )