/**
  * @task internal
  */
 private function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->pathIDs) {
         $path_clauses = array();
         $repo_info = igroup($this->pathIDs, 'repositoryID');
         foreach ($repo_info as $repository_id => $paths) {
             $path_clauses[] = qsprintf($conn_r, '(p.repositoryID = %d AND p.pathID IN (%Ld))', $repository_id, ipull($paths, 'pathID'));
         }
         $path_clauses = '(' . implode(' OR ', $path_clauses) . ')';
         $where[] = $path_clauses;
     }
     if ($this->authors) {
         $where[] = qsprintf($conn_r, 'r.authorPHID IN (%Ls)', $this->authors);
     }
     if ($this->revIDs) {
         $where[] = qsprintf($conn_r, 'r.id IN (%Ld)', $this->revIDs);
     }
     if ($this->repositoryPHIDs) {
         $where[] = qsprintf($conn_r, 'r.repositoryPHID IN (%Ls)', $this->repositoryPHIDs);
     }
     if ($this->commitHashes) {
         $hash_clauses = array();
         foreach ($this->commitHashes as $info) {
             list($type, $hash) = $info;
             $hash_clauses[] = qsprintf($conn_r, '(hash_rel.type = %s AND hash_rel.hash = %s)', $type, $hash);
         }
         $hash_clauses = '(' . implode(' OR ', $hash_clauses) . ')';
         $where[] = $hash_clauses;
     }
     if ($this->phids) {
         $where[] = qsprintf($conn_r, 'r.phid IN (%Ls)', $this->phids);
     }
     if ($this->branches) {
         $where[] = qsprintf($conn_r, 'r.branchName in (%Ls)', $this->branches);
     }
     if ($this->arcanistProjectPHIDs) {
         $where[] = qsprintf($conn_r, 'r.arcanistProjectPHID in (%Ls)', $this->arcanistProjectPHIDs);
     }
     switch ($this->status) {
         case self::STATUS_ANY:
             break;
         case self::STATUS_OPEN:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', DifferentialRevisionStatus::getOpenStatuses());
             break;
         case self::STATUS_NEEDS_REVIEW:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', array(ArcanistDifferentialRevisionStatus::NEEDS_REVIEW));
             break;
         case self::STATUS_NEEDS_REVISION:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', array(ArcanistDifferentialRevisionStatus::NEEDS_REVISION));
             break;
         case self::STATUS_ACCEPTED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', array(ArcanistDifferentialRevisionStatus::ACCEPTED));
             break;
         case self::STATUS_CLOSED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', DifferentialRevisionStatus::getClosedStatuses());
             break;
         case self::STATUS_ABANDONED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ld)', array(ArcanistDifferentialRevisionStatus::ABANDONED));
             break;
         default:
             throw new Exception("Unknown revision status filter constant '{$this->status}'!");
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
 /**
  * @task internal
  */
 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->pathIDs) {
         $path_clauses = array();
         $repo_info = igroup($this->pathIDs, 'repositoryID');
         foreach ($repo_info as $repository_id => $paths) {
             $path_clauses[] = qsprintf($conn_r, '(p.repositoryID = %d AND p.pathID IN (%Ld))', $repository_id, ipull($paths, 'pathID'));
         }
         $path_clauses = '(' . implode(' OR ', $path_clauses) . ')';
         $where[] = $path_clauses;
     }
     if ($this->authors) {
         $where[] = qsprintf($conn_r, 'r.authorPHID IN (%Ls)', $this->authors);
     }
     if ($this->revIDs) {
         $where[] = qsprintf($conn_r, 'r.id IN (%Ld)', $this->revIDs);
     }
     if ($this->repositoryPHIDs) {
         $where[] = qsprintf($conn_r, 'r.repositoryPHID IN (%Ls)', $this->repositoryPHIDs);
     }
     if ($this->commitHashes) {
         $hash_clauses = array();
         foreach ($this->commitHashes as $info) {
             list($type, $hash) = $info;
             $hash_clauses[] = qsprintf($conn_r, '(hash_rel.type = %s AND hash_rel.hash = %s)', $type, $hash);
         }
         $hash_clauses = '(' . implode(' OR ', $hash_clauses) . ')';
         $where[] = $hash_clauses;
     }
     if ($this->commitPHIDs) {
         $where[] = qsprintf($conn_r, 'commits.commitPHID IN (%Ls)', $this->commitPHIDs);
     }
     if ($this->phids) {
         $where[] = qsprintf($conn_r, 'r.phid IN (%Ls)', $this->phids);
     }
     if ($this->branches) {
         $where[] = qsprintf($conn_r, 'r.branchName in (%Ls)', $this->branches);
     }
     if ($this->updatedEpochMin !== null) {
         $where[] = qsprintf($conn_r, 'r.dateModified >= %d', $this->updatedEpochMin);
     }
     if ($this->updatedEpochMax !== null) {
         $where[] = qsprintf($conn_r, 'r.dateModified <= %d', $this->updatedEpochMax);
     }
     // NOTE: Although the status constants are integers in PHP, the column is a
     // string column in MySQL, and MySQL won't use keys on string columns if
     // you put integers in the query.
     switch ($this->status) {
         case self::STATUS_ANY:
             break;
         case self::STATUS_OPEN:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', DifferentialRevisionStatus::getOpenStatuses());
             break;
         case self::STATUS_NEEDS_REVIEW:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', array(ArcanistDifferentialRevisionStatus::NEEDS_REVIEW));
             break;
         case self::STATUS_NEEDS_REVISION:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', array(ArcanistDifferentialRevisionStatus::NEEDS_REVISION));
             break;
         case self::STATUS_ACCEPTED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', array(ArcanistDifferentialRevisionStatus::ACCEPTED));
             break;
         case self::STATUS_CLOSED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', DifferentialRevisionStatus::getClosedStatuses());
             break;
         case self::STATUS_ABANDONED:
             $where[] = qsprintf($conn_r, 'r.status IN (%Ls)', array(ArcanistDifferentialRevisionStatus::ABANDONED));
             break;
         default:
             throw new Exception(pht("Unknown revision status filter constant '%s'!", $this->status));
     }
     $where[] = $this->buildWhereClauseParts($conn_r);
     return $this->formatWhereClause($where);
 }