@@ -14,9 +14,9 @@ |
||
14 | 14 | /** |
15 | 15 | * Thrown if an error occurs whilst executing a query. |
16 | 16 | */ |
17 | -class QueryException extends DatabaseException { |
|
17 | +class QueryException extends DatabaseException { |
|
18 | 18 | |
19 | - public function __construct( $message = 'An error occured executing a database query', $code = 0, \Exception $previous = null ) { |
|
19 | + public function __construct( $message = 'An error occured executing a database query', $code = 0, \Exception $previous = null ) { |
|
20 | 20 | parent::__construct($message, $code, $previous); |
21 | 21 | } |
22 | 22 |
@@ -56,7 +56,7 @@ |
||
56 | 56 | |
57 | 57 | if( $this->limit ) { |
58 | 58 | $sql[] = "LIMIT :limit"; |
59 | - $this->params['limit'] = $this->limit; |
|
59 | + $this->params['limit'] = $this->limit; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $sql; |
@@ -54,7 +54,7 @@ |
||
54 | 54 | |
55 | 55 | return array_merge( |
56 | 56 | [ |
57 | - "UPDATE {$this->table}", |
|
57 | + "update {$this->table}", |
|
58 | 58 | ], |
59 | 59 | $this->compileSet(), |
60 | 60 | $this->compileWhere(), |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $end++; |
76 | 76 | } |
77 | 77 | |
78 | - $sql[0] = 'SET '. $sql[0]; |
|
78 | + $sql[0] = 'SET '.$sql[0]; |
|
79 | 79 | $sql[$end] = trim($sql[$end], ','); |
80 | 80 | |
81 | 81 | return $sql; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | if( $this->limit ) { |
90 | 90 | $sql[] = "LIMIT :limit"; |
91 | - $this->params['limit'] = $this->limit; |
|
91 | + $this->params['limit'] = $this->limit; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $sql; |
@@ -390,7 +390,7 @@ |
||
390 | 390 | |
391 | 391 | $this->db->execute("UPDATE {$this->table_name} SET lft = ?, rgt = ? WHERE id = ?", array($lft, $rgt, $id)); |
392 | 392 | |
393 | - return $rgt + 1; |
|
393 | + return $rgt + 1; |
|
394 | 394 | |
395 | 395 | } |
396 | 396 |
@@ -108,8 +108,9 @@ |
||
108 | 108 | $child['rgt'] = (int) $child['rgt']; |
109 | 109 | |
110 | 110 | // if current left > right on top of stack we've gone down a level so pop the stack |
111 | - while( $stack && $child['lft'] > $stack[count($stack) - 1] ) |
|
112 | - array_pop($stack); |
|
111 | + while( $stack && $child['lft'] > $stack[count($stack) - 1] ) { |
|
112 | + array_pop($stack); |
|
113 | + } |
|
113 | 114 | |
114 | 115 | $child['depth'] = $offset + count($stack) + 1; |
115 | 116 |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | $parent = $this->findNodeById($parent_id); |
143 | 143 | |
144 | 144 | // shift everything up to make room for the new node |
145 | - $this->db->query("UPDATE {$this->table_name} SET rgt = rgt + 2 WHERE rgt >= ?", $parent['rgt']); |
|
146 | - $this->db->query("UPDATE {$this->table_name} SET lft = lft + 2 WHERE lft >= ?", $parent['rgt']); |
|
145 | + $this->db->query("update {$this->table_name} SET rgt = rgt + 2 WHERE rgt >= ?", $parent['rgt']); |
|
146 | + $this->db->query("update {$this->table_name} SET lft = lft + 2 WHERE lft >= ?", $parent['rgt']); |
|
147 | 147 | |
148 | 148 | // single query - http://www.slideshare.net/billkarwin/models-for-hierarchical-data (slide 36) |
149 | 149 | /*update table set |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | $this->db->execute( |
162 | - "UPDATE {$this->table_name} SET lft = ?, rgt = ? WHERE id = ?", |
|
162 | + "update {$this->table_name} SET lft = ?, rgt = ? WHERE id = ?", |
|
163 | 163 | array($parent['rgt'], $parent['rgt'] + 1, $id) |
164 | 164 | ); |
165 | 165 | |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | $diff = (int) $node['rgt'] - (int) $node['lft'] + 1; |
195 | 195 | |
196 | 196 | // remove the item from the tree by blanking the left and right indexes |
197 | - $this->db->execute("UPDATE {$this->table_name} SET lft = 0, rgt = 0 WHERE lft BETWEEN ? AND ?", array($node['lft'], $node['rgt'])); |
|
197 | + $this->db->execute("update {$this->table_name} SET lft = 0, rgt = 0 WHERE lft BETWEEN ? AND ?", array($node['lft'], $node['rgt'])); |
|
198 | 198 | |
199 | - $this->db->execute("UPDATE {$this->table_name} SET lft = lft - ? WHERE lft >= ?", array($diff, $node['lft'])); |
|
200 | - $this->db->execute("UPDATE {$this->table_name} SET rgt = rgt - ? WHERE rgt >= ?", array($diff, $node['rgt'])); |
|
199 | + $this->db->execute("update {$this->table_name} SET lft = lft - ? WHERE lft >= ?", array($diff, $node['lft'])); |
|
200 | + $this->db->execute("update {$this->table_name} SET rgt = rgt - ? WHERE rgt >= ?", array($diff, $node['rgt'])); |
|
201 | 201 | |
202 | 202 | if( !$transaction ) |
203 | 203 | $this->db->commit(); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | // remove the node and it's descendents from the tree whilst keeping it's structure, by converting the left and right values to negative numbers |
237 | 237 | $this->db->execute( |
238 | - "UPDATE {$this->table_name} SET lft = -(lft - :lft + 1), rgt = -(rgt -:lft + 1) WHERE lft >= :lft AND rgt <= :rgt", |
|
238 | + "update {$this->table_name} SET lft = -(lft - :lft + 1), rgt = -(rgt -:lft + 1) WHERE lft >= :lft AND rgt <= :rgt", |
|
239 | 239 | array( |
240 | 240 | 'lft' => $node['lft'], |
241 | 241 | 'rgt' => $node['rgt'] |
@@ -243,25 +243,25 @@ discard block |
||
243 | 243 | ); |
244 | 244 | |
245 | 245 | // collapse the gap we just created |
246 | - $this->db->execute("UPDATE {$this->table_name} SET lft = lft - ? WHERE lft > ?", array($diff, $node['lft'])); |
|
247 | - $this->db->execute("UPDATE {$this->table_name} SET rgt = rgt - ? WHERE rgt > ?", array($diff, $node['rgt'])); |
|
246 | + $this->db->execute("update {$this->table_name} SET lft = lft - ? WHERE lft > ?", array($diff, $node['lft'])); |
|
247 | + $this->db->execute("update {$this->table_name} SET rgt = rgt - ? WHERE rgt > ?", array($diff, $node['rgt'])); |
|
248 | 248 | |
249 | 249 | // refresh parent state |
250 | 250 | $parent = $this->findNodeById($parent_id); |
251 | 251 | |
252 | 252 | // create new gap |
253 | - $this->db->execute("UPDATE {$this->table_name} SET lft = lft + ? WHERE lft > ?", array($diff, $parent['rgt'])); |
|
254 | - $this->db->execute("UPDATE {$this->table_name} SET rgt = rgt + ? WHERE rgt >= ?", array($diff, $parent['rgt'])); |
|
253 | + $this->db->execute("update {$this->table_name} SET lft = lft + ? WHERE lft > ?", array($diff, $parent['rgt'])); |
|
254 | + $this->db->execute("update {$this->table_name} SET rgt = rgt + ? WHERE rgt >= ?", array($diff, $parent['rgt'])); |
|
255 | 255 | |
256 | 256 | // refresh parent state |
257 | 257 | $parent = $this->findNodeById($parent_id); |
258 | 258 | |
259 | 259 | // fill the gap with the original node, updating the left and right values |
260 | - $this->db->execute("UPDATE {$this->table_name} SET lft = ? - ? - lft - 1 WHERE lft < 0", array($parent['rgt'], $diff)); |
|
261 | - $this->db->execute("UPDATE {$this->table_name} SET rgt = ? - ? - rgt - 1 WHERE rgt < 0", array($parent['rgt'], $diff)); |
|
260 | + $this->db->execute("update {$this->table_name} SET lft = ? - ? - lft - 1 WHERE lft < 0", array($parent['rgt'], $diff)); |
|
261 | + $this->db->execute("update {$this->table_name} SET rgt = ? - ? - rgt - 1 WHERE rgt < 0", array($parent['rgt'], $diff)); |
|
262 | 262 | |
263 | 263 | // ensure the correct parent is assigned - may have already by done by calling function |
264 | - $this->db->execute("UPDATE {$this->table_name} SET parent_id = ? WHERE id = ?", array($parent_id, $id)); |
|
264 | + $this->db->execute("update {$this->table_name} SET parent_id = ? WHERE id = ?", array($parent_id, $id)); |
|
265 | 265 | |
266 | 266 | if( !$transaction ) |
267 | 267 | $this->db->commit(); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | |
363 | 363 | try { |
364 | 364 | $this->db->begin(); |
365 | - $this->db->execute("UPDATE {$this->table_name} SET lft = 0, rgt = 0"); |
|
365 | + $this->db->execute("update {$this->table_name} SET lft = 0, rgt = 0"); |
|
366 | 366 | $this->rebuildNode($sort, 0); |
367 | 367 | $this->db->commit(); |
368 | 368 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $rgt = $this->rebuildNode($sort, $child, $rgt); |
389 | 389 | } |
390 | 390 | |
391 | - $this->db->execute("UPDATE {$this->table_name} SET lft = ?, rgt = ? WHERE id = ?", array($lft, $rgt, $id)); |
|
391 | + $this->db->execute("update {$this->table_name} SET lft = ?, rgt = ? WHERE id = ?", array($lft, $rgt, $id)); |
|
392 | 392 | |
393 | 393 | return $rgt + 1; |
394 | 394 |
@@ -349,7 +349,7 @@ |
||
349 | 349 | $offset = (int) $offset['depth']; |
350 | 350 | |
351 | 351 | foreach( $data as $id => $item ) { |
352 | - $tree[$id] = str_repeat('|-- ', (int) $item['depth'] - $offset). $item['name']; |
|
352 | + $tree[$id] = str_repeat('|-- ', (int) $item['depth'] - $offset).$item['name']; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | ]; |
93 | 93 | |
94 | 94 | if( !isset($factories[$dsn->type]) ) |
95 | - throw new ConfigurationException('Invalid database type: '. $dsn->type); |
|
95 | + throw new ConfigurationException('Invalid database type: '.$dsn->type); |
|
96 | 96 | |
97 | 97 | $factory = $factories[$dsn->type]; |
98 | 98 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | elseif( is_array($dsn) ) |
114 | 114 | return new DSN($dsn); |
115 | 115 | else |
116 | - throw new ConfigurationException('Invalid DSN: '. $dsn); |
|
116 | + throw new ConfigurationException('Invalid DSN: '.$dsn); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | if( !$name ) |
153 | 153 | throw new DatabaseException('Managed database connections must have a name'); |
154 | 154 | if( $this->has($name) ) |
155 | - throw new DatabaseException('Connection already exists with name: '. $name); |
|
155 | + throw new DatabaseException('Connection already exists with name: '.$name); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | } |
@@ -85,8 +85,8 @@ |
||
85 | 85 | protected function compile() { |
86 | 86 | |
87 | 87 | $sql = [ |
88 | - ($this->ignore ? 'INSERT IGNORE' : 'INSERT'). ' '. $this->into, |
|
89 | - '('. implode(', ', $this->columns). ')', |
|
88 | + ($this->ignore ? 'INSERT IGNORE' : 'INSERT').' '.$this->into, |
|
89 | + '('.implode(', ', $this->columns).')', |
|
90 | 90 | 'VALUES', |
91 | 91 | ]; |
92 | 92 |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | |
117 | 117 | return array_merge( |
118 | 118 | [ |
119 | - ($this->distinct ? 'SELECT DISTINCT' : 'SELECT'). ' '. $cols, |
|
120 | - 'FROM '. $this->from, |
|
119 | + ($this->distinct ? 'SELECT DISTINCT' : 'SELECT').' '.$cols, |
|
120 | + 'FROM '.$this->from, |
|
121 | 121 | ], |
122 | 122 | $this->compileJoins(), |
123 | 123 | $this->compileWhere(), |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $sql = []; |
159 | 159 | |
160 | 160 | if( $this->group ) |
161 | - $sql[] = 'GROUP BY '. implode(', ', $this->group); |
|
161 | + $sql[] = 'GROUP BY '.implode(', ', $this->group); |
|
162 | 162 | |
163 | 163 | return $sql; |
164 | 164 |