JSchemaChangeitemmysql
Extends \JSchemaChangeitemChecks the database schema against one MySQL DDL query to see if it has been run.
This class is used to check the site's database to see if the DDL query has been run.
If not, it provides the ability to fix the database by re-running the DDL query.
The queries are parsed from the update files in the folder
administrator/components/com_admin/sql/updates/
This is an abstract class. We need to extend it for each database and add a buildCheckQuery() method that creates the query to check that a DDL query has been run.
| package |
CMS.Library |
|---|---|
| subpackage |
Schema |
| since |
2.5 |
Methods
__construct
Class constructor, overridden in descendant classes.
__construct(mixed $properties = null)
| since |
11.1 |
|---|
Arguments
- $properties
mixedEither and associative array or another object to set the initial properties of the object.
__toString
Magic method to convert the object to a string gracefully.
__toString() : string
| since |
11.1 |
|---|---|
| deprecated |
12.3 Classes should provide their own __toString() implementation. |
Response
stringThe classname.
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
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 If yes, return true, otherwise return false
check() : boolean
| since |
2.5 |
|---|
Response
booleantrue on success, false otherwise
def
Sets a default value if not alreay assigned
def(string $property, mixed $default = null) : mixed
| since |
11.1 |
|---|
Arguments
- $property
stringThe name of the property.- $default
mixedThe default value.
Response
mixed
fix
Runs the update query to apply the change to the database
fix()
| since |
2.5 |
|---|
fixInteger
Fix up integer. Fixes problem with MySQL integer descriptions.
fixInteger(string $type1, string $type2) : string
If you change a column to "integer unsigned" it shows as "int(10) unsigned" in the check query.
| 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 semi-colon. Injects the database prefix.
| since |
2.5 |
|---|
Arguments
- $string
stringThe input string to be cleaned up.
Response
stringThe modified string.
get
Returns a property of the object or the default value if the property is not set.
get(string $property, mixed $default = null) : mixed
| since |
11.1 |
|---|---|
| see | \JObject::getProperties() |
Arguments
- $property
stringThe name of the property.- $default
mixedThe default value.
Response
mixedThe value of the property.
getError
Get the most recent error message.
getError(integer $i = null, boolean $toString = true) : string
| since |
11.1 |
|---|---|
| see | \JError |
| deprecated |
12.3 JError has been deprecated |
Arguments
- $i
integerOption error index.- $toString
booleanIndicates if JError objects should return their error message.
Response
stringError message
getErrors
Return all errors, if any.
getErrors() : array
| since |
11.1 |
|---|---|
| see | \JError |
| deprecated |
12.3 JError has been deprecated |
Response
arrayArray of error messages or JErrors.
getInstance
Returns an instance of the correct schemachangeitem for the $db
getInstance(\JDatabase $db, string $file, string $query) : \JSchemaChangeItem
| since |
2.5 |
|---|
Arguments
- $db
- $file
stringfull path name of the sql file- $query
stringtext of the sql query (one line of the file)
Response
\JSchemaChangeItemfor the $db driver
getProperties
Returns an associative array of object properties.
getProperties(boolean $public = true) : array
| since |
11.1 |
|---|---|
| see | \JObject::get() |
Arguments
- $public
booleanIf true, returns only the public properties.
Response
array
set
Modifies a property of the object, creating it if it does not already exist.
set(string $property, mixed $value = null) : mixed
| since |
11.1 |
|---|
Arguments
- $property
stringThe name of the property.- $value
mixedThe value of the property to set.
Response
mixedPrevious value of the property.
setError
Add an error message.
setError(string $error) : void
| since |
11.1 |
|---|---|
| see | \JError |
| deprecated |
12.3 JError has been deprecated |
Arguments
- $error
stringError message.
setProperties
Set the object properties based on a named array/hash.
setProperties(mixed $properties) : boolean
| since |
11.1 |
|---|---|
| see | \JObject::set() |
Arguments
- $properties
mixedEither an associative array or another object.
Response
boolean
toString
Converts the object to a string (the class name).
toString() : string
Properties
file
Update file: full path file name where query was found
Type(s)
string
updateQuery
Update query: query used to change the db schema (one line from the file)
Type(s)
string
checkQuery
Check query: query used to check the db schema
Type(s)
string
checkQueryExpected
Check query result: expected result of check query if database is up to date
Type(s)
string
db
JDatabase object
Type(s)
string
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
Type(s)
string
msgElements
Array with values for use in a JText::sprintf statment indicating what was checked
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
Type(s)
array
checkStatus
Checked status
Type(s)
integer
rerunStatus
Rerun status
Type(s)
integer
_errors
An array of error messages or Exception objects.