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