|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\Database\SQLSRV; |
13 | 13 |
|
14 | | -use Closure; |
15 | 14 | use CodeIgniter\Database\BaseBuilder; |
16 | 15 | use CodeIgniter\Database\Exceptions\DatabaseException; |
17 | 16 | use CodeIgniter\Database\Exceptions\DataException; |
@@ -93,57 +92,7 @@ protected function _truncate(string $table): string |
93 | 92 | */ |
94 | 93 | public function join(string $table, string $cond, string $type = '', ?bool $escape = null) |
95 | 94 | { |
96 | | - if ($type !== '') { |
97 | | - $type = strtoupper(trim($type)); |
98 | | - |
99 | | - if (! in_array($type, $this->joinTypes, true)) { |
100 | | - $type = ''; |
101 | | - } else { |
102 | | - $type .= ' '; |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - // Extract any aliases that might exist. We use this information |
107 | | - // in the protectIdentifiers to know whether to add a table prefix |
108 | | - $this->trackAliases($table); |
109 | | - |
110 | | - if (! is_bool($escape)) { |
111 | | - $escape = $this->db->protectIdentifiers; |
112 | | - } |
113 | | - |
114 | | - if (! $this->hasOperator($cond)) { |
115 | | - $cond = ' USING (' . ($escape ? $this->db->escapeIdentifiers($cond) : $cond) . ')'; |
116 | | - } elseif ($escape === false) { |
117 | | - $cond = ' ON ' . $cond; |
118 | | - } else { |
119 | | - // Split multiple conditions |
120 | | - if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) { |
121 | | - $conditions = []; |
122 | | - $joints = $joints[0]; |
123 | | - array_unshift($joints, ['', 0]); |
124 | | - |
125 | | - for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) { |
126 | | - $joints[$i][1] += strlen($joints[$i][0]); // offset |
127 | | - $conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]); |
128 | | - $pos = $joints[$i][1] - strlen($joints[$i][0]); |
129 | | - $joints[$i] = $joints[$i][0]; |
130 | | - } |
131 | | - |
132 | | - ksort($conditions); |
133 | | - } else { |
134 | | - $conditions = [$cond]; |
135 | | - $joints = ['']; |
136 | | - } |
137 | | - |
138 | | - $cond = ' ON '; |
139 | | - |
140 | | - foreach ($conditions as $i => $condition) { |
141 | | - $operator = $this->getOperator($condition); |
142 | | - |
143 | | - $cond .= $joints[$i]; |
144 | | - $cond .= preg_match('/(\(*)?([\[\]\w\.\'-]+)' . preg_quote($operator, '/') . '(.*)/i', $condition, $match) ? $match[1] . $this->db->protectIdentifiers($match[2]) . $operator . $this->db->protectIdentifiers($match[3]) : $condition; |
145 | | - } |
146 | | - } |
| 95 | + parent::join($table, $cond, $type, $escape); |
147 | 96 |
|
148 | 97 | // Do we want to escape the table name? |
149 | 98 | if ($escape === true) { |
@@ -516,73 +465,6 @@ protected function compileSelect($selectOverride = false): string |
516 | 465 | return $sql; |
517 | 466 | } |
518 | 467 |
|
519 | | - /** |
520 | | - * WHERE, HAVING |
521 | | - * |
522 | | - * @param mixed $key |
523 | | - * @param mixed $value |
524 | | - * |
525 | | - * @return $this |
526 | | - */ |
527 | | - protected function whereHaving(string $qbKey, $key, $value = null, string $type = 'AND ', ?bool $escape = null) |
528 | | - { |
529 | | - if (! is_array($key)) { |
530 | | - $key = [$key => $value]; |
531 | | - } |
532 | | - |
533 | | - // If the escape value was not set will base it on the global setting |
534 | | - if (! is_bool($escape)) { |
535 | | - $escape = $this->db->protectIdentifiers; |
536 | | - } |
537 | | - |
538 | | - foreach ($key as $k => $v) { |
539 | | - $prefix = empty($this->{$qbKey}) ? $this->groupGetType('') : $this->groupGetType($type); |
540 | | - |
541 | | - if ($v !== null) { |
542 | | - $op = $this->getOperator($k, true); |
543 | | - |
544 | | - if (! empty($op)) { |
545 | | - $k = trim($k); |
546 | | - |
547 | | - end($op); |
548 | | - |
549 | | - $op = trim(current($op)); |
550 | | - |
551 | | - if (substr($k, -1 * strlen($op)) === $op) { |
552 | | - $k = rtrim(strrev(preg_replace(strrev('/' . $op . '/'), strrev(''), strrev($k), 1))); |
553 | | - } |
554 | | - } |
555 | | - |
556 | | - $bind = $this->setBind($k, $v, $escape); |
557 | | - |
558 | | - if (empty($op)) { |
559 | | - $k .= ' ='; |
560 | | - } else { |
561 | | - $k .= " {$op}"; |
562 | | - } |
563 | | - |
564 | | - if ($v instanceof Closure) { |
565 | | - $builder = $this->cleanClone(); |
566 | | - $v = '(' . str_replace("\n", ' ', $v($builder)->getCompiledSelect()) . ')'; |
567 | | - } else { |
568 | | - $v = " :{$bind}:"; |
569 | | - } |
570 | | - } elseif (! $this->hasOperator($k) && $qbKey !== 'QBHaving') { |
571 | | - // value appears not to have been set, assign the test to IS NULL |
572 | | - $k .= ' IS NULL'; |
573 | | - } elseif (preg_match('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) { |
574 | | - $k = substr($k, 0, $match[0][1]) . ($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL'); |
575 | | - } |
576 | | - |
577 | | - $this->{$qbKey}[] = [ |
578 | | - 'condition' => $prefix . $k . $v, |
579 | | - 'escape' => $escape, |
580 | | - ]; |
581 | | - } |
582 | | - |
583 | | - return $this; |
584 | | - } |
585 | | - |
586 | 468 | /** |
587 | 469 | * Compiles the select statement based on the other functions called |
588 | 470 | * and runs the query |
|
0 commit comments