For adding generic where statements

@param string $cond SQL Where condition.
@param mixed $bind optional bind values
@return \Gems_Tracker_Token_TokenSelect
514972
public function forWhere($cond, $bind = null)
    {
        $this->sql_select->where($cond, $bind);

        return $this;
    }
699244
public function query(string $sql, $bind = []): Statement
    {
        $this->operation = 'query';
        $this->params = $bind;
        $this->sql = $sql;
        return $this;
    }
540214
public function del($table, $cond=null)
	{
		$ds = $this->ds();
		$cond = SqlHelper::parse_cond($ds, $cond);
		$table = SqlHelper::qtable($table);
		
		$sql = "DELETE FROM {$table} " . (empty($cond) ? '' : "WHERE {$cond}");
		
		$result = Sql::write($ds, Sql::MODE_WRITE_DELETE, [
				$sql
			]);
		return $result;
	}
434921
static function condToUrl($cond)
    {
        $cond = self::normalizeCond($cond, [], true);
        if (is_array($cond['from'])){
            $info = parse_url(reset($cond['from']));
            $base_url = '';
            if (isset($info['scheme'])) $base_url.= $info['scheme'].'://';
            if (isset($info['host'])) $base_url.= $info['host'];
            if ($base_url_length = mb_strlen($base_url)){
                foreach ($cond['from'] as $i => $from){
                    if (mb_substr($from,0,$base_url_length) == $base_url) $cond['from'][$i] = mb_substr($from, $base_url_length);
                }
            }
        }
        //if (sizeof($cond['select']) == 1) $cond['select'] = $cond['select'][0];
        if ($cond['select'] == 'self'){
            unset($cond['select'], $cond['depth']);
        }
        unset($cond['correct']);
        foreach ($cond as $key => $c){
            if (empty($c)) unset($cond[$key]);
        }
        $url = F::toJSON($cond, false);
        $url = mb_substr($url, 1, mb_strlen($url)-2, 'UTF-8');
        $url = strtr($url, [
                         '[' => '(',
                         ']' => ')',
                         ',""]' => ',)',
                         '"="' => '"eq"',
                         '"!="' => '"ne"',
                         '">"' => '"gt"',
                         '">="' => '"gte"',
                         '"<"' => '"lt"',
                         '"<="' => '"lte"'
                    ]);
        $url = preg_replace_callback('/"([^"]*)"/ui', function($m){
                        $replacements = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
                        $escapers = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
                        return urlencode(str_replace($escapers, $replacements, $m[1]));
                    }, $url);
        $url = preg_replace('/,([a-z_]+):/ui','&$1=',$url);
        $url = preg_replace('/\(([a-z_]+),/ui','$1(',$url);
        $url = preg_replace('/\),/ui',')$1',$url);
        $url = mb_substr($url, 5, mb_strlen($url)-5);
        if (isset($base_url)){
            $url = $base_url.'?from='.$url;
        }else{
            $info = explode('&', $url, 2);
            if (!empty($info)){
                $url = urldecode($info[0]).'?'.$info[1];
            }
        }
        return $url;
    }
95393
public function update($table, array $row, $cond=null)
	{
		$ds = $this->ds();
		if ( empty($row) ) return false;
		
        list($pairs, $values) = SqlHelper::placeholder_pair($row);
        $pairs = implode(',', $pairs);
        
        $table = SqlHelper::qtable($table);
		
        $sql = SqlHelper::bind($ds, "UPDATE {$table} SET {$pairs}", $row);
        
        $cond = SqlHelper::parse_cond($ds, $cond);
        if ($cond) $sql .= " WHERE {$cond}";
        
        $result = Sql::write($ds, Sql::MODE_WRITE_UPDATE, [
			 $sql
		]);
		return $result;
	}
282014
protected function joinInternal($join, $table, $cond = null)
    {
        if (!$this->from) {
            throw new Exception('Cannot join() without from()');
        }

        $join                          = strtoupper(ltrim("$join JOIN"));
        $table                         = $this->quoteName($table);
        $cond                          = $this->fixJoinCondition($cond);
        $this->from[$this->from_key][] = rtrim("$join $table $cond");
        return $this;
    }
474243
public function select($table, $cond=null, $fields='*', $sort=null, $limit=null, $calc=false)
	{
		return Sql::assistant( $this->ds )->select($table, $cond, $fields, $sort, $limit, $calc);
	}
309017
public function whereExpr($expr, $bind = null)
    {
        foreach ($this->queries as $query) {
            $query->whereExpr($expr, $bind);
        }

        return $this;
    }
852771
public function join($table, $cond = null, $type = '')
    {
        return $this->joinInternal($type, $table, $cond);
    }
736525
public function leftJoin($table, $alias_or_cond, $cond = null) {
		if (is_null($cond))
			$this->joins[] = new JoinClause(JoinClause::LEFT_JOIN, $table, null, $alias_or_cond);
		else
			$this->joins[] = new JoinClause(JoinClause::LEFT_JOIN, $table, $alias_or_cond, $cond);
		return $this;
	}
326577
function insertSql($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        $this->extractAndQuoteCols($bind, $cols, $vals);
        // build the statement
        $sql = "INSERT INTO "
            . $this->wrappedAdapter->quoteIdentifier($table, true)
            . ' (' . implode(', ', $cols) . ') '
            . 'VALUES (' . implode(', ', $vals) . ')';
        return $sql;
    }
176071
public function sql(ValueBinder $generator)
    {
        $parts = [];
        $parts[] = 'CASE';
        foreach ($this->_conditions as $k => $part) {
            $value = $this->_values[$k];
            $parts[] = 'WHEN ' . $this->_compile($part, $generator) . ' THEN ' . $this->_compile($value, $generator);
        }
        if ($this->_elseValue !== null) {
            $parts[] = 'ELSE';
            $parts[] = $this->_compile($this->_elseValue, $generator);
        }
        $parts[] = 'END';

        return implode(' ', $parts);
    }
657955
public function filterBy($cond)
	{
		$select = $this->getSelect();
		$db = $this->getDb();
		$descriptors = $this->getColumns();
		$alias = $this->getAlias();

		if ( is_array($cond) )
		{
			foreach($cond as $col => $value)
			{
				if( array_find_key( $descriptors, zend_column_eq_dg( $alias, $col ) ) )
				{
					$col = "$alias.$col";
				}
				$col = $db->quoteIdentifier($col);
				if( is_array($value) )
				{
					$valueChar = '?';
					$cond2 = '=';

					if(isset($value['condition']) && isset($value['value']))
					{
						$cond2 = $value['condition'];
						$value = $value['value'];
						$valueChar = '?';
					}

					if( is_array($value) )
					{
						if( 0 === count($value) )
						{
							$select->where('TRUE=FALSE');
							return $this;
						}
						if(strpos($cond2, 'IN') === false)
						{
							$cond2 = 'IN';
						}
						$valueChar = '(?)';
					}

					$select->where($col.' '. $cond2 .' '.$valueChar, $value);
				}
				else
				{
					if( is_null($value) )
					{
						$select->where($col.' IS NULL');
					}
					elseif( $value instanceof Zend_Db_Expr )
					{
						$select->where($col.' '.$value);
					}
					else
					{
						$select->where($col.' = ?', $value);
					}
				}
			}
		}
		else
		{
			$select->where($cond);
		}

		return $this;
	}
189939
public function execute(string $sql, $bind = []): Statement
    {
        $this->operation = 'execute';
        $this->sql = $sql;
        $this->params = $bind;
        return $this;
    }
469893
public function searchOne(array $cond = array())
    {
        $options = array(
            'count' => 1,
            'offset' => 0
        );

        $result = $this->search($cond, $options);

        if ($result['total'] != 1) {
            throw new NotFoundException($result['total'] . ' matching items found');
        }

        return $result->getFirstResult();
    }
839888
public function searchAll(array $cond = array(), $order = false): array
    {
        $options = array(
            'order' => $order,
            'count' => 0,
            'offset' => 0
        );

        $result = $this->search($cond, $options);

        return $result->getAllResults();
    }
918642
public function insert($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        foreach ($bind as $col => $val) {
            $cols[] = $this->quoteIdentifier($col, true);
            if ($val instanceof Zend_Db_Expr) {
                $vals[] = $val->__toString();
                unset($bind[$col]);
            } else {
                $vals[] = '?';
            }
        }

        // build the statement
        $sql = "INSERT INTO "
             . $this->quoteIdentifier($table, true)
             . ' (' . implode(', ', $cols) . ') '
             . 'VALUES (' . implode(', ', $vals) . ')'
             . ' ' . $this->_lastInsertSQL;

        // execute the statement and return the number of affected rows
        $stmt   = $this->query($sql, array_values($bind));
        $result = $stmt->rowCount();

        $stmt->nextRowset();

        $this->_lastInsertId = $stmt->fetchColumn();

        return $result;
    }