| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace Wikimedia\Rdbms\Platform; |
| 21 |
|
| 22 |
use Wikimedia\Rdbms\DBLanguageError; |
| 23 |
use Wikimedia\Rdbms\Query; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
class MySQLPlatform extends SQLPlatform { |
| 30 |
protected function getIdentifierQuoteChar() { |
| 31 |
return '`'; |
| 32 |
} |
| 33 |
|
| 34 |
public function buildStringCast( $field ) { |
| 35 |
return "CAST( $field AS BINARY )"; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function buildIntegerCast( $field ) { |
| 43 |
return 'CAST( ' . $field . ' AS SIGNED )'; |
| 44 |
} |
| 45 |
|
| 46 |
protected function normalizeJoinType( string $joinType ) { |
| 47 |
switch ( strtoupper( $joinType ) ) { |
| 48 |
case 'STRAIGHT_JOIN': |
| 49 |
case 'STRAIGHT JOIN': |
| 50 |
return 'STRAIGHT_JOIN'; |
| 51 |
|
| 52 |
default: |
| 53 |
return parent::normalizeJoinType( $joinType ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function useIndexClause( $index ) { |
| 62 |
return "FORCE INDEX (" . $this->indexName( $index ) . ")"; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function ignoreIndexClause( $index ) { |
| 70 |
return "IGNORE INDEX (" . $this->indexName( $index ) . ")"; |
| 71 |
} |
| 72 |
|
| 73 |
public function deleteJoinSqlText( $delTable, $joinTable, $delVar, $joinVar, $conds ) { |
| 74 |
if ( !$conds ) { |
| 75 |
throw new DBLanguageError( __METHOD__ . ' called with empty $conds' ); |
| 76 |
} |
| 77 |
|
| 78 |
$delTable = $this->tableName( $delTable ); |
| 79 |
$joinTable = $this->tableName( $joinTable ); |
| 80 |
$sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar "; |
| 81 |
|
| 82 |
if ( $conds != '*' ) { |
| 83 |
$sql .= ' AND ' . $this->makeList( $conds, self::LIST_AND ); |
| 84 |
} |
| 85 |
|
| 86 |
return $sql; |
| 87 |
} |
| 88 |
|
| 89 |
public function isTransactableQuery( Query $sql ) { |
| 90 |
return parent::isTransactableQuery( $sql ) && |
| 91 |
|
| 92 |
!preg_match( '/^SELECT\s+(GET|RELEASE|IS_FREE)_LOCK\(/', $sql->getSQL() ); |
| 93 |
} |
| 94 |
|
| 95 |
public function buildExcludedValue( $column ) { |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
return "VALUES($column)"; |
| 104 |
} |
| 105 |
|
| 106 |
public function lockSQLText( $lockName, $timeout ) { |
| 107 |
$encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) ); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
return "SELECT IF(GET_LOCK($encName,$timeout),UNIX_TIMESTAMP(SYSDATE(6)),NULL) AS acquired"; |
| 113 |
} |
| 114 |
|
| 115 |
public function lockIsFreeSQLText( $lockName ) { |
| 116 |
$encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) ); |
| 117 |
return "SELECT IS_FREE_LOCK($encName) AS unlocked"; |
| 118 |
} |
| 119 |
|
| 120 |
public function unlockSQLText( $lockName ) { |
| 121 |
$encName = $this->quoter->addQuotes( $this->makeLockName( $lockName ) ); |
| 122 |
return "SELECT RELEASE_LOCK($encName) AS released"; |
| 123 |
} |
| 124 |
|
| 125 |
public function makeLockName( $lockName ) { |
| 126 |
|
| 127 |
|
| 128 |
return ( strlen( $lockName ) > 64 ) ? sha1( $lockName ) : $lockName; |
| 129 |
} |
| 130 |
} |