@@ -46,7 +46,7 @@ |
||
| 46 | 46 | foreach ($this->parameters as $key => $val) { |
| 47 | 47 | $arg = $this->getArgName($key); |
| 48 | 48 | $columnsNames[] = $this->escape($key); |
| 49 | - $columnsValues[] = ':' . $arg; |
|
| 49 | + $columnsValues[] = ':'.$arg; |
|
| 50 | 50 | } |
| 51 | 51 | return trim(sprintf( |
| 52 | 52 | 'INSERT INTO %s (%s) VALUES (%s)', |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function errorCode() |
| 60 | 60 | { |
| 61 | - return !empty($this->error) ? $this->error['code']: null; |
|
| 61 | + return !empty($this->error) ? $this->error['code'] : null; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | protected function returnFunction() |
| 206 | 206 | { |
| 207 | - return $this->isGroupOpen === true ? $this : $this->query; |
|
| 207 | + return $this->isGroupOpen === true ? $this : $this->query; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $sql .= ')'; |
| 263 | 263 | break; |
| 264 | 264 | |
| 265 | - case 'NULL': |
|
| 265 | + case 'NULL': |
|
| 266 | 266 | case 'NOT_NULL': |
| 267 | 267 | $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
| 268 | 268 | $sql .= $item['sql']; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | if (is_string($item['value']) && |
| 280 | 280 | strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
| 281 | 281 | substr($item['value'], 0, strlen(Patabase\Constants::COLUMN_LITERALL)) === |
| 282 | - Patabase\Constants::COLUMN_LITERALL) { |
|
| 282 | + Patabase\Constants::COLUMN_LITERALL) { |
|
| 283 | 283 | |
| 284 | 284 | $arg = substr($item['value'], strlen(Patabase\Constants::COLUMN_LITERALL)); |
| 285 | 285 | $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
@@ -285,7 +285,7 @@ |
||
| 285 | 285 | $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
| 286 | 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 | 291 | $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function getArgumentName(string $column): string |
| 114 | 114 | { |
| 115 | - $arg = ':__' . str_replace('.', '_', $column); |
|
| 116 | - return $this->topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg; |
|
| 115 | + $arg = ':__'.str_replace('.', '_', $column); |
|
| 116 | + return $this->topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | // define argument for each values |
| 217 | 217 | $valueArgs = array(); |
| 218 | - foreach($item['value'] as $value){ |
|
| 218 | + foreach ($item['value'] as $value) { |
|
| 219 | 219 | $arg = $this->getArgumentName($item['column']); |
| 220 | 220 | $valueArgs[] = $arg; |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | //build and return sql |
| 227 | - return $item['sql']. '(' . implode(', ', $valueArgs) .')'; |
|
| 227 | + return $item['sql'].'('.implode(', ', $valueArgs).')'; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,20 +237,20 @@ discard block |
||
| 237 | 237 | { |
| 238 | 238 | $sql = ''; |
| 239 | 239 | if (!empty($this->conditions)) { |
| 240 | - $sql = ' '. $this->sqlBase .' '; // start the SQL WHERE or HAVING clause |
|
| 241 | - $currentOperator = 'AND'; // current condition operator |
|
| 240 | + $sql = ' '.$this->sqlBase.' '; // start the SQL WHERE or HAVING clause |
|
| 241 | + $currentOperator = 'AND'; // current condition operator |
|
| 242 | 242 | |
| 243 | 243 | foreach ($this->conditions as $key => $item) { |
| 244 | 244 | |
| 245 | 245 | // need operator AND or OR, except for the first or if |
| 246 | 246 | // previous item is a begin group item |
| 247 | - $isSqlNeedOperator = $key > 0 && $this->conditions[$key -1]['type'] != 'group_start'; |
|
| 247 | + $isSqlNeedOperator = $key > 0 && $this->conditions[$key-1]['type'] != 'group_start'; |
|
| 248 | 248 | |
| 249 | 249 | switch ($item['type']) { |
| 250 | 250 | |
| 251 | 251 | case'group_start': |
| 252 | 252 | $currentOperator = $item['operator']; // register operator |
| 253 | - $sql .= '(' ; |
|
| 253 | + $sql .= '('; |
|
| 254 | 254 | break; |
| 255 | 255 | |
| 256 | 256 | case'group_end': |
@@ -260,32 +260,32 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | case 'NULL': |
| 262 | 262 | case 'NOT_NULL': |
| 263 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 264 | - $sql .= $item['sql']; |
|
| 263 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 264 | + $sql .= $item['sql']; |
|
| 265 | 265 | break; |
| 266 | 266 | |
| 267 | 267 | case 'IN': |
| 268 | 268 | case 'NOT_IN': |
| 269 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 270 | - $sql .= $this->getSqlInOrNotIn($item); |
|
| 269 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 270 | + $sql .= $this->getSqlInOrNotIn($item); |
|
| 271 | 271 | break; |
| 272 | 272 | |
| 273 | 273 | default: |
| 274 | 274 | // support for column literral |
| 275 | 275 | if (is_string($item['value']) && |
| 276 | - strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
| 276 | + strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
| 277 | 277 | substr($item['value'], 0, strlen(Patabase\Constants::COLUMN_LITERALL)) === |
| 278 | 278 | Patabase\Constants::COLUMN_LITERALL) { |
| 279 | 279 | |
| 280 | 280 | $arg = substr($item['value'], strlen(Patabase\Constants::COLUMN_LITERALL)); |
| 281 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 282 | - $sql .= $item['sql'] . $this->query->escape($arg); |
|
| 281 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 282 | + $sql .= $item['sql'].$this->query->escape($arg); |
|
| 283 | 283 | |
| 284 | - } else { |
|
| 284 | + } else { |
|
| 285 | 285 | // *normal* value |
| 286 | 286 | $arg = $this->getArgumentName($item['column']); |
| 287 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 288 | - $sql .= $item['sql'] . $arg; |
|
| 287 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
| 288 | + $sql .= $item['sql'].$arg; |
|
| 289 | 289 | |
| 290 | 290 | // set parameters |
| 291 | 291 | $this->topQuery->setSqlParameter($arg, $item['value']); |
@@ -143,9 +143,9 @@ |
||
| 143 | 143 | $sqlWhere = (isset($this->where)) ? $this->where->sql() : ''; |
| 144 | 144 | $sqlTableName = $this->escape($this->tableName); |
| 145 | 145 | return trim(sprintf('UPDATE %s SET %s %s', |
| 146 | - $sqlTableName, |
|
| 147 | - $this->sqlColumns(), |
|
| 148 | - $sqlWhere |
|
| 146 | + $sqlTableName, |
|
| 147 | + $this->sqlColumns(), |
|
| 148 | + $sqlWhere |
|
| 149 | 149 | )); |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | \ No newline at end of file |
@@ -58,15 +58,15 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | $columns = array(); |
| 60 | 60 | foreach ($this->parameters as $key => $val) { |
| 61 | - $arg = ':_' . str_replace('.', '_', $key); |
|
| 62 | - $columns[] = $this->escape($key) . ' =' .$arg; |
|
| 61 | + $arg = ':_'.str_replace('.', '_', $key); |
|
| 62 | + $columns[] = $this->escape($key).' ='.$arg; |
|
| 63 | 63 | $this->pdoParameters[$arg] = $val; |
| 64 | 64 | } |
| 65 | 65 | foreach ($this->incrementColumns as $key => $val) { |
| 66 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '+' .$val ; |
|
| 66 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'+'.$val; |
|
| 67 | 67 | } |
| 68 | 68 | foreach ($this->decrementColumns as $key => $val) { |
| 69 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '-' .$val ; |
|
| 69 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'-'.$val; |
|
| 70 | 70 | } |
| 71 | 71 | return implode(', ', $columns); |
| 72 | 72 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function where(): Where |
| 81 | 81 | { |
| 82 | - if (!isset($this->where)){ |
|
| 82 | + if (!isset($this->where)) { |
|
| 83 | 83 | $this->where = new Query\Where($this, $this->driver); |
| 84 | 84 | } |
| 85 | 85 | return $this->where; |
@@ -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 | |
@@ -97,7 +97,7 @@ |
||
| 97 | 97 | * @param string $tableName The name of the table |
| 98 | 98 | * |
| 99 | 99 | * @return bool True if the table has been dropped, otherwise false |
| 100 | - */ |
|
| 100 | + */ |
|
| 101 | 101 | public function dropTable(string $tableName): bool |
| 102 | 102 | { |
| 103 | 103 | $sql = trim(sprintf('DROP TABLE %s', $tableName)); |
@@ -261,7 +261,7 @@ |
||
| 261 | 261 | */ |
| 262 | 262 | public function beginTransaction(): void |
| 263 | 263 | { |
| 264 | - if (! $this->inTransaction()) { |
|
| 264 | + if (!$this->inTransaction()) { |
|
| 265 | 265 | $this->getConnection()->beginTransaction(); |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -131,8 +131,8 @@ |
||
| 131 | 131 | */ |
| 132 | 132 | public function escape(string $str): string |
| 133 | 133 | { |
| 134 | - $list = explode('.', $str); |
|
| 135 | - return implode('.', $this->escapeList($list)); |
|
| 134 | + $list = explode('.', $str); |
|
| 135 | + return implode('.', $this->escapeList($list)); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | // check for required attributes |
| 164 | 164 | foreach ($this->dsnAttributes as $attribute) { |
| 165 | - if (! array_key_exists($attribute, $settings)) { |
|
| 165 | + if (!array_key_exists($attribute, $settings)) { |
|
| 166 | 166 | throw new Exception\MissingArgException('This configuration parameter is missing: "'.$attribute.'"'); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // defaut output format |
| 171 | - if (array_key_exists('default_output_format', $settings)){ |
|
| 171 | + if (array_key_exists('default_output_format', $settings)) { |
|
| 172 | 172 | $format = $settings['default_output_format']; |
| 173 | - if (!in_array($format, $this->outputFormats)){ |
|
| 173 | + if (!in_array($format, $this->outputFormats)) { |
|
| 174 | 174 | throw new Exception\InvalidArgException('The default output format specified is invalid.'); |
| 175 | 175 | } |
| 176 | 176 | $this->defaultOutputFormat = $format; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $this->createConnection($settings); |
| 180 | 180 | $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 181 | - $this->hostname = array_key_exists('hostname',$settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
| 181 | + $this->hostname = array_key_exists('hostname', $settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
| 182 | 182 | $this->driverName = $settings['driver']; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function errorCode(): int |
| 214 | 214 | { |
| 215 | - return !empty($this->error) ? $this->error['code']: ''; |
|
| 215 | + return !empty($this->error) ? $this->error['code'] : ''; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | return $pdoStatement->execute($parameters); |
| 257 | 257 | } catch (\PDOException $e) { |
| 258 | 258 | // register error |
| 259 | - $this->error['code'] = (int)$e->getCode(); |
|
| 259 | + $this->error['code'] = (int) $e->getCode(); |
|
| 260 | 260 | $this->error['message'] = $e->getMessage(); |
| 261 | 261 | return false; |
| 262 | 262 | } |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function createConnection(array $settings): void |
| 100 | 100 | { |
| 101 | - $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
| 102 | - $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
| 103 | - $dsn = 'pgsql:host='.$settings['hostname'] .$port .$dbname ; |
|
| 101 | + $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
| 102 | + $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
| 103 | + $dsn = 'pgsql:host='.$settings['hostname'].$port.$dbname; |
|
| 104 | 104 | |
| 105 | 105 | $this->pdo = new \PDO( |
| 106 | 106 | $dsn, |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $sql = 'SELECT COUNT(*) FROM pg_database WHERE datname = :dbName'; |
| 224 | 224 | $query = $this->pdo->prepare($sql); |
| 225 | - $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
| 225 | + $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
| 226 | 226 | $query->execute(); |
| 227 | 227 | return (bool) $query->fetchColumn(); |
| 228 | 228 | } |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool True if the database has been created, otherwise false. |
| 239 | 239 | */ |
| 240 | - public function createDatabase(string $databaseName, ?string $owner= null, ?string $template = 'template0'): bool |
|
| 240 | + public function createDatabase(string $databaseName, ?string $owner = null, ?string $template = 'template0'): bool |
|
| 241 | 241 | { |
| 242 | 242 | $sql = trim(sprintf('CREATE DATABASE %s %s TEMPLATE %s', |
| 243 | 243 | $this->escape($databaseName), |
| 244 | - isset($owner) ? 'OWNER '. $this->escape($owner) : '', |
|
| 244 | + isset($owner) ? 'OWNER '.$this->escape($owner) : '', |
|
| 245 | 245 | $template |
| 246 | 246 | )); |
| 247 | 247 | return $this->prepareAndExecuteSql($sql); |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | { |
| 261 | 261 | $sql = trim(sprintf('CREATE USER %s PASSWORD %s', |
| 262 | 262 | $this->escape($userName), |
| 263 | - "'" . $userPassword ."'" |
|
| 263 | + "'".$userPassword."'" |
|
| 264 | 264 | )); |
| 265 | 265 | return $this->prepareAndExecuteSql($sql); |
| 266 | 266 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | public function dropUser(string $userName, bool $ifExists = false): bool |
| 278 | 278 | { |
| 279 | 279 | $sql = trim(sprintf('DROP USER %s %s', |
| 280 | - $ifExists === true ? 'IF EXISTS': '', |
|
| 280 | + $ifExists === true ? 'IF EXISTS' : '', |
|
| 281 | 281 | $this->escape($userName) |
| 282 | 282 | )); |
| 283 | 283 | return $this->prepareAndExecuteSql($sql); |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $rq->execute(); |
| 130 | 130 | // return string |
| 131 | 131 | return strval($rq->fetchColumn()); |
| 132 | - } |
|
| 133 | - catch (\PDOException $e) { |
|
| 132 | + } catch (\PDOException $e) { |
|
| 134 | 133 | return 0; |
| 135 | 134 | } |
| 136 | 135 | } |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function lastInsertedId(): string |
| 124 | 124 | { |
| 125 | - // Postgres does not set pdo->lastInsertedId |
|
| 126 | - // use sequence |
|
| 127 | - try { |
|
| 125 | + // Postgres does not set pdo->lastInsertedId |
|
| 126 | + // use sequence |
|
| 127 | + try { |
|
| 128 | 128 | $rq = $this->pdo->prepare('SELECT LASTVAL()'); |
| 129 | 129 | $rq->execute(); |
| 130 | 130 | // return string |
@@ -158,7 +158,6 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * Get whether foreign keys are enabled or not |
| 160 | 160 | * For compatibility with Sqlite, not implemented in that driver (allways enabled), return true |
| 161 | - |
|
| 162 | 161 | * @access public |
| 163 | 162 | * @return bool true if foreign keys are enabled, otherwise false |
| 164 | 163 | */ |
@@ -182,11 +181,11 @@ discard block |
||
| 182 | 181 | public function addForeignKey(string $fkName, string $srcTable, string $srcColumn, string $refTable, string $refColumn): bool |
| 183 | 182 | { |
| 184 | 183 | $sql = sprintf('ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)', |
| 185 | - $this->escape($srcTable), |
|
| 186 | - $fkName, |
|
| 187 | - $this->escape($srcColumn), |
|
| 188 | - $this->escape($refTable), |
|
| 189 | - $this->escape($refColumn) |
|
| 184 | + $this->escape($srcTable), |
|
| 185 | + $fkName, |
|
| 186 | + $this->escape($srcColumn), |
|
| 187 | + $this->escape($refTable), |
|
| 188 | + $this->escape($refColumn) |
|
| 190 | 189 | ); |
| 191 | 190 | return $this->prepareAndExecuteSql($sql); |
| 192 | 191 | } |
@@ -203,9 +202,9 @@ discard block |
||
| 203 | 202 | public function dropForeignKey(string $fkName, string $tableName, bool $ifExists = false): bool |
| 204 | 203 | { |
| 205 | 204 | $sql = sprintf('ALTER TABLE %s DROP CONSTRAINT %s %s', |
| 206 | - $this->escape($tableName), |
|
| 207 | - $ifExists ? 'IF EXISTS' : '', |
|
| 208 | - $fkName |
|
| 205 | + $this->escape($tableName), |
|
| 206 | + $ifExists ? 'IF EXISTS' : '', |
|
| 207 | + $fkName |
|
| 209 | 208 | ); |
| 210 | 209 | return $this->prepareAndExecuteSql($sql); |
| 211 | 210 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | public function __construct(array $settings, bool $isServerConnection = false) |
| 38 | 38 | { |
| 39 | 39 | // remove database attribute for server connection |
| 40 | - if ($isServerConnection){ |
|
| 40 | + if ($isServerConnection) { |
|
| 41 | 41 | $dbKey = array_search('database', $this->dsnAttributes); |
| 42 | 42 | if ($dbKey !== false) { |
| 43 | 43 | unset($this->dsnAttributes[$dbKey]); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return bool True if the database has been created, otherwise false. |
| 68 | 68 | */ |
| 69 | - abstract public function createDatabase(string $databaseName, ?string $owner= null, ?string $template = null): bool; |
|
| 69 | + abstract public function createDatabase(string $databaseName, ?string $owner = null, ?string $template = null): bool; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Create a user |