/** * @dataProvider getBogusFilters * @group Core * @group SegmentExpression */ public function testBogusFiltersExpectExceptionThrown($bogus) { try { $segment = new Piwik_SegmentExpression($bogus); $segment->parseSubExpressions(); $segment->getSql(); } catch (Exception $e) { return; } $this->fail('Expected exception not raised'); }
public function test_bogusFilters_expectExceptionThrown() { $boguses = array('A=B', 'C!D', '', ' ', ',;,', ',', ',,', '===', '!='); foreach ($boguses as $bogus) { $segment = new Piwik_SegmentExpression($bogus); try { $segment->parseSubExpressions(); $processed = $segment->getSql(); $this->fail('expecting exception ' . $bogus); } catch (Exception $e) { $this->pass(); } } }
/** * Extend SQL query with segment expressions * * @param string select clause * @param array of table names (without prefix) * @param string where clause * @param string (optional) order by clause * @param string (optional) group by clause * @return string entire select query */ public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false) { $joinWithSubSelect = 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); //var_dump($return); return $return; }
public function getSql() { if ($this->isEmpty()) { return array('sql' => '', 'bind' => array()); } $this->segment->parseSubExpressionsIntoSqlExpressions(); return $this->segment->getSql(); }
public function getSql( $fieldsAvailableInTable = array(), $joinedTableName = false) { if($this->isEmpty()) { return array('sql' => '', 'bind' => array(), 'sql_join_visits' => ''); } $this->segment->parseSubExpressionsIntoSqlExpressions($fieldsAvailableInTable, $joinedTableName); $return = $this->segment->getSql(); $return['sql_join_visits'] = ''; if(!empty($fieldsAvailableInTable)) { if(!$this->isSegmentAvailable($fieldsAvailableInTable)) { $return['sql_join_visits'] = "LEFT JOIN ".Piwik_Common::prefixTable('log_visit')." AS log_visit USING(idvisit)"; } } return $return; }