@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Maphper\DataSource; |
3 | 3 | class StmtCache { |
4 | - private $pdo; |
|
5 | - private $queryCache = []; |
|
4 | + private $pdo; |
|
5 | + private $queryCache = []; |
|
6 | 6 | |
7 | - public function __construct(\PDO $pdo) { |
|
8 | - $this->pdo = $pdo; |
|
9 | - } |
|
7 | + public function __construct(\PDO $pdo) { |
|
8 | + $this->pdo = $pdo; |
|
9 | + } |
|
10 | 10 | |
11 | - public function getCachedStmt($sql) { |
|
11 | + public function getCachedStmt($sql) { |
|
12 | 12 | $queryId = $this->getQueryId($sql); |
13 | 13 | if (isset($this->queryCache[$queryId])) $stmt = $this->queryCache[$queryId]; |
14 | 14 | else { |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | return $stmt; |
19 | 19 | } |
20 | 20 | |
21 | - private function getQueryId($sql) { |
|
22 | - return md5($sql); |
|
23 | - } |
|
21 | + private function getQueryId($sql) { |
|
22 | + return md5($sql); |
|
23 | + } |
|
24 | 24 | |
25 | - public function deleteQueryFromCache($sql) { |
|
26 | - unset($this->queryCache[$this->getQueryId($sql)]); |
|
27 | - } |
|
25 | + public function deleteQueryFromCache($sql) { |
|
26 | + unset($this->queryCache[$this->getQueryId($sql)]); |
|
27 | + } |
|
28 | 28 | |
29 | - public function clearCache() { |
|
30 | - $this->queryCache = []; |
|
31 | - } |
|
29 | + public function clearCache() { |
|
30 | + $this->queryCache = []; |
|
31 | + } |
|
32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | private function tableExists($name) { |
47 | - $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="'. $name.'"'); |
|
47 | + $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="' . $name . '"'); |
|
48 | 48 | return count($result->fetchAll()) == 1; |
49 | 49 | } |
50 | 50 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | // SQLSTATE[HY000]: General error: 17 database schema has changed |
64 | 64 | $this->stmtCache->clearCache(); |
65 | 65 | |
66 | - $affix = '_'.substr(md5($table), 0, 6); |
|
66 | + $affix = '_' . substr(md5($table), 0, 6); |
|
67 | 67 | $this->createTable($table . $affix, $primaryKey, $data); |
68 | 68 | $fields = []; |
69 | 69 | foreach ($data as $key => $value) { $fields[] = $key; } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $columns = implode(', ', $this->getColumns($table)); |
73 | 73 | |
74 | 74 | $this->pdo->query('INSERT INTO ' . $this->quote($table . $affix) . '(' . $columns . ') SELECT ' . $columns . ' FROM ' . $this->quote($table)); |
75 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
75 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | catch (\PDOException $e) { |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | echo $e->getMessage(); |
81 | 81 | } |
82 | 82 | |
83 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
84 | - $this->pdo->query('ALTER TABLE ' . $table . $affix. ' RENAME TO '. $table ); |
|
83 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
84 | + $this->pdo->query('ALTER TABLE ' . $table . $affix . ' RENAME TO ' . $table); |
|
85 | 85 | |
86 | 86 | } |
87 | 87 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | $pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')'; |
97 | 97 | |
98 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
98 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
99 | 99 | $this->pdo->query('CREATE TABLE ' . $table . ' (' . $pkField . ')'); |
100 | 100 | |
101 | 101 | foreach ($data as $key => $value) { |