@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | $new = ''; |
| 13 | 13 | $par = array_values($par); |
| 14 | 14 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
| 15 | - $par = [ $par ]; |
|
| 15 | + $par = [$par]; |
|
| 16 | 16 | } |
| 17 | 17 | $parts = explode('??', $sql); |
| 18 | 18 | $index = 0; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | $index += count($tmp) - 1; |
| 23 | 23 | if (isset($par[$index])) { |
| 24 | 24 | if (!is_array($par[$index])) { |
| 25 | - $par[$index] = [ $par[$index] ]; |
|
| 25 | + $par[$index] = [$par[$index]]; |
|
| 26 | 26 | } |
| 27 | 27 | $params = $par[$index]; |
| 28 | 28 | array_splice($par, $index, 1, $params); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $new .= implode(',', array_fill(0, count($params), '?')); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | - return [ $new, $par ]; |
|
| 33 | + return [$new, $par]; |
|
| 34 | 34 | } |
| 35 | 35 | /** |
| 36 | 36 | * Run a query (prepare & execute). |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | $this->connect(); |
| 53 | 53 | $statement = \ibase_prepare($this->transaction !== null ? $this->transaction : $this->lnk, $sql); |
| 54 | 54 | if ($statement === false) { |
| 55 | - throw new DBException('Prepare error: ' . \ibase_errmsg()); |
|
| 55 | + throw new DBException('Prepare error: '.\ibase_errmsg()); |
|
| 56 | 56 | } |
| 57 | 57 | return new Statement( |
| 58 | 58 | $statement, |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | isset($this->connection['opts']) ? $this->connection['opts'] : [] |
| 45 | 45 | ); |
| 46 | 46 | } catch (\PDOException $e) { |
| 47 | - throw new DBException('Connect error: ' . $e->getMessage()); |
|
| 47 | + throw new DBException('Connect error: '.$e->getMessage()); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -24,28 +24,28 @@ |
||
| 24 | 24 | foreach ($data as $i => $v) { |
| 25 | 25 | switch (gettype($v)) { |
| 26 | 26 | case 'boolean': |
| 27 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_BOOL); |
|
| 27 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_BOOL); |
|
| 28 | 28 | break; |
| 29 | 29 | case 'integer': |
| 30 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_INT); |
|
| 30 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_INT); |
|
| 31 | 31 | break; |
| 32 | 32 | case 'NULL': |
| 33 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_NULL); |
|
| 33 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_NULL); |
|
| 34 | 34 | break; |
| 35 | 35 | case 'double': |
| 36 | - $this->statement->bindValue($i+1, $v); |
|
| 36 | + $this->statement->bindValue($i + 1, $v); |
|
| 37 | 37 | break; |
| 38 | 38 | default: |
| 39 | 39 | // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: |
| 40 | 40 | // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? |
| 41 | 41 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
| 42 | - $this->statement->bindParam($i+1, $v, \PDO::PARAM_LOB); |
|
| 42 | + $this->statement->bindParam($i + 1, $v, \PDO::PARAM_LOB); |
|
| 43 | 43 | break; |
| 44 | 44 | } |
| 45 | 45 | if (!is_string($data[$i])) { |
| 46 | 46 | $data[$i] = serialize($data[$i]); |
| 47 | 47 | } |
| 48 | - $this->statement->bindValue($i+1, $v); |
|
| 48 | + $this->statement->bindValue($i + 1, $v); |
|
| 49 | 49 | break; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | |
| 91 | 91 | public function begin() : bool |
| 92 | 92 | { |
| 93 | - return $this->transaction = true; |
|
| 93 | + return $this->transaction = true; |
|
| 94 | 94 | } |
| 95 | 95 | public function commit() : bool |
| 96 | 96 | { |
@@ -70,14 +70,14 @@ |
||
| 70 | 70 | if ($log) { |
| 71 | 71 | $tm = microtime(true); |
| 72 | 72 | } |
| 73 | - $res = \oci_execute(\oci_parse($this->lnk, $sql)?:throw new \Exception()); |
|
| 73 | + $res = \oci_execute(\oci_parse($this->lnk, $sql) ?: throw new \Exception()); |
|
| 74 | 74 | if ($log) { |
| 75 | 75 | $tm = microtime(true) - $tm; |
| 76 | - if ($tm >= (float)$this->option('log_slow', 0)) { |
|
| 76 | + if ($tm >= (float) $this->option('log_slow', 0)) { |
|
| 77 | 77 | @file_put_contents( |
| 78 | 78 | $log, |
| 79 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 80 | - $sql . "\r\n" . |
|
| 79 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 80 | + $sql."\r\n". |
|
| 81 | 81 | "\r\n", |
| 82 | 82 | FILE_APPEND |
| 83 | 83 | ); |
@@ -124,7 +124,7 @@ |
||
| 124 | 124 | } |
| 125 | 125 | return $new; |
| 126 | 126 | }) |
| 127 | - as $relation |
|
| 127 | + as $relation |
|
| 128 | 128 | ) { |
| 129 | 129 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
| 130 | 130 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | $columns = Collection::from($this |
| 30 | 30 | ->query( |
| 31 | 31 | "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ? and hidden_column = 'NO'", |
| 32 | - [ strtoupper($table), $this->name() ] |
|
| 32 | + [strtoupper($table), $this->name()] |
|
| 33 | 33 | )) |
| 34 | - ->map(function ($v) { |
|
| 34 | + ->map(function($v) { |
|
| 35 | 35 | $new = []; |
| 36 | 36 | foreach ($v as $kk => $vv) { |
| 37 | 37 | $new[strtoupper($kk)] = $vv; |
| 38 | 38 | } |
| 39 | 39 | return $new; |
| 40 | 40 | }) |
| 41 | - ->mapKey(function ($v) { |
|
| 41 | + ->mapKey(function($v) { |
|
| 42 | 42 | return $v['COLUMN_NAME']; |
| 43 | 43 | }) |
| 44 | - ->map(function ($v) { |
|
| 44 | + ->map(function($v) { |
|
| 45 | 45 | $v['length'] = null; |
| 46 | 46 | if (!isset($v['DATA_TYPE'])) { |
| 47 | 47 | return $v; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | default: |
| 54 | 54 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
| 55 | 55 | // extract length from varchar |
| 56 | - $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
| 56 | + $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
| 57 | 57 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
| 58 | 58 | } |
| 59 | 59 | break; |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | ->query( |
| 70 | 70 | "SELECT constraint_name FROM all_constraints |
| 71 | 71 | WHERE table_name = ? AND constraint_type = ? AND owner = ?", |
| 72 | - [ strtoupper($table), 'P', $owner ] |
|
| 72 | + [strtoupper($table), 'P', $owner] |
|
| 73 | 73 | )) |
| 74 | - ->map(function ($v) { |
|
| 74 | + ->map(function($v) { |
|
| 75 | 75 | $new = []; |
| 76 | 76 | foreach ($v as $kk => $vv) { |
| 77 | 77 | $new[strtoupper($kk)] = $vv; |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | ->query( |
| 87 | 87 | "SELECT column_name FROM all_cons_columns |
| 88 | 88 | WHERE table_name = ? AND constraint_name = ? AND owner = ?", |
| 89 | - [ strtoupper($table), $pkname, $owner ] |
|
| 89 | + [strtoupper($table), $pkname, $owner] |
|
| 90 | 90 | )) |
| 91 | - ->map(function ($v) { |
|
| 91 | + ->map(function($v) { |
|
| 92 | 92 | $new = []; |
| 93 | 93 | foreach ($v as $kk => $vv) { |
| 94 | 94 | $new[strtoupper($kk)] = $vv; |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
| 116 | 116 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 117 | 117 | ORDER BY cc.POSITION", |
| 118 | - [ $owner, $owner, $pkname, 'R' ] |
|
| 118 | + [$owner, $owner, $pkname, 'R'] |
|
| 119 | 119 | )) |
| 120 | - ->map(function ($v) { |
|
| 120 | + ->map(function($v) { |
|
| 121 | 121 | $new = []; |
| 122 | 122 | foreach ($v as $kk => $vv) { |
| 123 | 123 | $new[strtoupper($kk)] = $vv; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | as $relation |
| 128 | 128 | ) { |
| 129 | 129 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
| 130 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
| 130 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
| 131 | 131 | $relation['COLUMN_NAME']; |
| 132 | 132 | } |
| 133 | 133 | foreach ($relations as $data) { |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
| 158 | 158 | cc.COLUMN_NAME IN (??) |
| 159 | 159 | ORDER BY POSITION", |
| 160 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
| 160 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
| 161 | 161 | )) |
| 162 | - ->map(function ($v) { |
|
| 162 | + ->map(function($v) { |
|
| 163 | 163 | $new = []; |
| 164 | 164 | foreach ($v as $kk => $vv) { |
| 165 | 165 | $new[strtoupper($kk)] = $vv; |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | ->query( |
| 180 | 180 | "SELECT COLUMN_NAME FROM all_cons_columns |
| 181 | 181 | WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 182 | - [ $owner, current($foreign['keymap']) ] |
|
| 182 | + [$owner, current($foreign['keymap'])] |
|
| 183 | 183 | )) |
| 184 | - ->map(function ($v) { |
|
| 184 | + ->map(function($v) { |
|
| 185 | 185 | $new = []; |
| 186 | 186 | foreach ($v as $kk => $vv) { |
| 187 | 187 | $new[strtoupper($kk)] = $vv; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $relname = $foreign['table']; |
| 197 | 197 | $cntr = 1; |
| 198 | 198 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 199 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
| 199 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
| 200 | 200 | } |
| 201 | 201 | $definition->addRelation( |
| 202 | 202 | new TableRelation( |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $relname = $data['table']; |
| 213 | 213 | $cntr = 1; |
| 214 | 214 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 215 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
| 215 | + $relname = $data['table'].'_'.(++$cntr); |
|
| 216 | 216 | } |
| 217 | 217 | $definition->addRelation( |
| 218 | 218 | new TableRelation( |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
| 241 | 241 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 242 | 242 | ORDER BY cc.POSITION", |
| 243 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
| 243 | + [$owner, $owner, strtoupper($table), 'R'] |
|
| 244 | 244 | )) |
| 245 | - ->map(function ($v) { |
|
| 245 | + ->map(function($v) { |
|
| 246 | 246 | $new = []; |
| 247 | 247 | foreach ($v as $kk => $vv) { |
| 248 | 248 | $new[strtoupper($kk)] = $vv; |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | ->query( |
| 261 | 261 | "SELECT COLUMN_NAME FROM all_cons_columns |
| 262 | 262 | WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 263 | - [ $owner, current($data['keymap']) ] |
|
| 263 | + [$owner, current($data['keymap'])] |
|
| 264 | 264 | )) |
| 265 | - ->map(function ($v) { |
|
| 265 | + ->map(function($v) { |
|
| 266 | 266 | $new = []; |
| 267 | 267 | foreach ($v as $kk => $vv) { |
| 268 | 268 | $new[strtoupper($kk)] = $vv; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | $relname = $data['table']; |
| 278 | 278 | $cntr = 1; |
| 279 | 279 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 280 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
| 280 | + $relname = $data['table'].'_'.(++$cntr); |
|
| 281 | 281 | } |
| 282 | 282 | $definition->addRelation( |
| 283 | 283 | new TableRelation( |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?", |
| 299 | 299 | [$this->connection['name']] |
| 300 | 300 | )) |
| 301 | - ->map(function ($v) { |
|
| 301 | + ->map(function($v) { |
|
| 302 | 302 | $new = []; |
| 303 | 303 | foreach ($v as $kk => $vv) { |
| 304 | 304 | $new[strtoupper($kk)] = $vv; |
| 305 | 305 | } |
| 306 | 306 | return $new; |
| 307 | 307 | }) |
| 308 | - ->mapKey(function ($v) { |
|
| 308 | + ->mapKey(function($v) { |
|
| 309 | 309 | return $v['TABLE_NAME']; |
| 310 | 310 | }) |
| 311 | 311 | ->pluck('TABLE_NAME') |
| 312 | - ->map(function ($v) { |
|
| 312 | + ->map(function($v) { |
|
| 313 | 313 | return $this->table($v); |
| 314 | 314 | }) |
| 315 | 315 | ->toArray(); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $fields = []; |
| 77 | 77 | $exists = false; |
| 78 | 78 | foreach ($relation->table->getColumns() as $column) { |
| 79 | - $nm = $name . static::SEP . $column; |
|
| 79 | + $nm = $name.static::SEP.$column; |
|
| 80 | 80 | if (isset($this->aliases[$nm])) { |
| 81 | 81 | $nm = $this->aliases[$nm]; |
| 82 | 82 | } |
@@ -90,17 +90,17 @@ discard block |
||
| 90 | 90 | $parts = explode(static::SEP, $name); |
| 91 | 91 | $name = array_pop($parts); |
| 92 | 92 | if (!$exists && !count($parts) && !isset($temp[$name])) { |
| 93 | - $temp[$name] = $relation->many ? [ '___clean' => true ] : null; |
|
| 93 | + $temp[$name] = $relation->many ? ['___clean' => true] : null; |
|
| 94 | 94 | } |
| 95 | 95 | if ($exists) { |
| 96 | - $full = ''; |
|
| 96 | + $full = ''; |
|
| 97 | 97 | foreach ($parts as $item) { |
| 98 | - $full = $full ? $full . static::SEP . $item : $item; |
|
| 98 | + $full = $full ? $full.static::SEP.$item : $item; |
|
| 99 | 99 | $temp = &$temp[$item]; |
| 100 | 100 | if ($this->relations[$full][0]->many) { |
| 101 | 101 | $rpk = []; |
| 102 | 102 | foreach ($this->relations[$full][0]->table->getPrimaryKey() as $pkey) { |
| 103 | - $nm = $full . static::SEP . $pkey; |
|
| 103 | + $nm = $full.static::SEP.$pkey; |
|
| 104 | 104 | if (isset($this->aliases[$nm])) { |
| 105 | 105 | $nm = $this->aliases[$nm]; |
| 106 | 106 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | if (!isset($temp[$name])) { |
| 113 | - $temp[$name] = $relation->many ? [ '___clean' => true ] : null; |
|
| 113 | + $temp[$name] = $relation->many ? ['___clean' => true] : null; |
|
| 114 | 114 | } |
| 115 | 115 | $temp = &$temp[$name]; |
| 116 | 116 | if ($relation->many) { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | - $this->fetched ++; |
|
| 179 | + $this->fetched++; |
|
| 180 | 180 | while ($this->result->valid()) { |
| 181 | 181 | $row = $this->result->current(); |
| 182 | 182 | $pk = []; |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | $table = $temp[1]; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if (isset($tables[$schema . '.' . $table])) { |
|
| 33 | - return $tables[$schema . '.' . $table]; |
|
| 32 | + if (isset($tables[$schema.'.'.$table])) { |
|
| 33 | + return $tables[$schema.'.'.$table]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | static $relationsT = null; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | (kc.table_schema = ? OR ct.table_schema = ?) AND |
| 62 | 62 | kc.table_name IS NOT NULL AND |
| 63 | 63 | kc.position_in_unique_constraint IS NOT NULL", |
| 64 | - [ $catalog, $main, $main ] |
|
| 64 | + [$catalog, $main, $main] |
|
| 65 | 65 | ) |
| 66 | 66 | )->toArray(); |
| 67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | if ($row['referenced_table_schema'] !== $main) { |
| 72 | 72 | $additional[] = $row['referenced_table_schema']; |
| 73 | 73 | } |
| 74 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
| 75 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
| 74 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
| 75 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
| 76 | 76 | } |
| 77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
| 78 | 78 | $col = Collection::from( |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | (kc.table_schema = ? AND ct.table_schema = ?) AND |
| 98 | 98 | kc.table_name IS NOT NULL AND |
| 99 | 99 | kc.position_in_unique_constraint IS NOT NULL", |
| 100 | - [ $catalog, $s, $s ] |
|
| 100 | + [$catalog, $s, $s] |
|
| 101 | 101 | ) |
| 102 | 102 | )->toArray(); |
| 103 | 103 | foreach ($col as $row) { |
| 104 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
| 105 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
| 104 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
| 105 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | $columns = Collection::from($this |
| 111 | 111 | ->query( |
| 112 | 112 | "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
| 113 | - [ $table, $schema, $catalog ] |
|
| 113 | + [$table, $schema, $catalog] |
|
| 114 | 114 | )) |
| 115 | - ->mapKey(function ($v) { |
|
| 115 | + ->mapKey(function($v) { |
|
| 116 | 116 | return $v['column_name']; |
| 117 | 117 | }) |
| 118 | - ->map(function ($v) { |
|
| 118 | + ->map(function($v) { |
|
| 119 | 119 | $v['length'] = null; |
| 120 | 120 | if (!isset($v['data_type'])) { |
| 121 | 121 | return $v; |
@@ -123,20 +123,20 @@ discard block |
||
| 123 | 123 | switch ($v['data_type']) { |
| 124 | 124 | case 'character': |
| 125 | 125 | case 'character varying': |
| 126 | - $v['length'] = (int)$v['character_maximum_length']; |
|
| 126 | + $v['length'] = (int) $v['character_maximum_length']; |
|
| 127 | 127 | break; |
| 128 | 128 | } |
| 129 | 129 | return $v; |
| 130 | 130 | }) |
| 131 | 131 | ->toArray(); |
| 132 | 132 | if (!count($columns)) { |
| 133 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
| 133 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
| 134 | 134 | } |
| 135 | 135 | $pkname = Collection::from($this |
| 136 | 136 | ->query( |
| 137 | 137 | "SELECT constraint_name FROM information_schema.table_constraints |
| 138 | 138 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
| 139 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
| 139 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
| 140 | 140 | )) |
| 141 | 141 | ->pluck('constraint_name') |
| 142 | 142 | ->value(); |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | ->query( |
| 147 | 147 | "SELECT column_name FROM information_schema.constraint_column_usage |
| 148 | 148 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
| 149 | - [ $table, $pkname, $schema, $catalog ] |
|
| 149 | + [$table, $pkname, $schema, $catalog] |
|
| 150 | 150 | )) |
| 151 | 151 | ->pluck('column_name') |
| 152 | 152 | ->toArray(); |
| 153 | 153 | } |
| 154 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 154 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 155 | 155 | ->addColumns($columns) |
| 156 | 156 | ->setPrimaryKey($primary) |
| 157 | 157 | ->setComment(''); |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 162 | 162 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 163 | 163 | $relations = []; |
| 164 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 165 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . $relation['table_name']; |
|
| 164 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 165 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.$relation['table_name']; |
|
| 166 | 166 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 167 | 167 | $relation['column_name']; |
| 168 | 168 | } |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | $usedcol = []; |
| 179 | 179 | if (count($columns)) { |
| 180 | 180 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 181 | - ->filter(function ($v) use ($columns) { |
|
| 181 | + ->filter(function($v) use ($columns) { |
|
| 182 | 182 | return in_array($v['column_name'], $columns); |
| 183 | 183 | }) as $relation |
| 184 | 184 | ) { |
| 185 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
| 185 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
| 186 | 186 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 187 | 187 | $relation['referenced_column_name']; |
| 188 | 188 | $usedcol[] = $relation['column_name']; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $orig = $relname; |
| 199 | 199 | $cntr = 1; |
| 200 | 200 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 201 | - $relname = $orig . '_' . (++ $cntr); |
|
| 201 | + $relname = $orig.'_'.(++$cntr); |
|
| 202 | 202 | } |
| 203 | 203 | $definition->addRelation( |
| 204 | 204 | new TableRelation( |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $orig = $relname; |
| 220 | 220 | $cntr = 1; |
| 221 | 221 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 222 | - $relname = $orig . '_' . (++ $cntr); |
|
| 222 | + $relname = $orig.'_'.(++$cntr); |
|
| 223 | 223 | } |
| 224 | 224 | $definition->addRelation( |
| 225 | 225 | new TableRelation( |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | // assuming current table is linked to "one" record in the referenced table |
| 236 | 236 | // resulting in a "belongsTo" relationship |
| 237 | 237 | $relations = []; |
| 238 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 239 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
| 238 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 239 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
| 240 | 240 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 241 | 241 | $relation['referenced_column_name']; |
| 242 | 242 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $orig = $relname; |
| 250 | 250 | $cntr = 1; |
| 251 | 251 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 252 | - $relname = $orig . '_' . (++ $cntr); |
|
| 252 | + $relname = $orig.'_'.(++$cntr); |
|
| 253 | 253 | } |
| 254 | 254 | $definition->addRelation( |
| 255 | 255 | new TableRelation( |
@@ -268,19 +268,19 @@ discard block |
||
| 268 | 268 | $tables = Collection::from($this |
| 269 | 269 | ->query( |
| 270 | 270 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
| 271 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
| 271 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
| 272 | 272 | )) |
| 273 | - ->mapKey(function ($v) { |
|
| 273 | + ->mapKey(function($v) { |
|
| 274 | 274 | return $v['table_name']; |
| 275 | 275 | }) |
| 276 | 276 | ->pluck('table_name') |
| 277 | - ->map(function ($v) { |
|
| 277 | + ->map(function($v) { |
|
| 278 | 278 | return $this->table($v); |
| 279 | 279 | }) |
| 280 | 280 | ->toArray(); |
| 281 | 281 | |
| 282 | 282 | foreach (array_keys($tables) as $k) { |
| 283 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
| 283 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
| 284 | 284 | } |
| 285 | 285 | return $tables; |
| 286 | 286 | } |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | if (!is_array($err)) { |
| 61 | 61 | $err = []; |
| 62 | 62 | } |
| 63 | - if ($log && (int)$this->driver->option('log_errors', 1)) { |
|
| 63 | + if ($log && (int) $this->driver->option('log_errors', 1)) { |
|
| 64 | 64 | @file_put_contents( |
| 65 | 65 | $log, |
| 66 | - '--' . date('Y-m-d H:i:s') . ' ERROR: ' . implode(',', $err) . "\r\n" . |
|
| 67 | - $this->sql . "\r\n" . |
|
| 66 | + '--'.date('Y-m-d H:i:s').' ERROR: '.implode(',', $err)."\r\n". |
|
| 67 | + $this->sql."\r\n". |
|
| 68 | 68 | "\r\n", |
| 69 | 69 | FILE_APPEND |
| 70 | 70 | ); |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | if ($log) { |
| 75 | 75 | $tm = microtime(true) - $tm; |
| 76 | - if ($tm >= (float)$this->driver->option('log_slow', 0)) { |
|
| 76 | + if ($tm >= (float) $this->driver->option('log_slow', 0)) { |
|
| 77 | 77 | @file_put_contents( |
| 78 | 78 | $log, |
| 79 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 80 | - $this->sql . "\r\n" . |
|
| 79 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 80 | + $this->sql."\r\n". |
|
| 81 | 81 | "\r\n", |
| 82 | 82 | FILE_APPEND |
| 83 | 83 | ); |