MysqlChangeItem

Extends ChangeItem

Checks the database schema against one MySQL DDL query to see if it has been run.

since

2.5

package

Application

Methods

__construct

Constructor: builds check query and message from $updateQuery

__construct(\Joomla\Database\DatabaseDriver db, string file, string query) : mixed
inherited
since

2.5

Arguments

db

\Joomla\Database\DatabaseDriverDatabase connector object

file

stringFull path name of the sql file

query

stringText of the sql query (one line of the file)

Response

mixed

buildCheckQuery

Checks a DDL query to see if it is a known type If yes, build a check query to see if the DDL has been run on the database.

buildCheckQuery() : void
inherited abstract

If successful, the $msgElements, $queryType, $checkStatus and $checkQuery fields are populated. The $msgElements contains the text to create the user message. The $checkQuery contains the SQL query to check whether the schema change has been run against the current database. The $queryType contains the type of DDL query that was run (for example, CREATE_TABLE, ADD_COLUMN, CHANGE_COLUMN_TYPE, ADD_INDEX). The $checkStatus field is set to zero if the query is created

If not successful, $checkQuery is empty and , and $checkStatus is -1. For example, this will happen if the current line is a non-DDL statement.

since

2.5

check

Runs the check query and checks that 1 row is returned

check() : int
inherited
since

2.5

Response

int1 if success, -1 if skipped, -2 if check failed

checkDefault

Create query clause for column changes/modifications for DEFAULT attribute

checkDefault(array changesArray, string type) : string
since

3.8.6

Arguments

changesArray

arrayThe array of words after COLUMN name

type

stringThe type of the COLUMN

Response

stringThe query clause for DEFAULT check in the check query

checkNull

Create query clause for column changes/modifications for NULL attribute

checkNull(array changesArray) : string
since

3.8.6

Arguments

changesArray

arrayThe array of words after COLUMN name

Response

stringThe query clause for NULL check in the check query

fix

Runs the update query to apply the change to the database

fix() : void
inherited
since

2.5

fixInteger

Fix up integer. Fixes problem with MySQL integer descriptions.

fixInteger(string type1, string type2) : string

On MySQL 8 display length is not shown anymore. This means we have to match e.g. both "int(10) unsigned" and "int unsigned", or both "int(11)" and "int" and so on. The same applies to the other integer data types "tinyint", "smallint", "mediumint" and "bigint".

since

2.5

Arguments

type1

stringthe column type

type2

stringthe column attributes

Response

stringThe original or changed column type.

fixQuote

Fixes up a string for inclusion in a query.

fixQuote(string string) : string

Replaces name quote character with normal quote for literal. Drops trailing semicolon. Injects the database prefix.

since

2.5

Arguments

string

stringThe input string to be cleaned up.

Response

stringThe modified string.

fixUtf8mb4TypeChecks

Make check query for column changes/modifications tolerant for automatic type changes of text columns, e.g. from TEXT to MEDIUMTEXT, after conversion from utf8 to utf8mb4, and fix integer columns without display length for MySQL 8 (see also function "fixInteger" above).

fixUtf8mb4TypeChecks(string type) : string
since

3.5

Arguments

type

stringThe column type found in the update query

Response

stringThe condition for type check in the check query

getInstance

Returns a reference to the ChangeItem object.

getInstance(\Joomla\Database\DatabaseDriver db, string file, string query) : \Joomla\CMS\Schema\ChangeItem
inherited static
since

2.5

throws

\RuntimeExceptionif class for database driver not found

Arguments

db

\Joomla\Database\DatabaseDriverDatabase connector object

file

stringFull path name of the sql file

query

stringText of the sql query (one line of the file)

Response

\Joomla\CMS\Schema\ChangeIteminstance based on the database driver

Properties

file

Update file: full path file name where query was found

inherited
since

2.5

Type(s)

string

updateQuery

Update query: query used to change the db schema (one line from the file)

inherited
since

2.5

Type(s)

string

checkQuery

Check query: query used to check the db schema

inherited
since

2.5

Type(s)

string

checkQueryExpected

Check query result: expected result of check query if database is up to date

inherited
since

2.5

Type(s)

string

db

DatabaseDriver object

inherited
since

2.5

Type(s)

\Joomla\Database\DatabaseDriver

queryType

Query type: To be used in building a language key for a message to tell user what was checked / changed Possible values: ADD_TABLE, ADD_COLUMN, CHANGE_COLUMN_TYPE, ADD_INDEX

inherited
since

2.5

Type(s)

string

msgElements

Array with values for use in a Text::sprintf statement indicating what was checked

inherited

Tells you what the message should be, based on which elements are defined, as follows: For ADD_TABLE: table For ADD_COLUMN: table, column For CHANGE_COLUMN_TYPE: table, column, type For ADD_INDEX: table, index

since

2.5

Type(s)

array

checkStatus

Checked status

inherited
since

2.5

Type(s)

int

rerunStatus

Rerun status

inherited
since

2.5

Type(s)

int