Skip to content

Commit cc7a8cd

Browse files
committed
Changed from breaking changes to user $args
Changed from breaking changes to use the existing extra `$args`. All existing PHPUnit tests run without failing.
1 parent 6ef9eff commit cc7a8cd

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

lib/ezFunctions.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ function createCertificate(
113113
*
114114
* @param strings $y, - The right expression.
115115
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
116-
* @param strings $group, - notes beginning or end of where group, '(',')'.
117116
* @param strings $args - for any extras
118117
*
119-
* function comparison($x, $operator, $y, $and=null, $group=null, ...$args)
118+
* function comparison($x, $operator, $y, $and=null, ...$args)
120119
* {
121-
* return array($x, $operator, $y, $and, $group, ...$args);
120+
* return array($x, $operator, $y, $and, ...$args);
122121
* }
123122
*
124123
* @return array
@@ -127,110 +126,110 @@ function createCertificate(
127126
/**
128127
* Creates an equality comparison expression with the given arguments.
129128
*/
130-
function eq($x, $y, $and = null, $group = null, ...$args)
129+
function eq($x, $y, $and = null, ...$args)
131130
{
132131
$expression = array();
133-
\array_push($expression, $x, \EQ, $y, $and, $group, ...$args);
132+
\array_push($expression, $x, \EQ, $y, $and, ...$args);
134133
return $expression;
135134
}
136135

137136
/**
138137
* Creates a non equality comparison expression with the given arguments.
139138
*/
140-
function neq($x, $y, $and = null, $group = null, ...$args)
139+
function neq($x, $y, $and = null, ...$args)
141140
{
142141
$expression = array();
143-
\array_push($expression, $x, \NEQ, $y, $and, $group, ...$args);
142+
\array_push($expression, $x, \NEQ, $y, $and, ...$args);
144143
return $expression;
145144
}
146145

147146
/**
148147
* Creates the other non equality comparison expression with the given arguments.
149148
*/
150-
function ne($x, $y, $and = null, $group = null, ...$args)
149+
function ne($x, $y, $and = null, ...$args)
151150
{
152151
$expression = array();
153-
\array_push($expression, $x, \NE, $y, $and, $group, ...$args);
152+
\array_push($expression, $x, \NE, $y, $and, ...$args);
154153
return $expression;
155154
}
156155

157156
/**
158157
* Creates a lower-than comparison expression with the given arguments.
159158
*/
160-
function lt($x, $y, $and = null, $group = null, ...$args)
159+
function lt($x, $y, $and = null, ...$args)
161160
{
162161
$expression = array();
163-
\array_push($expression, $x, \LT, $y, $and, $group, ...$args);
162+
\array_push($expression, $x, \LT, $y, $and, ...$args);
164163
return $expression;
165164
}
166165

167166
/**
168167
* Creates a lower-than-equal comparison expression with the given arguments.
169168
*/
170-
function lte($x, $y, $and = null, $group = null, ...$args)
169+
function lte($x, $y, $and = null, ...$args)
171170
{
172171
$expression = array();
173-
\array_push($expression, $x, \LTE, $y, $and, $group, ...$args);
172+
\array_push($expression, $x, \LTE, $y, $and, ...$args);
174173
return $expression;
175174
}
176175

177176
/**
178177
* Creates a greater-than comparison expression with the given arguments.
179178
*/
180-
function gt($x, $y, $and = null, $group = null, ...$args)
179+
function gt($x, $y, $and = null, ...$args)
181180
{
182181
$expression = array();
183-
\array_push($expression, $x, \GT, $y, $and, $group, ...$args);
182+
\array_push($expression, $x, \GT, $y, $and, ...$args);
184183
return $expression;
185184
}
186185

187186
/**
188187
* Creates a greater-than-equal comparison expression with the given arguments.
189188
*/
190-
function gte($x, $y, $and = null, $group = null, ...$args)
189+
function gte($x, $y, $and = null, ...$args)
191190
{
192191
$expression = array();
193-
\array_push($expression, $x, \GTE, $y, $and, $group, ...$args);
192+
\array_push($expression, $x, \GTE, $y, $and, ...$args);
194193
return $expression;
195194
}
196195

197196
/**
198197
* Creates an IS NULL expression with the given arguments.
199198
*/
200-
function isNull($x, $y = 'null', $and = null, $group = null, ...$args)
199+
function isNull($x, $y = 'null', $and = null, ...$args)
201200
{
202201
$expression = array();
203-
\array_push($expression, $x, \_isNULL, $y, $and, $group, ...$args);
202+
\array_push($expression, $x, \_isNULL, $y, $and, ...$args);
204203
return $expression;
205204
}
206205

207206
/**
208207
* Creates an IS NOT NULL expression with the given arguments.
209208
*/
210-
function isNotNull($x, $y = 'null', $and = null, $group = null, ...$args)
209+
function isNotNull($x, $y = 'null', $and = null, ...$args)
211210
{
212211
$expression = array();
213-
\array_push($expression, $x, \_notNULL, $y, $and, $group, ...$args);
212+
\array_push($expression, $x, \_notNULL, $y, $and, ...$args);
214213
return $expression;
215214
}
216215

217216
/**
218217
* Creates a LIKE() comparison expression with the given arguments.
219218
*/
220-
function like($x, $y, $and = null, $group = null, ...$args)
219+
function like($x, $y, $and = null, ...$args)
221220
{
222221
$expression = array();
223-
\array_push($expression, $x, \_LIKE, $y, $and, $group, ...$args);
222+
\array_push($expression, $x, \_LIKE, $y, $and, ...$args);
224223
return $expression;
225224
}
226225

227226
/**
228227
* Creates a NOT LIKE() comparison expression with the given arguments.
229228
*/
230-
function notLike($x, $y, $and = null, $group = null, ...$args)
229+
function notLike($x, $y, $and = null, ...$args)
231230
{
232231
$expression = array();
233-
\array_push($expression, $x, \_notLIKE, $y, $and, $group, ...$args);
232+
\array_push($expression, $x, \_notLIKE, $y, $and, ...$args);
234233
return $expression;
235234
}
236235

@@ -260,7 +259,7 @@ function notIn($x, $y, ...$args)
260259
function between($x, $y, $y2, ...$args)
261260
{
262261
$expression = array();
263-
\array_push($expression, $x, \_BETWEEN, $y, $y2, null, \_AND, ...$args);
262+
\array_push($expression, $x, \_BETWEEN, $y, $y2, \_AND, ...$args);
264263
return $expression;
265264
}
266265

@@ -270,7 +269,7 @@ function between($x, $y, $y2, ...$args)
270269
function notBetween($x, $y, $y2, ...$args)
271270
{
272271
$expression = array();
273-
\array_push($expression, $x, \_notBETWEEN, $y, $y2, null, \_AND, ...$args);
272+
\array_push($expression, $x, \_notBETWEEN, $y, $y2, \_AND, ...$args);
274273
return $expression;
275274
}
276275

lib/ezQuery.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ public function limit($numberOf, $offset = null)
342342
return 'LIMIT ' . $rows . $value;
343343
}
344344

345-
private function conditions($key, $condition, $value, $combine, $group)
345+
private function conditions($key, $condition, $value, $combine, $extra)
346346
{
347-
$groupStart = (!empty($group) && $group === '(') ? $group : '';
348-
$groupEnd = (!empty($group) && $group === ')') ? $group : '';
347+
$groupStart = (!empty($extra) && $extra === '(') ? $extra : '';
348+
$groupEnd = (!empty($extra) && $extra === ')') ? $extra : '';
349349

350350
if ($this->isPrepareOn()) {
351351
$this->whereSQL .= "$groupStart $key $condition " . \_TAG . " $groupEnd $combine ";
@@ -399,35 +399,32 @@ private function retrieveConditions($whereConditions)
399399
$operator = [];
400400
$extra = [];
401401
$combiner = [];
402-
$group = [];
403402
foreach ($whereConditions as $checkFields) {
404403
$operator[] = (isset($checkFields[1])) ? $checkFields[1] : '';
405404
if (empty($checkFields[1])) {
406405
$this->clearPrepare();
407-
return [[], [], [], [], [], []];
406+
return [[], [], [], [], []];
408407
}
409408

410409
if (\strtoupper($checkFields[1]) == 'IN') {
411410
$whereKey[] = $checkFields[0];
412411
$whereValue[] = \array_slice((array) $checkFields, 2);
413412
$combiner[] = \_AND;
414-
$group[] = null;
415413
$extra[] = null;
416414
} else {
417415
if (!empty($checkFields[0])) {
418416
$whereKey[] = $checkFields[0];
419417
$whereValue[] = (isset($checkFields[2])) ? $checkFields[2] : '';
420418
$combiner[] = (isset($checkFields[3])) ? $checkFields[3] : \_AND;
421-
$group[] = (isset($checkFields[4])) ? $checkFields[4] : null;
422-
$extra[] = (isset($checkFields[5])) ? $checkFields[5] : null;
419+
$extra[] = (isset($checkFields[4])) ? $checkFields[4] : null;
423420
}
424421
}
425422
}
426423

427-
return [$operator, $whereKey, $whereValue, $combiner, $extra, $group];
424+
return [$operator, $whereKey, $whereValue, $combiner, $extra];
428425
}
429426

430-
private function processConditions($column, $condition, $value, $valueOrCombine, $extraCombine, $whereGroup)
427+
private function processConditions($column, $condition, $value, $valueOrCombine, $extraCombine)
431428
{
432429
if (!\in_array($condition, \_BOOLEAN_OPERATORS))
433430
return $this->clearPrepare();
@@ -441,7 +438,7 @@ private function processConditions($column, $condition, $value, $valueOrCombine,
441438
} elseif ((($condition == \_LIKE) || ($condition == \_notLIKE)) && !\preg_match('/[_%?]/', $value)) {
442439
return $this->clearPrepare();
443440
} else {
444-
$this->conditions($column, $condition, $value, $valueOrCombine, $whereGroup);
441+
$this->conditions($column, $condition, $value, $valueOrCombine, $extraCombine);
445442
}
446443
}
447444

@@ -459,11 +456,11 @@ public function whereGroup(...$whereConditions)
459456

460457
if ($totalConditions > 0) {
461458

462-
if (empty($whereConditions[0][4]) || $whereConditions[0][4] !== '(')
463-
$whereConditions[0][4] = '(';
459+
if (!in_array('(', $whereConditions[0]))
460+
$whereConditions[0][count($whereConditions[0])] = '(';
464461

465-
if (empty($whereConditions[$totalConditions][4]) || $whereConditions[$totalConditions][4] !== ')')
466-
$whereConditions[$totalConditions][4] = ')';
462+
if (!in_array(')', $whereConditions[$totalConditions]))
463+
$whereConditions[$totalConditions][count($whereConditions[$totalConditions])] = ')';
467464
}
468465

469466
return $whereConditions;
@@ -483,7 +480,7 @@ public function where(...$whereConditions)
483480
if (\is_string($whereConditions[0]) && \strpos($whereConditions[0], $whereOrHaving) !== false)
484481
return $whereConditions[0];
485482

486-
list($operator, $whereKeys, $whereValues, $combiner, $extra, $group) = $this->retrieveConditions($whereConditions);
483+
list($operator, $whereKeys, $whereValues, $combiner, $extra) = $this->retrieveConditions($whereConditions);
487484
if (empty($operator))
488485
return false;
489486

@@ -498,7 +495,7 @@ public function where(...$whereConditions)
498495
if (\in_array(\strtoupper($combine), \_COMBINERS) || isset($extra[$i]))
499496
$this->combineWith = isset($extra[$i]) ? $combine : \strtoupper($combine);
500497

501-
if ($this->processConditions($key, $isCondition, $whereValues[$i], $this->combineWith, $extra[$i], $group[$i]) === false)
498+
if ($this->processConditions($key, $isCondition, $whereValues[$i], $this->combineWith, $extra[$i]) === false)
502499
return false;
503500

504501
$i++;

tests/pdo/pdo_sqliteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testWhereGroup()
233233
$i = $i + 2;
234234
}
235235

236-
$this->assertEquals(0, $this->object->query('DROP TABLE unit_test'));
236+
$this->assertEquals(1, $this->object->query('DROP TABLE unit_test'));
237237
}
238238

239239
public function testJoins()

0 commit comments

Comments
 (0)