示例#1
0
 /**
  * Extend an SQL query that aggregates data over one of the 'log_' tables with segment expressions.
  *
  * @param string $select The select clause. Should NOT include the **SELECT** just the columns, eg,
  *                       `'t1.col1 as col1, t2.col2 as col2'`.
  * @param array $from Array of table names (without prefix), eg, `array('log_visit', 'log_conversion')`.
  * @param false|string $where (optional) Where clause, eg, `'t1.col1 = ? AND t2.col2 = ?'`.
  * @param array|string $bind (optional) Bind parameters, eg, `array($col1Value, $col2Value)`.
  * @param false|string $orderBy (optional) Order by clause, eg, `"t1.col1 ASC"`.
  * @param false|string $groupBy (optional) Group by clause, eg, `"t2.col2"`.
  * @param int $limit Limit number of result to $limit
  * @param int $offset Specified the offset of the first row to return
  * @param int If set to value >= 1 then the Select query (and All inner queries) will be LIMIT'ed by this value.
  *              Use only when you're not aggregating or it will sample the data.
  * @return string The entire select query.
  */
 public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false, $limit = 0, $offset = 0)
 {
     $segmentExpression = $this->segmentExpression;
     if ($offset > 0) {
         $limit = (int) $offset . ', ' . (int) $limit;
     }
     return $this->segmentQueryBuilder->getSelectQueryString($segmentExpression, $select, $from, $where, $bind, $groupBy, $orderBy, $limit);
 }
示例#2
0
 public function getSelectQueryString(SegmentExpression $segmentExpression, $select, $from, $where, $bind, $groupBy, $orderBy, $limit)
 {
     $result = parent::getSelectQueryString($segmentExpression, $select, $from, $where, $bind, $groupBy, $orderBy, $limit);
     $prefixParts = array();
     if (SettingsServer::isArchivePhpTriggered()) {
         $prefixParts[] = 'trigger = CronArchive';
     }
     $idSegments = $this->getSegmentIdOfExpression($segmentExpression);
     if (!empty($idSegments)) {
         $prefixParts[] = "idSegments = [" . implode(', ', $idSegments) . "]";
     }
     if (!empty($prefixParts)) {
         $result['sql'] = "/* " . implode(', ', $prefixParts) . " */\n" . $result['sql'];
     }
     return $result;
 }