Skip to content

Commit

Permalink
Updated SQL Builder so that Where() method does not need the operator…
Browse files Browse the repository at this point in the history
… (i.e. '=' is the default).
  • Loading branch information
cclark61 committed Jan 30, 2019
1 parent f843f04 commit db1f077
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/Builders/SQL/Statements/Traits/Conditions.php
Expand Up @@ -27,7 +27,7 @@ trait Conditions
// Add Condition Method
//=========================================================================
//=========================================================================
protected function AddCondition(&$conditions, $field, $op, $val, $type, $andor='and')
protected function AddCondition(&$conditions, $field, $op, $val, $type='s', $andor='and')
{
//-----------------------------------------------------------------
// Validate Parameters
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/Builders/SQL/Statements/Traits/Where.php
Expand Up @@ -37,6 +37,25 @@ trait Where
//=========================================================================
public function Where($field, $op=null, $val=false, $type='s', $andor='and')
{
if ($op && !self::IsValidOperator($op)) {
$invalid_op = true;
if (is_scalar($op) || is_array($op)) {
$invalid_op = false;
if ($type && in_array($type, ['and', 'or'])) {
$andor = $type;
}
if ($val && in_array($val, ['i', 's', 'd', 'b'])) {
$type = $val;
}
$val = $op;
$op = '=';
}

if ($invalid_op) {
throw new \Exception('Invalid operator given.');
return;
}
}
$this->AddCondition($this->wheres, $field, $op, $val, $type, $andor);
return $this;
}
Expand Down

0 comments on commit db1f077

Please sign in to comment.