You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @param string|null $op If give this param will build one WrapExpressions include the stored expressions add into WHERE. Otherwise will stored the expressions into array.
* make wrap when build the SQL expressions of WHERE.
697
732
* @param string $op If give this param will build one WrapExpressions include the stored expressions add into WHERE. Otherwise will stored the expressions into array.
698
733
* @return ActiveRecord
699
734
*/
700
-
publicfunctionwrap(?string$op = null)
735
+
publicfunctionendWrap(string$op): self
701
736
{
702
-
if ($op !== null) {
703
-
$this->wrap = false;
704
-
if (is_array($this->expressions) && count($this->expressions) > 0) {
705
-
$this->addConditionGroup(newWrapExpressions([
706
-
'delimiter' => '',
707
-
'target' => $this->expressions
708
-
]), 'or' === strtolower($op) ? 'OR' : 'AND');
709
-
}
710
-
$this->expressions = [];
711
-
} else {
712
-
$this->wrap = true;
737
+
$this->wrap = false;
738
+
if (is_array($this->wrapExpressions) === true && count($this->wrapExpressions) > 0) {
739
+
$this->addCondition(newWrapExpressions([
740
+
'delimiter' => ('or' === strtolower($op) ? ' OR ' : ' AND '),
741
+
'target' => $this->wrapExpressions
742
+
]), null, null);
713
743
}
744
+
$this->wrapExpressions = [];
714
745
return$this;
715
746
}
716
747
748
+
717
749
/**
718
750
* helper function to build place holder when making SQL expressions.
719
751
* @param mixed $value the value will bind to SQL, just store it in $this->params.
@@ -738,25 +770,31 @@ protected function filterParam($value)
738
770
/**
739
771
* helper function to add condition into WHERE.
740
772
* create the SQL Expressions.
741
-
* @param string $field The field name, the source of Expressions
742
-
* @param string $operator
773
+
* @param string|Expressions $field The field name, the source of Expressions
774
+
* @param ?string $operator
743
775
* @param mixed $value the target of the Expressions
744
776
* @param string $delimiter the operator to concat this Expressions into WHERE or SET statement.
745
777
* @param string $name The Expression will contact to.
$this->assertStringContainsString('SELECT "user".* FROM "user" WHERE "user"."id" IS NOT NULL AND "user"."id" = 1 AND "user"."id" < 2 AND "user"."id" > 0', $sql);
238
+
$this->assertStringContainsString('SELECT "user".* FROM "user" WHERE "user"."id" IS NOT NULL AND "user"."id" = 1 AND "user"."id" < 2 AND "user"."id" > 0', $sql);
$this->assertEquals('SELECT "user".* FROM "user" WHERE "user"."name" IS NOT NULL AND ("user"."name" = :ph1 OR "user"."id" = 1 OR "user"."password" >= :ph2) AND "user"."id" = 2 LIMIT 1', $sql);
$this->assertEquals('SELECT "user".* FROM "user" LEFT JOIN contact ON "contact"."user_id" = "user"."id" WHERE ("user"."name" = :ph1 OR "user"."id" IN (:ph2,:ph3,:ph4) OR "user"."id" = 1) AND "user"."name" IS NOT NULL AND "user"."id" BETWEEN :ph5 AND :ph6 LIMIT 1', $sql);
$this->assertEquals('SELECT test_table.* FROM test_table LEFT JOIN table1 ON table1.some_id = test_table.id LEFT JOIN table2 ON table2.some_id = table1.id LIMIT 1', $result);
151
+
$this->assertEquals('SELECT test_table.* FROM test_table LEFT JOIN table1 ON table1.some_id = test_table.id LEFT JOIN table2 ON table2.some_id = table1.id LIMIT 1', $result);
0 commit comments