Update many Phabricator queries for new %Q query semantics
Summary: Depends on D19785. Ref T13217. This converts many of the most common clause construction pathways to the new %Q / %LQ / %LO / %LA / %LJ semantics. Test Plan: Browsed around a bunch, saw fewer warnings and no obvious behavioral errors. The transformations here are generally mechanical (although I did them by hand). Reviewers: amckinley Reviewed By: amckinley Subscribers: hach-que Maniphest Tasks: T13217 Differential Revision: https://secure.phabricator.com/D19789
This commit is contained in:
@@ -27,15 +27,15 @@ abstract class PhabricatorOffsetPagedQuery extends PhabricatorQuery {
|
||||
return $this->limit;
|
||||
}
|
||||
|
||||
protected function buildLimitClause(AphrontDatabaseConnection $conn_r) {
|
||||
protected function buildLimitClause(AphrontDatabaseConnection $conn) {
|
||||
if ($this->limit && $this->offset) {
|
||||
return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, $this->limit);
|
||||
return qsprintf($conn, 'LIMIT %d, %d', $this->offset, $this->limit);
|
||||
} else if ($this->limit) {
|
||||
return qsprintf($conn_r, 'LIMIT %d', $this->limit);
|
||||
return qsprintf($conn, 'LIMIT %d', $this->limit);
|
||||
} else if ($this->offset) {
|
||||
return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
|
||||
return qsprintf($conn, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
|
||||
} else {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,28 +15,19 @@ abstract class PhabricatorQuery extends Phobject {
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatWhereClause(array $parts) {
|
||||
protected function formatWhereClause(
|
||||
AphrontDatabaseConnection $conn,
|
||||
array $parts) {
|
||||
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
|
||||
return 'WHERE '.$this->formatWhereSubclause($parts);
|
||||
return qsprintf($conn, 'WHERE %LA', $parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatWhereSubclause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '('.implode(') AND (', $parts).')';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
@@ -57,39 +48,32 @@ abstract class PhabricatorQuery extends Phobject {
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatJoinClause(array $parts) {
|
||||
protected function formatJoinClause(
|
||||
AphrontDatabaseConnection $conn,
|
||||
array $parts) {
|
||||
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
|
||||
return implode(' ', $parts);
|
||||
return qsprintf($conn, '%LJ', $parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatHavingClause(array $parts) {
|
||||
protected function formatHavingClause(
|
||||
AphrontDatabaseConnection $conn,
|
||||
array $parts) {
|
||||
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
|
||||
return 'HAVING '.$this->formatHavingSubclause($parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatHavingSubclause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '('.implode(') AND (', $parts).')';
|
||||
return qsprintf($conn, 'HAVING %LA', $parts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -195,15 +195,15 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
}
|
||||
}
|
||||
|
||||
final protected function buildLimitClause(AphrontDatabaseConnection $conn_r) {
|
||||
final protected function buildLimitClause(AphrontDatabaseConnection $conn) {
|
||||
if ($this->shouldLimitResults()) {
|
||||
$limit = $this->getRawResultLimit();
|
||||
if ($limit) {
|
||||
return qsprintf($conn_r, 'LIMIT %d', $limit);
|
||||
return qsprintf($conn, 'LIMIT %d', $limit);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
|
||||
protected function shouldLimitResults() {
|
||||
@@ -306,7 +306,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
*/
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$joins = $this->buildJoinClauseParts($conn);
|
||||
return $this->formatJoinClause($joins);
|
||||
return $this->formatJoinClause($conn, $joins);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
*/
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
|
||||
$where = $this->buildWhereClauseParts($conn);
|
||||
return $this->formatWhereClause($where);
|
||||
return $this->formatWhereClause($conn, $where);
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
*/
|
||||
protected function buildHavingClause(AphrontDatabaseConnection $conn) {
|
||||
$having = $this->buildHavingClauseParts($conn);
|
||||
return $this->formatHavingClause($having);
|
||||
return $this->formatHavingClause($conn, $having);
|
||||
}
|
||||
|
||||
|
||||
@@ -371,13 +371,13 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
*/
|
||||
protected function buildGroupClause(AphrontDatabaseConnection $conn) {
|
||||
if (!$this->shouldGroupQueryResultRows()) {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
|
||||
return qsprintf(
|
||||
$conn,
|
||||
'GROUP BY %Q',
|
||||
$this->getApplicationSearchObjectPHIDColumn());
|
||||
$this->getApplicationSearchObjectPHIDColumn($conn));
|
||||
}
|
||||
|
||||
|
||||
@@ -1134,7 +1134,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
}
|
||||
}
|
||||
|
||||
return qsprintf($conn, 'ORDER BY %Q', implode(', ', $sql));
|
||||
return qsprintf($conn, 'ORDER BY %LQ', $sql);
|
||||
}
|
||||
|
||||
|
||||
@@ -1244,17 +1244,18 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
* See @{method:getPrimaryTableAlias} if the column needs to be qualified with
|
||||
* a table alias.
|
||||
*
|
||||
* @return string Column name.
|
||||
* @param AphrontDatabaseConnection Connection executing queries.
|
||||
* @return PhutilQueryString Column name.
|
||||
* @task appsearch
|
||||
*/
|
||||
protected function getApplicationSearchObjectPHIDColumn() {
|
||||
if ($this->getPrimaryTableAlias()) {
|
||||
$prefix = $this->getPrimaryTableAlias().'.';
|
||||
} else {
|
||||
$prefix = '';
|
||||
}
|
||||
protected function getApplicationSearchObjectPHIDColumn(
|
||||
AphrontDatabaseConnection $conn) {
|
||||
|
||||
return $prefix.'phid';
|
||||
if ($this->getPrimaryTableAlias()) {
|
||||
return qsprintf($conn, '%T.phid', $this->getPrimaryTableAlias());
|
||||
} else {
|
||||
return qsprintf($conn, 'phid');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1308,15 +1309,15 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
* @task appsearch
|
||||
*/
|
||||
protected function buildApplicationSearchGroupClause(
|
||||
AphrontDatabaseConnection $conn_r) {
|
||||
AphrontDatabaseConnection $conn) {
|
||||
|
||||
if ($this->getApplicationSearchMayJoinMultipleRows()) {
|
||||
return qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'GROUP BY %Q',
|
||||
$this->getApplicationSearchObjectPHIDColumn());
|
||||
} else {
|
||||
return '';
|
||||
return qsprintf($conn, '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,7 +1411,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
}
|
||||
}
|
||||
|
||||
$phid_column = $this->getApplicationSearchObjectPHIDColumn();
|
||||
$phid_column = $this->getApplicationSearchObjectPHIDColumn($conn);
|
||||
$orderable = $this->getOrderableColumns();
|
||||
|
||||
$vector = $this->getOrderVector();
|
||||
@@ -2373,7 +2374,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
*/
|
||||
public function buildEdgeLogicJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$edge_table = PhabricatorEdgeConfig::TABLE_NAME_EDGE;
|
||||
$phid_column = $this->getApplicationSearchObjectPHIDColumn();
|
||||
$phid_column = $this->getApplicationSearchObjectPHIDColumn($conn);
|
||||
|
||||
$joins = array();
|
||||
foreach ($this->edgeLogicConstraints as $type => $constraints) {
|
||||
@@ -2531,9 +2532,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
||||
}
|
||||
|
||||
if ($full && $null) {
|
||||
$full = $this->formatWhereSubclause($full);
|
||||
$null = $this->formatWhereSubclause($null);
|
||||
$where[] = qsprintf($conn, '(%Q OR %Q)', $full, $null);
|
||||
$where[] = qsprintf($conn, '(%LA OR %LA)', $full, $null);
|
||||
} else if ($full) {
|
||||
foreach ($full as $condition) {
|
||||
$where[] = $condition;
|
||||
|
||||
Reference in New Issue
Block a user