@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function getArgumentName($column) |
118 | 118 | { |
119 | - $arg = ':__' . str_replace('.', '_', $column); |
|
120 | - return $this->topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg; |
|
119 | + $arg = ':__'.str_replace('.', '_', $column); |
|
120 | + return $this->topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | { |
220 | 220 | // define argument for each values |
221 | 221 | $valueArgs = array(); |
222 | - foreach($item['value'] as $value){ |
|
222 | + foreach ($item['value'] as $value) { |
|
223 | 223 | $arg = $this->getArgumentName($item['column']); |
224 | 224 | $valueArgs[] = $arg; |
225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | //build and return sql |
231 | - return $item['sql']. '(' . implode(', ', $valueArgs) .')'; |
|
231 | + return $item['sql'].'('.implode(', ', $valueArgs).')'; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | { |
242 | 242 | $sql = ''; |
243 | 243 | if (!empty($this->conditions)) { |
244 | - $sql = ' '. $this->sqlBase .' '; // start the SQL WHERE or HAVING clause |
|
245 | - $currentOperator = 'AND'; // current condition operator |
|
244 | + $sql = ' '.$this->sqlBase.' '; // start the SQL WHERE or HAVING clause |
|
245 | + $currentOperator = 'AND'; // current condition operator |
|
246 | 246 | |
247 | 247 | foreach ($this->conditions as $key => $item) { |
248 | 248 | |
249 | 249 | // need operator AND or OR, except for the first or if |
250 | 250 | // previous item is a begin group item |
251 | - $isSqlNeedOperator = $key > 0 && $this->conditions[$key -1]['type'] != 'group_start'; |
|
251 | + $isSqlNeedOperator = $key > 0 && $this->conditions[$key-1]['type'] != 'group_start'; |
|
252 | 252 | |
253 | 253 | switch ($item['type']) { |
254 | 254 | |
255 | 255 | case'group_start': |
256 | 256 | $currentOperator = $item['operator']; // register operator |
257 | - $sql .= '(' ; |
|
257 | + $sql .= '('; |
|
258 | 258 | break; |
259 | 259 | |
260 | 260 | case'group_end': |
@@ -264,32 +264,32 @@ discard block |
||
264 | 264 | |
265 | 265 | case 'NULL': |
266 | 266 | case 'NOT_NULL': |
267 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
268 | - $sql .= $item['sql']; |
|
267 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
268 | + $sql .= $item['sql']; |
|
269 | 269 | break; |
270 | 270 | |
271 | 271 | case 'IN': |
272 | 272 | case 'NOT_IN': |
273 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
274 | - $sql .= $this->getSqlInOrNotIn($item); |
|
273 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
274 | + $sql .= $this->getSqlInOrNotIn($item); |
|
275 | 275 | break; |
276 | 276 | |
277 | 277 | default: |
278 | 278 | // support for column literral |
279 | 279 | if (is_string($item['value']) && |
280 | - strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
280 | + strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
281 | 281 | substr($item['value'], 0, strlen(Patabase\Constants::COLUMN_LITERALL)) === |
282 | 282 | Patabase\Constants::COLUMN_LITERALL) { |
283 | 283 | |
284 | 284 | $arg = substr($item['value'], strlen(Patabase\Constants::COLUMN_LITERALL)); |
285 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
286 | - $sql .= $item['sql'] . $this->query->escape($arg); |
|
285 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
286 | + $sql .= $item['sql'].$this->query->escape($arg); |
|
287 | 287 | |
288 | - } else { |
|
288 | + } else { |
|
289 | 289 | // *normal* value |
290 | 290 | $arg = $this->getArgumentName($item['column']); |
291 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
292 | - $sql .= $item['sql'] . $arg; |
|
291 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
292 | + $sql .= $item['sql'].$arg; |
|
293 | 293 | |
294 | 294 | // set parameters |
295 | 295 | $this->topQuery->setSqlParameter($arg, $item['value']); |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | { |
64 | 64 | $columns = array(); |
65 | 65 | foreach ($this->parameters as $key => $val) { |
66 | - $arg = ':_' . str_replace('.', '_', $key); |
|
67 | - $columns[] = $this->escape($key) . ' =' .$arg; |
|
66 | + $arg = ':_'.str_replace('.', '_', $key); |
|
67 | + $columns[] = $this->escape($key).' ='.$arg; |
|
68 | 68 | $this->pdoParameters[$arg] = $val; |
69 | 69 | } |
70 | 70 | foreach ($this->incrementColumns as $key => $val) { |
71 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '+' .$val ; |
|
71 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'+'.$val; |
|
72 | 72 | } |
73 | 73 | foreach ($this->decrementColumns as $key => $val) { |
74 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '-' .$val ; |
|
74 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'-'.$val; |
|
75 | 75 | } |
76 | 76 | return implode(', ', $columns); |
77 | 77 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function where() |
86 | 86 | { |
87 | - if (!isset($this->where)){ |
|
87 | + if (!isset($this->where)) { |
|
88 | 88 | $this->where = new Query\Where($this, $this->driver); |
89 | 89 | } |
90 | 90 | return $this->where; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @access protected |
44 | 44 | * @var array $settings The driver settings |
45 | 45 | */ |
46 | - protected $settings= null; |
|
46 | + protected $settings = null; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Open a PDO connection |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function closeConnection() |
151 | 151 | { |
152 | - if ($this->driver){ |
|
152 | + if ($this->driver) { |
|
153 | 153 | $this->driver->closeConnection(); |
154 | 154 | $this->driver = null; |
155 | 155 | } |
@@ -257,7 +257,7 @@ |
||
257 | 257 | */ |
258 | 258 | public function beginTransaction() |
259 | 259 | { |
260 | - if (! $this->inTransaction()) { |
|
260 | + if (!$this->inTransaction()) { |
|
261 | 261 | $this->getConnection()->beginTransaction(); |
262 | 262 | } |
263 | 263 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function createConnection(array $settings) |
102 | 102 | { |
103 | - $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
104 | - $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
105 | - $dsn = 'pgsql:host='.$settings['hostname'] .$port .$dbname ; |
|
103 | + $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
104 | + $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
105 | + $dsn = 'pgsql:host='.$settings['hostname'].$port.$dbname; |
|
106 | 106 | |
107 | 107 | $this->pdo = new \PDO( |
108 | 108 | $dsn, |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | $sql = 'SELECT COUNT(*) FROM pg_database WHERE datname = :dbName'; |
210 | 210 | $query = $this->pdo->prepare($sql); |
211 | - $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
211 | + $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
212 | 212 | $query->execute(); |
213 | 213 | return (bool) $query->fetchColumn(); |
214 | 214 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | $sql = trim(sprintf('CREATE DATABASE %s %s TEMPLATE %s', |
229 | 229 | $this->escape($databaseName), |
230 | - isset($owner) ? 'OWNER '. $this->escape($owner) : '', |
|
230 | + isset($owner) ? 'OWNER '.$this->escape($owner) : '', |
|
231 | 231 | $template |
232 | 232 | )); |
233 | 233 | return $this->prepareAndExecuteSql($sql); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | $sql = trim(sprintf('CREATE USER %s PASSWORD %s', |
248 | 248 | $this->escape($userName), |
249 | - "'" . $userPassword ."'" |
|
249 | + "'".$userPassword."'" |
|
250 | 250 | )); |
251 | 251 | return $this->prepareAndExecuteSql($sql); |
252 | 252 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | public function dropUser($userName, $ifExists = false) |
264 | 264 | { |
265 | 265 | $sql = trim(sprintf('DROP USER %s %s', |
266 | - $ifExists === true ? 'IF EXISTS': '', |
|
266 | + $ifExists === true ? 'IF EXISTS' : '', |
|
267 | 267 | $this->escape($userName) |
268 | 268 | )); |
269 | 269 | return $this->prepareAndExecuteSql($sql); |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | { |
165 | 165 | // check for required attributes |
166 | 166 | foreach ($this->dsnAttributes as $attribute) { |
167 | - if (! array_key_exists($attribute, $settings)) { |
|
167 | + if (!array_key_exists($attribute, $settings)) { |
|
168 | 168 | throw new Exception\MissingArgException('This configuration parameter is missing: "'.$attribute.'"'); |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | // defaut output format |
173 | - if (array_key_exists('default_output_format', $settings)){ |
|
173 | + if (array_key_exists('default_output_format', $settings)) { |
|
174 | 174 | $format = $settings['default_output_format']; |
175 | - if (!in_array($format, $this->outputFormats)){ |
|
175 | + if (!in_array($format, $this->outputFormats)) { |
|
176 | 176 | throw new Exception\InvalidArgException('The default output format specified is invalid.'); |
177 | 177 | } |
178 | 178 | $this->defaultOutputFormat = $format; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | $this->createConnection($settings); |
182 | 182 | $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
183 | - $this->hostname = array_key_exists('hostname',$settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
183 | + $this->hostname = array_key_exists('hostname', $settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
184 | 184 | $this->driverName = $settings['driver']; |
185 | 185 | } |
186 | 186 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function errorCode() |
216 | 216 | { |
217 | - return !empty($this->error) ? $this->error['code']: ''; |
|
217 | + return !empty($this->error) ? $this->error['code'] : ''; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | return $pdoStatement->execute($parameters); |
259 | 259 | } catch (\PDOException $e) { |
260 | 260 | // register error |
261 | - $this->error['code'] = (int)$e->getCode(); |
|
261 | + $this->error['code'] = (int) $e->getCode(); |
|
262 | 262 | $this->error['message'] = $e->getMessage(); |
263 | 263 | return false; |
264 | 264 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | public function __construct(array $settings, $isServerConnection = false) |
42 | 42 | { |
43 | 43 | // remove database attribute for server connection |
44 | - if ($isServerConnection){ |
|
44 | + if ($isServerConnection) { |
|
45 | 45 | $dbKey = array_search('database', $this->dsnAttributes); |
46 | 46 | if ($dbKey !== false) { |
47 | 47 | unset($this->dsnAttributes[$dbKey]); |
@@ -41,7 +41,7 @@ |
||
41 | 41 | */ |
42 | 42 | public static function getInstance(array $settings, $isServerConnection = false) |
43 | 43 | { |
44 | - if (! isset($settings['driver'])) { |
|
44 | + if (!isset($settings['driver'])) { |
|
45 | 45 | throw new Exception\MissingArgException('You must define a driver'); |
46 | 46 | } |
47 | 47 |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function __construct( $driver) |
|
141 | + public function __construct($driver) |
|
142 | 142 | { |
143 | 143 | $this->driver = $driver; |
144 | 144 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | } |
203 | 203 | |
204 | 204 | // register error |
205 | - $this->error['code'] = (int)$e->getCode(); |
|
205 | + $this->error['code'] = (int) $e->getCode(); |
|
206 | 206 | $this->error['message'] = $e->getMessage(); |
207 | 207 | return false; |
208 | 208 | } |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | $paramType = \PDO::PARAM_STR; // default |
227 | 227 | |
228 | 228 | if (!isset($val)) { |
229 | - $paramType = \PDO::PARAM_NULL; |
|
229 | + $paramType = \PDO::PARAM_NULL; |
|
230 | 230 | |
231 | 231 | } elseif (is_int($val)) { |
232 | - $paramType = \PDO::PARAM_INT; |
|
232 | + $paramType = \PDO::PARAM_INT; |
|
233 | 233 | |
234 | 234 | } elseif (is_bool($val)) { |
235 | - $paramType = \PDO::PARAM_BOOL; |
|
235 | + $paramType = \PDO::PARAM_BOOL; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | // bind value |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | { |
252 | 252 | try { |
253 | 253 | // prepare bind execute |
254 | - if (!isset($this->pdoStatement)){ |
|
255 | - if (!$this->prepare()){ |
|
254 | + if (!isset($this->pdoStatement)) { |
|
255 | + if (!$this->prepare()) { |
|
256 | 256 | return false; |
257 | 257 | } |
258 | 258 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | // register error |
270 | - $this->error['code'] = (int)$e->getCode(); |
|
270 | + $this->error['code'] = (int) $e->getCode(); |
|
271 | 271 | $this->error['message'] = $e->getMessage(); |
272 | 272 | return false; |
273 | 273 | } |
@@ -297,23 +297,23 @@ discard block |
||
297 | 297 | */ |
298 | 298 | protected static function fetchOutput(QueryBuilder $query, $executed, $outputFormat) |
299 | 299 | { |
300 | - switch (strtoupper($outputFormat)){ |
|
300 | + switch (strtoupper($outputFormat)) { |
|
301 | 301 | |
302 | 302 | case Output::ASSOC: |
303 | - return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
303 | + return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
304 | 304 | |
305 | 305 | case Output::OBJ: |
306 | - return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_OBJ) : array(); |
|
306 | + return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_OBJ) : array(); |
|
307 | 307 | |
308 | 308 | case Output::COLUMN: |
309 | - return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) : array(); |
|
309 | + return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) : array(); |
|
310 | 310 | |
311 | 311 | case Output::JSON: |
312 | - $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
312 | + $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
313 | 313 | return json_encode($results, JSON_NUMERIC_CHECK); |
314 | 314 | |
315 | 315 | case Output::JSON_PRETTY_PRINT: |
316 | - $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
316 | + $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array(); |
|
317 | 317 | return json_encode($results, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK); |
318 | 318 | |
319 | 319 | default: |