Skip to content

Commit 30dde6b

Browse files
committed
update docs, and wording, code clean up
1 parent e30b76b commit 30dde6b

File tree

4 files changed

+123
-112
lines changed

4 files changed

+123
-112
lines changed

README.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ ___General Methods___
4646
to_string($arrays, $separation = ',');
4747
clean($string);
4848
create_cache(string $path = null);
49-
secureSetup($key = 'certificate.key',
50-
$cert = 'certificate.crt',
51-
$ca = 'cacert.pem',
52-
$path = '.'._DS
49+
secureSetup(string $key = 'certificate.key',
50+
string $cert = 'certificate.crt',
51+
string $ca = 'cacert.pem',
52+
string $path = '.'._DS
5353
);
5454
secureReset();
5555
createCertificate(string $privatekeyFile = certificate.key,
@@ -62,7 +62,7 @@ ___Shortcut Table Methods___
6262

6363
create(string $table = null, ...$schemas);// $schemas requires... column()
6464
column(string $column = null, string $type = null, ...$args);
65-
primary(string $constraintName, ...$primaryKeys);
65+
primary(string $primaryName, ...$primaryKeys);
6666
index(string $indexName, ...$indexKeys);
6767
drop(string $table);
6868
Example
@@ -108,15 +108,38 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou
108108
* `unionAll(string $table = null, $columnFields = '*', ...$conditions);`
109109
* `orderBy($orderBy, $order);`
110110
* `limit($numberOf, $offset = null)`
111-
* `where( ...$whereKeyArray);`
111+
* `where( ...$whereConditions);`
112112
* `selecting(string $table = null, $columnFields = '*', ...$conditions);`
113-
* `create_select(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere);`
114-
* `select_into(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere);`
115-
* `update(string $table = null, $keyAndValue, ...$whereKeys);`
116-
* `delete(string $table = null, ...$whereKeys);`
113+
* `create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`
114+
* `select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions);`
115+
* `update(string $table = null, $keyAndValue, ...$whereConditions);`
116+
* `delete(string $table = null, ...$whereConditions);`
117117
* `replace(string $table = null, $keyAndValue);`
118118
* `insert(string $table = null, $keyAndValue);`
119-
* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere);`
119+
* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions);`
120+
121+
```php
122+
// The variadic ...$whereConditions, and ..$conditions parameters,
123+
// represent the following global functions.
124+
// They are comparison expressions returning an array with the given arguments,
125+
// the last arguments of _AND, _OR, _NOT, _andNOT will combine expressions
126+
eq('key/Field/Column', $value, _AND), // combine next expression
127+
neq('key/Field/Column', $value, _OR), // will combine next expression again
128+
ne('key/Field/Column', $value)
129+
lt('key/Field/Column', $value)
130+
lte('key/Field/Column', $value)
131+
gt('key/Field/Column', $value)
132+
gte('key/Field/Column', $value)
133+
isNull('key/Field/Column')
134+
isNotNull('key/Field/Column')
135+
like('key/Field/Column', '_%')
136+
notLike('key/Field/Column', '_%')
137+
in('key/Field/Column', $value)
138+
notIn('key/Field/Column', $value)
139+
between('key/Field/Column', $value, $value2)
140+
notBetween('key/Field/Column', $value, $value2)
141+
// The above should be used within the where( ...$whereConditions) clause
142+
```
120143

121144
```php
122145
// Supply the the whole query string, and placing '?' within
@@ -140,17 +163,8 @@ $values['phone'] = $number;
140163
$db->insert('profile', $values);
141164
$db->insert('profile', ['name' => 'john john', 'email' => 'john@email', 'phone' => 123456]);
142165

143-
// returns result set given the table name, column fields, and ...conditionals
144-
$result = $db->selecting('profile', 'phone',
145-
// ...conditionals are comparison operators($column, $value, _COMBINE_EXPRESSION_CONSTANTS)
146-
// these operators are functions returning arrays:
147-
// eq(), neq(), ne(), lt(), lte(),
148-
// gt(), gte(), isNull(), isNotNull(),
149-
// like(), notLike(), in(), notIn(), between(), notBetween(),
150-
// _COMBINE_EXPRESSION_CONSTANTS:
151-
// _AND, _OR, _NOT, _andNOT
152-
eq('email', $email, _AND), neq('id', 1)
153-
);
166+
// returns result set given the table name, column fields, and ...conditions
167+
$result = $db->selecting('profile', 'phone', eq('email', $email, _AND), neq('id', 1));
154168

155169
foreach ($result as $row) {
156170
echo $row->phone;

lib/ezFunctions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ function column(string $column = null, string $type = null, ...$args)
6060
return ezSchema::column($column, $type, ...$args);
6161
}
6262

63-
function primary(string $constraintName, ...$primaryKeys)
63+
function primary(string $primaryName, ...$primaryKeys)
6464
{
6565
array_unshift($primaryKeys, \PRIMARY);
66-
return \column(\CONSTRAINT, $constraintName, ...$primaryKeys);
66+
return \column(\CONSTRAINT, $primaryName, ...$primaryKeys);
6767
}
6868

69-
function foreign(string $constraintName, ...$foreignKeys)
69+
function foreign(string $foreignName, ...$foreignKeys)
7070
{
7171
array_unshift($foreignKeys, \FOREIGN);
72-
return \column(\CONSTRAINT, $constraintName, ...$foreignKeys);
72+
return \column(\CONSTRAINT, $foreignName, ...$foreignKeys);
7373
}
7474

75-
function unique(string $constraintName, ...$uniqueKeys)
75+
function unique(string $uniqueName, ...$uniqueKeys)
7676
{
7777
array_unshift($uniqueKeys, \UNIQUE);
78-
return \column(\CONSTRAINT, $constraintName, ...$uniqueKeys);
78+
return \column(\CONSTRAINT, $uniqueName, ...$uniqueKeys);
7979
}
8080

8181
function index(string $indexName, ...$indexKeys)

lib/ezQuery.php

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -292,102 +292,99 @@ public function limit($numberOf, $offset = null)
292292
return 'LIMIT '.$rows.$value;
293293
}
294294

295-
public function where( ...$whereKeyArray)
295+
public function where( ...$whereConditions)
296296
{
297-
if (empty($whereKeyArray))
297+
if (empty($whereConditions))
298298
return false;
299299

300300
$whereOrHaving = ($this->isWhere) ? 'WHERE' : 'HAVING';
301301
$this->isWhere = true;
302302

303-
$whereKey = [];
303+
$whereClause = [];
304304
$operator = [];
305305
$extra = [];
306306
$combiner = [];
307307
$combineWith = '';
308-
if (\is_string($whereKeyArray[0])) {
309-
if ((\strpos($whereKeyArray[0], 'WHERE') !== false)
310-
|| (\strpos($whereKeyArray[0], 'HAVING') !== false)
308+
309+
$storeWhereConditions = $whereConditions;
310+
if (\is_string($whereConditions[0])) {
311+
if ((\strpos($whereConditions[0], 'WHERE') !== false)
312+
|| (\strpos($whereConditions[0], 'HAVING') !== false)
311313
)
312-
return $whereKeyArray[0];
314+
return $whereConditions[0];
313315

314-
foreach ($whereKeyArray as $makeArray)
315-
$whereKeys[] = \explode(' ', $makeArray);
316-
} else
317-
$whereKeys = $whereKeyArray;
316+
$storeWhereConditions = [];
317+
foreach ($whereConditions as $makeWhereArray)
318+
$storeWhereConditions[] = \explode(' ', $makeWhereArray);
319+
}
318320

319-
foreach ($whereKeys as $values) {
320-
$operator[] = (isset($values[1])) ? $values[1]: '';
321-
if (!empty($values[1])){
322-
if (\strtoupper($values[1]) == 'IN') {
323-
$whereKey[ $values[0] ] = \array_slice((array) $values, 2);
324-
$combiner[] = (isset($values[3])) ? $values[3]: \_AND;
325-
$extra[] = (isset($values[4])) ? $values[4]: null;
326-
} else {
327-
$whereKey[ (isset($values[0])) ? $values[0] : '1' ] = (isset($values[2])) ? $values[2] : '' ;
328-
$combiner[] = (isset($values[3])) ? $values[3]: \_AND;
329-
$extra[] = (isset($values[4])) ? $values[4]: null;
330-
}
331-
} else {
321+
foreach ($storeWhereConditions as $checkFields) {
322+
$operator[] = (isset($checkFields[1])) ? $checkFields[1]: '';
323+
if (empty($checkFields[1]))
332324
return $this->clearPrepare();
333-
}
325+
326+
if (\strtoupper($checkFields[1]) == 'IN') {
327+
$whereClause[ $checkFields[0] ] = \array_slice((array) $checkFields, 2);
328+
$combiner[] = (isset($checkFields[3])) ? $checkFields[3]: \_AND;
329+
$extra[] = (isset($checkFields[4])) ? $checkFields[4]: null;
330+
} else {
331+
$whereClause[ (isset($checkFields[0])) ? $checkFields[0] : '1' ] = (isset($checkFields[2])) ? $checkFields[2] : '' ;
332+
$combiner[] = (isset($checkFields[3])) ? $checkFields[3]: \_AND;
333+
$extra[] = (isset($checkFields[4])) ? $checkFields[4]: null;
334+
}
334335
}
335336

336337
$where = '1';
337-
if (! isset($whereKey['1'])) {
338+
if (! isset($whereClause['1'])) {
338339
$where = '';
339340
$i = 0;
340-
foreach($whereKey as $key => $val) {
341+
foreach($whereClause as $key => $val) {
341342
$isCondition = \strtoupper($operator[$i]);
342343
$combine = $combiner[$i];
344+
$combineWith = \_AND;
343345
if ( \in_array(\strtoupper($combine), \_COMBINERS) || isset($extra[$i]))
344346
$combineWith = (isset($extra[$i])) ? $combine : \strtoupper($combine);
345-
else
346-
$combineWith = \_AND;
347347

348-
if (! \in_array( $isCondition, \_BOOLEAN_OPERATORS)) {
348+
if (! \in_array( $isCondition, \_BOOLEAN_OPERATORS))
349349
return $this->clearPrepare();
350-
} else {
351-
if (($isCondition == \_BETWEEN) || ($isCondition == \_notBETWEEN)) {
352-
$value = $this->escape($combineWith);
353-
if (\in_array(\strtoupper($extra[$i]), \_COMBINERS))
354-
$myCombineWith = \strtoupper($extra[$i]);
355-
else
356-
$myCombineWith = \_AND;
357350

358-
if ($this->isPrepareOn()) {
359-
$where .= "$key ".$isCondition.' '.\_TAG." AND ".\_TAG." $myCombineWith ";
360-
$this->addPrepare($val);
361-
$this->addPrepare($combineWith);
362-
} else
363-
$where .= "$key ".$isCondition." '".$this->escape($val)."' AND '".$value."' $myCombineWith ";
351+
if (($isCondition == \_BETWEEN) || ($isCondition == \_notBETWEEN)) {
352+
$value = $this->escape($combineWith);
353+
$myCombineWith = \_AND;
354+
if (\in_array(\strtoupper($extra[$i]), \_COMBINERS))
355+
$myCombineWith = \strtoupper($extra[$i]);
356+
357+
if ($this->isPrepareOn()) {
358+
$where .= "$key ".$isCondition.' '.\_TAG." AND ".\_TAG." $myCombineWith ";
359+
$this->addPrepare($val);
360+
$this->addPrepare($combineWith);
361+
} else
362+
$where .= "$key ".$isCondition." '".$this->escape($val)."' AND '".$value."' $myCombineWith ";
364363

365-
$combineWith = $myCombineWith;
366-
} elseif ($isCondition == \_IN) {
367-
$value = '';
368-
foreach ($val as $inValues) {
369-
if ($this->isPrepareOn()) {
370-
$value .= \_TAG.', ';
371-
$this->addPrepare($inValues);
372-
} else
373-
$value .= "'".$this->escape($inValues)."', ";
374-
}
375-
$where .= "$key ".$isCondition." ( ".\rtrim($value, ', ')." ) $combineWith ";
376-
} elseif (((\strtolower($val) == 'null') || ($isCondition == 'IS') || ($isCondition == 'IS NOT'))) {
377-
$isCondition = (($isCondition == 'IS') || ($isCondition == 'IS NOT')) ? $isCondition : 'IS';
378-
$where .= "$key ".$isCondition." NULL $combineWith ";
379-
} elseif ((($isCondition == \_LIKE) || ($isCondition == \_notLIKE)) && ! \preg_match('/[_%?]/', $val)) {
380-
return $this->clearPrepare();
381-
} else {
364+
$combineWith = $myCombineWith;
365+
} elseif ($isCondition == \_IN) {
366+
$value = '';
367+
foreach ($val as $inValues) {
382368
if ($this->isPrepareOn()) {
383-
$where .= "$key ".$isCondition.' '.\_TAG." $combineWith ";
384-
$this->addPrepare($val);
369+
$value .= \_TAG.', ';
370+
$this->addPrepare($inValues);
385371
} else
386-
$where .= "$key ".$isCondition." '".$this->escape($val)."' $combineWith ";
387-
}
388-
389-
$i++;
390-
}
372+
$value .= "'".$this->escape($inValues)."', ";
373+
}
374+
$where .= "$key ".$isCondition." ( ".\rtrim($value, ', ')." ) $combineWith ";
375+
} elseif (((\strtolower($val) == 'null') || ($isCondition == 'IS') || ($isCondition == 'IS NOT'))) {
376+
$isCondition = (($isCondition == 'IS') || ($isCondition == 'IS NOT')) ? $isCondition : 'IS';
377+
$where .= "$key ".$isCondition." NULL $combineWith ";
378+
} elseif ((($isCondition == \_LIKE) || ($isCondition == \_notLIKE)) && ! \preg_match('/[_%?]/', $val)) {
379+
return $this->clearPrepare();
380+
} else {
381+
if ($this->isPrepareOn()) {
382+
$where .= "$key ".$isCondition.' '.\_TAG." $combineWith ";
383+
$this->addPrepare($val);
384+
} else
385+
$where .= "$key ".$isCondition." '".$this->escape($val)."' $combineWith ";
386+
}
387+
$i++;
391388
}
392389
$where = \rtrim($where, " $combineWith ");
393390
}
@@ -507,15 +504,15 @@ public function unionAll(string $table = null, $columnFields = '*', ...$conditio
507504
return 'UNION ALL '.$this->select_sql($table, $columnFields, ...$conditions);
508505
}
509506

510-
public function create_select(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere)
507+
public function create_select(string $newTable, $fromColumns, $oldTable = null, ...$conditions)
511508
{
512509
if (isset($oldTable))
513510
$this->fromTable = $oldTable;
514511
else {
515512
return $this->clearPrepare();
516513
}
517514

518-
$newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$fromWhere);
515+
$newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$conditions);
519516
if (is_string($newTableFromTable))
520517
return (($this->isPrepareOn()) && !empty($this->prepareValues()))
521518
? $this->query($newTableFromTable, true)
@@ -524,15 +521,15 @@ public function create_select(string $newTable, $fromColumns, $oldTable = null,
524521
return $this->clearPrepare();
525522
}
526523

527-
public function select_into(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere)
524+
public function select_into(string $newTable, $fromColumns, $oldTable = null, ...$conditions)
528525
{
529526
$this->isInto = true;
530527
if (isset($oldTable))
531528
$this->fromTable = $oldTable;
532529
else
533530
return $this->clearPrepare();
534531

535-
$newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$fromWhere);
532+
$newTableFromTable = $this->select_sql($newTable, $fromColumns, ...$conditions);
536533
if (is_string($newTableFromTable))
537534
return (($this->isPrepareOn()) && !empty($this->prepareValues()))
538535
? $this->query($newTableFromTable, true)
@@ -541,7 +538,7 @@ public function select_into(string $newTable, $fromColumns, $oldTable = null, ..
541538
return $this->clearPrepare();
542539
}
543540

544-
public function update(string $table = null, $keyAndValue, ...$whereKeys)
541+
public function update(string $table = null, $keyAndValue, ...$whereConditions)
545542
{
546543
if ( ! is_array( $keyAndValue ) || empty($table) ) {
547544
return $this->clearPrepare();
@@ -563,7 +560,7 @@ public function update(string $table = null, $keyAndValue, ...$whereKeys)
563560
}
564561
}
565562

566-
$where = $this->where(...$whereKeys);
563+
$where = $this->where(...$whereConditions);
567564
if (\is_string($where)) {
568565
$sql = \rtrim($sql, ', ') . $where;
569566
return (($this->isPrepareOn()) && !empty($this->prepareValues()))
@@ -574,15 +571,15 @@ public function update(string $table = null, $keyAndValue, ...$whereKeys)
574571
return $this->clearPrepare();
575572
}
576573

577-
public function delete(string $table = null, ...$whereKeys)
574+
public function delete(string $table = null, ...$whereConditions)
578575
{
579576
if ( empty($table) ) {
580577
return $this->clearPrepare();
581578
}
582579

583580
$sql = "DELETE FROM $table";
584581

585-
$where = $this->where(...$whereKeys);
582+
$where = $this->where(...$whereConditions);
586583
if (\is_string($where)) {
587584
$sql .= $where;
588585
return (($this->isPrepareOn()) && !empty($this->prepareValues()))
@@ -664,10 +661,10 @@ public function insert(string $table = null, $keyAndValue)
664661
return $this->_query_insert_replace($table, $keyAndValue, 'INSERT');
665662
}
666663

667-
public function insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere)
664+
public function insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions)
668665
{
669666
$putToTable = $this->_query_insert_replace($toTable, $toColumns, 'INSERT', false);
670-
$getFromTable = $this->select_sql($fromTable, $fromColumns, ...$fromWhere);
667+
$getFromTable = $this->select_sql($fromTable, $fromColumns, ...$conditions);
671668

672669
if (\is_string($putToTable) && \is_string($getFromTable))
673670
return (($this->isPrepareOn()) && !empty($this->prepareValues()))

0 commit comments

Comments
 (0)