/** * @dataProvider getBogusFilters * @group Core */ public function testBogusFiltersExpectExceptionThrown($bogus) { try { $segment = new SegmentExpression($bogus); $segment->parseSubExpressions(); $segment->getSql(); } catch (Exception $e) { return; } $this->fail('Expected exception not raised for:' . var_export($segment->getSql(), true)); }
/** * 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"`. * @return string The entire select query. */ public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false) { if (!is_array($from)) { $from = array($from); } if (!$this->isEmpty()) { $this->segment->parseSubExpressionsIntoSqlExpressions($from); $joins = $this->generateJoins($from); $from = $joins['sql']; $joinWithSubSelect = $joins['joinWithSubSelect']; $segmentSql = $this->segment->getSql(); $segmentWhere = $segmentSql['where']; if (!empty($segmentWhere)) { if (!empty($where)) { $where = "( {$where} )\n\t\t\t\tAND\n\t\t\t\t({$segmentWhere})"; } else { $where = $segmentWhere; } } $bind = array_merge($bind, $segmentSql['bind']); } else { $joins = $this->generateJoins($from); $from = $joins['sql']; $joinWithSubSelect = $joins['joinWithSubSelect']; } if ($joinWithSubSelect) { $sql = $this->buildWrappedSelectQuery($select, $from, $where, $orderBy, $groupBy); } else { $sql = $this->buildSelectQuery($select, $from, $where, $orderBy, $groupBy); } return array('sql' => $sql, 'bind' => $bind); }