@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | /** |
| 44 | 44 | * @var int[] |
| 45 | 45 | */ |
| 46 | - protected $li_of = [0,0]; |
|
| 46 | + protected $li_of = [0, 0]; |
|
| 47 | 47 | /** |
| 48 | 48 | * @var array |
| 49 | 49 | */ |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function __construct(DBInterface $db, $table) |
| 70 | 70 | { |
| 71 | 71 | $this->db = $db; |
| 72 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
| 72 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
| 73 | 73 | $primary = $this->definition->getPrimaryKey(); |
| 74 | 74 | $columns = $this->definition->getColumns(); |
| 75 | 75 | $this->pkey = count($primary) ? $primary : $columns; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $column = explode('.', $column); |
| 94 | 94 | if (count($column) === 1) { |
| 95 | - $column = [ $this->definition->getName(), $column[0] ]; |
|
| 95 | + $column = [$this->definition->getName(), $column[0]]; |
|
| 96 | 96 | $col = $this->definition->getColumn($column[1]); |
| 97 | 97 | } elseif (count($column) === 2) { |
| 98 | 98 | if ($column[0] === $this->definition->getName()) { |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | throw new DBException('Invalid column name in related table'); |
| 113 | 113 | } |
| 114 | 114 | } else { |
| 115 | - throw new DBException('Invalid foreign table name: ' . implode(',', $column)); |
|
| 115 | + throw new DBException('Invalid foreign table name: '.implode(',', $column)); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } else { |
@@ -121,15 +121,15 @@ discard block |
||
| 121 | 121 | $table = $this->definition; |
| 122 | 122 | $table = array_reduce( |
| 123 | 123 | $column, |
| 124 | - function ($carry, $item) use (&$table) { |
|
| 124 | + function($carry, $item) use (&$table) { |
|
| 125 | 125 | $table = $table->getRelation($item)->table; |
| 126 | 126 | return $table; |
| 127 | 127 | } |
| 128 | 128 | ); |
| 129 | 129 | $col = $table->getColumn($name); |
| 130 | - $column = [ implode(static::SEP, $column), $name ]; |
|
| 130 | + $column = [implode(static::SEP, $column), $name]; |
|
| 131 | 131 | } |
| 132 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
| 132 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
| 133 | 133 | } |
| 134 | 134 | protected function normalizeValue(TableColumn $col, $value) |
| 135 | 135 | { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | return $value; |
| 178 | 178 | case 'int': |
| 179 | - return (int)$value; |
|
| 179 | + return (int) $value; |
|
| 180 | 180 | default: |
| 181 | 181 | return $value; |
| 182 | 182 | } |
@@ -194,18 +194,16 @@ discard block |
||
| 194 | 194 | list($name, $column) = array_values($this->getColumn($column)); |
| 195 | 195 | if (is_null($value)) { |
| 196 | 196 | return $negate ? |
| 197 | - $this->where($name . ' IS NOT NULL') : |
|
| 198 | - $this->where($name . ' IS NULL'); |
|
| 197 | + $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL'); |
|
| 199 | 198 | } |
| 200 | 199 | if (!is_array($value)) { |
| 201 | 200 | return $negate ? |
| 202 | 201 | $this->where( |
| 203 | - $name . ' <> ?', |
|
| 204 | - [ $this->normalizeValue($column, $value) ] |
|
| 205 | - ) : |
|
| 206 | - $this->where( |
|
| 207 | - $name . ' = ?', |
|
| 208 | - [ $this->normalizeValue($column, $value) ] |
|
| 202 | + $name.' <> ?', |
|
| 203 | + [$this->normalizeValue($column, $value)] |
|
| 204 | + ) : $this->where( |
|
| 205 | + $name.' = ?', |
|
| 206 | + [$this->normalizeValue($column, $value)] |
|
| 209 | 207 | ); |
| 210 | 208 | } |
| 211 | 209 | if (isset($value['beg']) && isset($value['end'])) { |
@@ -216,8 +214,7 @@ discard block |
||
| 216 | 214 | $this->normalizeValue($column, $value['beg']), |
| 217 | 215 | $this->normalizeValue($column, $value['end']) |
| 218 | 216 | ] |
| 219 | - ) : |
|
| 220 | - $this->where( |
|
| 217 | + ) : $this->where( |
|
| 221 | 218 | $name.' BETWEEN ? AND ?', |
| 222 | 219 | [ |
| 223 | 220 | $this->normalizeValue($column, $value['beg']), |
@@ -227,12 +224,12 @@ discard block |
||
| 227 | 224 | } |
| 228 | 225 | return $negate ? |
| 229 | 226 | $this->where( |
| 230 | - $name . ' NOT IN (??)', |
|
| 231 | - [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ] |
|
| 227 | + $name.' NOT IN (??)', |
|
| 228 | + [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)] |
|
| 232 | 229 | ) : |
| 233 | 230 | $this->where( |
| 234 | - $name . ' IN (??)', |
|
| 235 | - [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ] |
|
| 231 | + $name.' IN (??)', |
|
| 232 | + [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)] |
|
| 236 | 233 | ); |
| 237 | 234 | } |
| 238 | 235 | /** |
@@ -243,7 +240,7 @@ discard block |
||
| 243 | 240 | */ |
| 244 | 241 | public function sort(string $column, bool $desc = false) : TableQuery |
| 245 | 242 | { |
| 246 | - return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
| 243 | + return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC')); |
|
| 247 | 244 | } |
| 248 | 245 | /** |
| 249 | 246 | * Group by a column (or columns) |
@@ -253,7 +250,7 @@ discard block |
||
| 253 | 250 | public function group($column) : TableQuery |
| 254 | 251 | { |
| 255 | 252 | if (!is_array($column)) { |
| 256 | - $column = [ $column ]; |
|
| 253 | + $column = [$column]; |
|
| 257 | 254 | } |
| 258 | 255 | foreach ($column as $k => $v) { |
| 259 | 256 | $column[$k] = $this->getColumn($v)['name']; |
@@ -294,7 +291,7 @@ discard block |
||
| 294 | 291 | $this->withr = []; |
| 295 | 292 | $this->order = []; |
| 296 | 293 | $this->having = []; |
| 297 | - $this->li_of = [0,0]; |
|
| 294 | + $this->li_of = [0, 0]; |
|
| 298 | 295 | $this->qiterator = null; |
| 299 | 296 | return $this; |
| 300 | 297 | } |
@@ -307,7 +304,7 @@ discard block |
||
| 307 | 304 | public function groupBy(string $sql, array $params = []) : TableQuery |
| 308 | 305 | { |
| 309 | 306 | $this->qiterator = null; |
| 310 | - $this->group = [ $sql, $params ]; |
|
| 307 | + $this->group = [$sql, $params]; |
|
| 311 | 308 | return $this; |
| 312 | 309 | } |
| 313 | 310 | /** |
@@ -320,7 +317,7 @@ discard block |
||
| 320 | 317 | */ |
| 321 | 318 | public function join($table, array $fields, string $name = null, bool $multiple = true) |
| 322 | 319 | { |
| 323 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
| 320 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
| 324 | 321 | $name = $name ?? $table->getName(); |
| 325 | 322 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
| 326 | 323 | throw new DBException('Alias / table name already in use'); |
@@ -329,7 +326,7 @@ discard block |
||
| 329 | 326 | foreach ($fields as $k => $v) { |
| 330 | 327 | $k = explode('.', $k, 2); |
| 331 | 328 | $k = count($k) == 2 ? $k[1] : $k[0]; |
| 332 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
| 329 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
| 333 | 330 | } |
| 334 | 331 | return $this; |
| 335 | 332 | } |
@@ -342,7 +339,7 @@ discard block |
||
| 342 | 339 | public function where(string $sql, array $params = []) : TableQuery |
| 343 | 340 | { |
| 344 | 341 | $this->qiterator = null; |
| 345 | - $this->where[] = [ $sql, $params ]; |
|
| 342 | + $this->where[] = [$sql, $params]; |
|
| 346 | 343 | return $this; |
| 347 | 344 | } |
| 348 | 345 | /** |
@@ -354,7 +351,7 @@ discard block |
||
| 354 | 351 | public function having(string $sql, array $params = []) : TableQuery |
| 355 | 352 | { |
| 356 | 353 | $this->qiterator = null; |
| 357 | - $this->having[] = [ $sql, $params ]; |
|
| 354 | + $this->having[] = [$sql, $params]; |
|
| 358 | 355 | return $this; |
| 359 | 356 | } |
| 360 | 357 | /** |
@@ -366,7 +363,7 @@ discard block |
||
| 366 | 363 | public function order(string $sql, array $params = []) : TableQuery |
| 367 | 364 | { |
| 368 | 365 | $this->qiterator = null; |
| 369 | - $this->order = [ $sql, $params ]; |
|
| 366 | + $this->order = [$sql, $params]; |
|
| 370 | 367 | return $this; |
| 371 | 368 | } |
| 372 | 369 | /** |
@@ -378,7 +375,7 @@ discard block |
||
| 378 | 375 | public function limit(int $limit, int $offset = 0) : TableQuery |
| 379 | 376 | { |
| 380 | 377 | $this->qiterator = null; |
| 381 | - $this->li_of = [ $limit, $offset ]; |
|
| 378 | + $this->li_of = [$limit, $offset]; |
|
| 382 | 379 | return $this; |
| 383 | 380 | } |
| 384 | 381 | /** |
@@ -394,22 +391,22 @@ discard block |
||
| 394 | 391 | $relations = $this->withr; |
| 395 | 392 | foreach ($this->definition->getRelations() as $k => $v) { |
| 396 | 393 | foreach ($this->where as $vv) { |
| 397 | - if (strpos($vv[0], $k . '.') !== false) { |
|
| 398 | - $relations[$k] = [ $v, $table ]; |
|
| 394 | + if (strpos($vv[0], $k.'.') !== false) { |
|
| 395 | + $relations[$k] = [$v, $table]; |
|
| 399 | 396 | } |
| 400 | 397 | } |
| 401 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
| 402 | - $relations[$k] = [ $v, $table ]; |
|
| 398 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
| 399 | + $relations[$k] = [$v, $table]; |
|
| 403 | 400 | } |
| 404 | 401 | } |
| 405 | 402 | |
| 406 | 403 | foreach ($this->joins as $k => $v) { |
| 407 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
| 404 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
| 408 | 405 | $tmp = []; |
| 409 | 406 | foreach ($v->keymap as $kk => $vv) { |
| 410 | 407 | $tmp[] = $kk.' = '.$vv; |
| 411 | 408 | } |
| 412 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 409 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 413 | 410 | } |
| 414 | 411 | foreach ($relations as $k => $v) { |
| 415 | 412 | $table = $v[1]; |
@@ -420,13 +417,13 @@ discard block |
||
| 420 | 417 | foreach ($v->keymap as $kk => $vv) { |
| 421 | 418 | $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' '; |
| 422 | 419 | } |
| 423 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 420 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 424 | 421 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
| 425 | 422 | $tmp = []; |
| 426 | 423 | foreach ($v->pivot_keymap as $kk => $vv) { |
| 427 | 424 | $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' '; |
| 428 | 425 | } |
| 429 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 426 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 430 | 427 | } else { |
| 431 | 428 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
| 432 | 429 | $tmp = []; |
@@ -434,30 +431,30 @@ discard block |
||
| 434 | 431 | $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' '; |
| 435 | 432 | } |
| 436 | 433 | if ($v->sql) { |
| 437 | - $tmp[] = $v->sql . ' '; |
|
| 434 | + $tmp[] = $v->sql.' '; |
|
| 438 | 435 | $par = array_merge($par, $v->par ?? []); |
| 439 | 436 | } |
| 440 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 437 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 441 | 438 | } |
| 442 | 439 | } |
| 443 | 440 | if (count($this->where)) { |
| 444 | 441 | $sql .= 'WHERE '; |
| 445 | 442 | $tmp = []; |
| 446 | 443 | foreach ($this->where as $v) { |
| 447 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 444 | + $tmp[] = '('.$v[0].')'; |
|
| 448 | 445 | $par = array_merge($par, $v[1]); |
| 449 | 446 | } |
| 450 | 447 | $sql .= implode(' AND ', $tmp).' '; |
| 451 | 448 | } |
| 452 | 449 | if (count($this->group)) { |
| 453 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
| 450 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
| 454 | 451 | $par = array_merge($par, $this->group[1]); |
| 455 | 452 | } |
| 456 | 453 | if (count($this->having)) { |
| 457 | 454 | $sql .= 'HAVING '; |
| 458 | 455 | $tmp = []; |
| 459 | 456 | foreach ($this->having as $v) { |
| 460 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 457 | + $tmp[] = '('.$v[0].')'; |
|
| 461 | 458 | $par = array_merge($par, $v[1]); |
| 462 | 459 | } |
| 463 | 460 | $sql .= implode(' AND ', $tmp).' '; |
@@ -491,7 +488,7 @@ discard block |
||
| 491 | 488 | $this->with(implode('.', $temp)); |
| 492 | 489 | $table = array_reduce( |
| 493 | 490 | $temp, |
| 494 | - function ($carry, $item) use (&$table) { |
|
| 491 | + function($carry, $item) use (&$table) { |
|
| 495 | 492 | return $table->getRelation($item)->table; |
| 496 | 493 | } |
| 497 | 494 | ); |
@@ -500,7 +497,7 @@ discard block |
||
| 500 | 497 | } |
| 501 | 498 | unset($fields[$k]); |
| 502 | 499 | foreach ($cols as $col) { |
| 503 | - $fields[] = $table . '.' . $col; |
|
| 500 | + $fields[] = $table.'.'.$col; |
|
| 504 | 501 | } |
| 505 | 502 | } |
| 506 | 503 | } |
@@ -538,37 +535,37 @@ discard block |
||
| 538 | 535 | $relations = $this->withr; |
| 539 | 536 | foreach ($this->definition->getRelations() as $k => $relation) { |
| 540 | 537 | foreach ($this->fields as $field) { |
| 541 | - if (strpos($field, $k . '.') === 0) { |
|
| 542 | - $relations[$k] = [ $relation, $table ]; |
|
| 538 | + if (strpos($field, $k.'.') === 0) { |
|
| 539 | + $relations[$k] = [$relation, $table]; |
|
| 543 | 540 | } |
| 544 | 541 | } |
| 545 | 542 | foreach ($this->where as $v) { |
| 546 | - if (strpos($v[0], $k . '.') !== false) { |
|
| 547 | - $relations[$k] = [ $relation, $table ]; |
|
| 543 | + if (strpos($v[0], $k.'.') !== false) { |
|
| 544 | + $relations[$k] = [$relation, $table]; |
|
| 548 | 545 | } |
| 549 | 546 | } |
| 550 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
| 551 | - $relations[$k] = [ $relation, $table ]; |
|
| 547 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
| 548 | + $relations[$k] = [$relation, $table]; |
|
| 552 | 549 | } |
| 553 | 550 | } |
| 554 | 551 | $select = []; |
| 555 | 552 | foreach ($this->fields as $k => $field) { |
| 556 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
| 553 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
| 557 | 554 | } |
| 558 | 555 | foreach ($this->withr as $name => $relation) { |
| 559 | 556 | foreach ($relation[0]->table->getColumns() as $column) { |
| 560 | - $select[] = $name . '.' . $column . ' ' . $name . static::SEP . $column; |
|
| 557 | + $select[] = $name.'.'.$column.' '.$name.static::SEP.$column; |
|
| 561 | 558 | } |
| 562 | 559 | } |
| 563 | 560 | $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' '; |
| 564 | 561 | $par = []; |
| 565 | 562 | foreach ($this->joins as $k => $v) { |
| 566 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
| 563 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
| 567 | 564 | $tmp = []; |
| 568 | 565 | foreach ($v->keymap as $kk => $vv) { |
| 569 | 566 | $tmp[] = $kk.' = '.$vv; |
| 570 | 567 | } |
| 571 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 568 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 572 | 569 | } |
| 573 | 570 | foreach ($relations as $relation => $v) { |
| 574 | 571 | $table = $v[1]; |
@@ -579,13 +576,13 @@ discard block |
||
| 579 | 576 | foreach ($v->keymap as $kk => $vv) { |
| 580 | 577 | $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' '; |
| 581 | 578 | } |
| 582 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 579 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 583 | 580 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
| 584 | 581 | $tmp = []; |
| 585 | 582 | foreach ($v->pivot_keymap as $kk => $vv) { |
| 586 | 583 | $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' '; |
| 587 | 584 | } |
| 588 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 585 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 589 | 586 | } else { |
| 590 | 587 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
| 591 | 588 | $tmp = []; |
@@ -593,36 +590,36 @@ discard block |
||
| 593 | 590 | $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' '; |
| 594 | 591 | } |
| 595 | 592 | if ($v->sql) { |
| 596 | - $tmp[] = $v->sql . ' '; |
|
| 593 | + $tmp[] = $v->sql.' '; |
|
| 597 | 594 | $par = array_merge($par, $v->par ?? []); |
| 598 | 595 | } |
| 599 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 596 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 600 | 597 | } |
| 601 | 598 | } |
| 602 | 599 | if (count($this->where)) { |
| 603 | 600 | $sql .= 'WHERE '; |
| 604 | 601 | $tmp = []; |
| 605 | 602 | foreach ($this->where as $v) { |
| 606 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 603 | + $tmp[] = '('.$v[0].')'; |
|
| 607 | 604 | $par = array_merge($par, $v[1]); |
| 608 | 605 | } |
| 609 | 606 | $sql .= implode(' AND ', $tmp).' '; |
| 610 | 607 | } |
| 611 | 608 | if (count($this->group)) { |
| 612 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
| 609 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
| 613 | 610 | $par = array_merge($par, $this->group[1]); |
| 614 | 611 | } |
| 615 | 612 | if (count($this->having)) { |
| 616 | 613 | $sql .= 'HAVING '; |
| 617 | 614 | $tmp = []; |
| 618 | 615 | foreach ($this->having as $v) { |
| 619 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 616 | + $tmp[] = '('.$v[0].')'; |
|
| 620 | 617 | $par = array_merge($par, $v[1]); |
| 621 | 618 | } |
| 622 | 619 | $sql .= implode(' AND ', $tmp).' '; |
| 623 | 620 | } |
| 624 | 621 | if (count($this->order)) { |
| 625 | - $sql .= 'ORDER BY ' . $this->order[0] . ' '; |
|
| 622 | + $sql .= 'ORDER BY '.$this->order[0].' '; |
|
| 626 | 623 | $par = array_merge($par, $this->order[1]); |
| 627 | 624 | } |
| 628 | 625 | $porder = []; |
@@ -630,30 +627,30 @@ discard block |
||
| 630 | 627 | $porder[] = $this->getColumn($field)['name']; |
| 631 | 628 | } |
| 632 | 629 | if (count($porder)) { |
| 633 | - $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
| 630 | + $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
| 634 | 631 | } |
| 635 | 632 | |
| 636 | 633 | if ($this->li_of[0]) { |
| 637 | 634 | if ($this->db->driverName() === 'oracle') { |
| 638 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
| 639 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
| 635 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
| 636 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
| 640 | 637 | } else { |
| 641 | - $f = array_map(function ($v) { |
|
| 638 | + $f = array_map(function($v) { |
|
| 642 | 639 | $v = explode(' ', trim($v), 2); |
| 643 | 640 | if (count($v) === 2) { return $v[1]; } |
| 644 | 641 | $v = explode('.', $v[0], 2); |
| 645 | 642 | return count($v) === 2 ? $v[1] : $v[0]; |
| 646 | 643 | }, $select); |
| 647 | - $sql = "SELECT " . implode(', ', $f) . " |
|
| 644 | + $sql = "SELECT ".implode(', ', $f)." |
|
| 648 | 645 | FROM ( |
| 649 | 646 | SELECT tbl__.*, rownum rnum__ FROM ( |
| 650 | - " . $sql . " |
|
| 647 | + " . $sql." |
|
| 651 | 648 | ) tbl__ |
| 652 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
| 649 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
| 653 | 650 | ) WHERE rnum__ > " . $this->li_of[1]; |
| 654 | 651 | } |
| 655 | 652 | } else { |
| 656 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
| 653 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
| 657 | 654 | } |
| 658 | 655 | } |
| 659 | 656 | return $this->qiterator = new TableQueryIterator( |
@@ -702,7 +699,7 @@ discard block |
||
| 702 | 699 | $ret[$k] = str_repeat(' ', 255); |
| 703 | 700 | $par[] = &$ret[$k]; |
| 704 | 701 | } |
| 705 | - $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
| 702 | + $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
| 706 | 703 | $this->db->query($sql, $par); |
| 707 | 704 | return $ret; |
| 708 | 705 | } else { |
@@ -734,7 +731,7 @@ discard block |
||
| 734 | 731 | } |
| 735 | 732 | $sql = 'UPDATE '.$table.' SET '; |
| 736 | 733 | $par = []; |
| 737 | - $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' '; |
|
| 734 | + $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' '; |
|
| 738 | 735 | $par = array_merge($par, array_values($update)); |
| 739 | 736 | if (count($this->where)) { |
| 740 | 737 | $sql .= 'WHERE '; |
@@ -743,7 +740,7 @@ discard block |
||
| 743 | 740 | $tmp[] = $v[0]; |
| 744 | 741 | $par = array_merge($par, $v[1]); |
| 745 | 742 | } |
| 746 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 743 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 747 | 744 | } |
| 748 | 745 | if (count($this->order)) { |
| 749 | 746 | $sql .= $this->order[0]; |
@@ -767,7 +764,7 @@ discard block |
||
| 767 | 764 | $tmp[] = $v[0]; |
| 768 | 765 | $par = array_merge($par, $v[1]); |
| 769 | 766 | } |
| 770 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 767 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 771 | 768 | } |
| 772 | 769 | if (count($this->order)) { |
| 773 | 770 | $sql .= $this->order[0]; |
@@ -787,13 +784,13 @@ discard block |
||
| 787 | 784 | $table = $this->definition; |
| 788 | 785 | array_reduce( |
| 789 | 786 | $parts, |
| 790 | - function ($carry, $item) use (&$table) { |
|
| 787 | + function($carry, $item) use (&$table) { |
|
| 791 | 788 | $relation = $table->getRelation($item); |
| 792 | 789 | if (!$relation) { |
| 793 | 790 | throw new DBException('Invalid relation name'); |
| 794 | 791 | } |
| 795 | - $name = $carry ? $carry . static::SEP . $item : $item; |
|
| 796 | - $this->withr[$name] = [ $relation, $carry ?? $table->getName() ]; |
|
| 792 | + $name = $carry ? $carry.static::SEP.$item : $item; |
|
| 793 | + $this->withr[$name] = [$relation, $carry ?? $table->getName()]; |
|
| 797 | 794 | $table = $relation->table; |
| 798 | 795 | return $name; |
| 799 | 796 | } |