Completed
Push — master ( 58d53e...73f4ae )
by Lukas
13:40
created

AdapterMySQL::getCharset()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Robin Appelman <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
26
namespace OC\DB;
27
28
class AdapterMySQL extends Adapter {
29
30
	/** @var string */
31
	protected $charset;
32
33
	/**
34
	 * @param string $tableName
35
	 */
36
	public function lockTable($tableName) {
37
		$this->conn->executeUpdate('LOCK TABLES `' .$tableName . '` WRITE');
0 ignored issues
show
Security introduced by
If $tableName can contain user-input, it is usually preferable to use a parameter placeholder like :paramName and pass the dynamic input as second argument array('param' => $tableName).

Instead of embedding dynamic parameters in SQL, Doctrine also allows you to pass them separately and insert a placeholder instead:

function findUser(Doctrine\DBAL\Connection $con, $email) {
    // Unsafe
    $con->executeQuery("SELECT * FROM users WHERE email = '".$email."'");

    // Safe
    $con->executeQuery(
        "SELECT * FROM users WHERE email = :email",
        array('email' => $email)
    );
}
Loading history...
38
	}
39
40
	public function unlockTable() {
41
		$this->conn->executeUpdate('UNLOCK TABLES');
42
	}
43
44
	public function fixupStatement($statement) {
45
		$statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCharset() . '_general_ci LIKE ', $statement);
46
		return $statement;
47
	}
48
49
	protected function getCharset() {
50
		if (!$this->charset) {
51
			$params = $this->conn->getParams();
52
			$this->charset = isset($params['charset']) ? $params['charset'] : 'utf8';
53
		}
54
55
		return $this->charset;
56
	}
57
}
58