MediaWiki master
MySQLPlatform.php
Go to the documentation of this file.
1<?php
7
10
17 protected function getIdentifierQuoteChar() {
18 return '`';
19 }
20
22 public function buildStringCast( $field ) {
23 return "CAST( $field AS BINARY )";
24 }
25
30 public function buildIntegerCast( $field ) {
31 return 'CAST( ' . $field . ' AS SIGNED )';
32 }
33
35 protected function normalizeJoinType( string $joinType ) {
36 switch ( strtoupper( $joinType ) ) {
37 case 'STRAIGHT_JOIN':
38 case 'STRAIGHT JOIN':
39 return 'STRAIGHT_JOIN';
40
41 default:
42 return parent::normalizeJoinType( $joinType );
43 }
44 }
45
50 public function useIndexClause( $index ) {
51 return "FORCE INDEX (" . $index . ")";
52 }
53
58 public function ignoreIndexClause( $index ) {
59 return "IGNORE INDEX (" . $index . ")";
60 }
61
63 public function deleteJoinSqlText( $delTable, $joinTable, $delVar, $joinVar, $conds ) {
64 if ( !$conds ) {
65 throw new DBLanguageError( __METHOD__ . ' called with empty $conds' );
66 }
67
68 $delTable = $this->tableName( $delTable );
69 $joinTable = $this->tableName( $joinTable );
70 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
71
72 if ( $conds != '*' ) {
73 $sql .= ' AND ' . $this->makeList( $conds, self::LIST_AND );
74 }
75
76 return $sql;
77 }
78
80 public function isTransactableQuery( Query $sql ) {
81 return parent::isTransactableQuery( $sql ) &&
82 // TODO: Use query verb
83 !preg_match( '/^SELECT\s+(GET|RELEASE|IS_FREE)_LOCK\‍(/', $sql->getSQL() );
84 }
85
87 public function buildExcludedValue( $column ) {
88 /* @see DatabaseMySQL::upsert() */
89 // Within "INSERT INTO ON DUPLICATE KEY UPDATE" statements:
90 // - MySQL>= 8.0.20 supports and prefers "VALUES ... AS".
91 // - MariaDB >= 10.3.3 supports and prefers VALUE().
92 // - Both support the old VALUES() function
93 // https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html
94 // https://mariadb.com/kb/en/insert-on-duplicate-key-update/
95 return "VALUES($column)";
96 }
97
99 public function lockSQLText( $lockName, $timeout ) {
100 $encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) );
101 // Unlike NOW(), SYSDATE() gets the time at invocation rather than query start.
102 // The precision argument is silently ignored for MySQL < 5.6 and MariaDB < 5.3.
103 // https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_sysdate
104 // https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
105 return "SELECT IF(GET_LOCK($encName,$timeout),UNIX_TIMESTAMP(SYSDATE(6)),NULL) AS acquired";
106 }
107
109 public function lockIsFreeSQLText( $lockName ) {
110 $encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) );
111 return "SELECT IS_FREE_LOCK($encName) AS unlocked";
112 }
113
115 public function unlockSQLText( $lockName ) {
116 $encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) );
117 return "SELECT RELEASE_LOCK($encName) AS released";
118 }
119
121 public function makeLockName( $lockName ) {
122 // https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock
123 // MySQL 5.7+ enforces a 64 char length limit.
124 return ( strlen( $lockName ) > 64 ) ? sha1( $lockName ) : $lockName;
125 }
126}
getIdentifierQuoteChar()
Get the character used for identifier quoting.string
deleteJoinSqlText( $delTable, $joinTable, $delVar, $joinVar, $conds)
string
buildStringCast( $field)
string 1.28 in IDatabase, moved to ISQLPlatform in 1.39
lockSQLText( $lockName, $timeout)
string
normalizeJoinType(string $joinType)
Validate and normalize a join type.Subclasses may override this to add supported join types....
isTransactableQuery(Query $sql)
Determine whether a SQL statement is sensitive to isolation level.A SQL statement is considered trans...
tableName(string $name, $format='quoted')
Format a table name ready for use in constructing an SQL query.This does two important things: it quo...
makeList(array $a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.These can be used to make conjunctions or disjunctions...
Holds information on Query to be executed.
Definition Query.php:17