-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select: Add support for locking clauses #55
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,8 @@ public function assembleSelect(Select $select, array &$values = []) | |
$this->buildGroupBy($select->getGroupBy(), $values), | ||
$this->buildHaving($select->getHaving(), $values), | ||
$this->buildOrderBy($select->getOrderBy(), $values), | ||
$this->buildLimitOffset($select->getLimit(), $select->getOffset()) | ||
$this->buildLimitOffset($select->getLimit(), $select->getOffset()), | ||
$this->buildFor($select->getFor()) | ||
]); | ||
|
||
$sql = implode($this->separator, $sql); | ||
|
@@ -684,6 +685,24 @@ public function buildLimitOffset($limit = null, $offset = null) | |
return implode($this->separator, $sql); | ||
} | ||
|
||
/** | ||
* Build the locking clause of a query | ||
* | ||
* @param ?string $lockStrength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find the ANSI-SQL definition, but read that this is defined in ANSI-SQL (to an extent, of course). Here is what I found about the implementation in our supported databases:
Because of the different implementations, I would say |
||
* | ||
* @return string | ||
*/ | ||
public function buildFor($lockStrength) | ||
{ | ||
$sql = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just |
||
|
||
if (! empty($lockStrength)) { | ||
$sql[] = "FOR $lockStrength"; | ||
} | ||
|
||
return implode($this->separator, $sql); | ||
} | ||
|
||
/** | ||
* Build the UNION parts of a query | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ class Select implements CommonTableExpressionInterface, LimitOffsetInterface, Or | |
/** @var array|null Internal representation for the HAVING part of the query */ | ||
protected $having; | ||
|
||
/** @var string The lock strength applied by the query */ | ||
protected $lockStrength; | ||
|
||
/** | ||
* The queries to UNION | ||
* | ||
|
@@ -352,6 +355,30 @@ public function orNotHaving($condition, $operator = Sql::ALL) | |
return $this; | ||
} | ||
|
||
/** | ||
* Get the lock strength applied by the query | ||
* | ||
* @return string | ||
*/ | ||
public function getFor() | ||
{ | ||
return $this->lockStrength; | ||
} | ||
|
||
/** | ||
* Set a lock strength to be applied by the query | ||
* | ||
* @param string $lockStrength | ||
* | ||
* @return self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
*/ | ||
public function for($lockStrength) | ||
{ | ||
$this->lockStrength = $lockStrength; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the UNION parts of the query | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just
string
here?