检查数据是否存在
@param string $condition
@param string $params
@return boolean
168210
public function exists($condition='', $params=null) {
		$cnt = $this->driver
            ->field('count(*)')
            ->where($condition, $params)
            ->fetchColumn();
		return $cnt > 0 ? true : false;
	}
1330558
function delete($condition = '', $params = []) {
        $sql = "DELETE FROM `$this->table`";

        if($this->where) {
            $sql .= ' '.$this->where;
        }

        if ($condition) {
            if(is_array($condition)) {
                $sql .= $this->w . $this->parseWhere($condition[0]);
            }
            elseif ($params) {
                //using prepared statement.
                if (!is_array($params)) {
                    $params = [$params];
                }
                $sql .= $this->w . $condition;
                $this->params = array_merge($this->params, $params);
            }
            else {
                $sql .= $this->w . $condition;
            }
        }

        $sql = str_replace('table.',$this->table.'.',$sql);
        $params = $this->params;

        $this->_reset();

        return $this->execute($sql, $params,false);
    }
599101
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        return $this->loadWiths($this->modelManager->many($condition, $params, $offset, $limit));
    }
737077
public function andWhere($condition, $params = [])
    {
        if (is_array($condition)) {
            foreach ($condition as $key => $value) {
                if ($this->canSetProperty($key)) {
                    $this->{$key} = $value;
                    unset($condition[$key]);
                }
            }
        }

        return parent::andWhere($condition);
    }
305274
public function having($conditions, $params = array(), $types = array())
    {
        $conditions = $this->processCondition($conditions, $params, $types);
        return $this->add('having', $conditions);
    }
904731
public function parseCondition($condition) {
        $condition = str_ireplace(array_keys($this->comparison),array_values($this->comparison),$condition);
        $condition = preg_replace('/\$(\w+):(\w+)\s/is','$\\1->\\2 ',$condition);
        switch(strtolower(C('TMPL_VAR_IDENTIFY'))) {
            case 'array': // 识别为数组
                $condition  =   preg_replace('/\$(\w+)\.(\w+)\s/is','$\\1["\\2"] ',$condition);
                break;
            case 'obj':  // 识别为对象
                $condition  =   preg_replace('/\$(\w+)\.(\w+)\s/is','$\\1->\\2 ',$condition);
                break;
            default:  // 自动判断数组或对象 只支持二维
                $condition  =   preg_replace('/\$(\w+)\.(\w+)\s/is','(is_array($\\1)?$\\1["\\2"]:$\\1->\\2) ',$condition);
        }
        if(false !== strpos($condition, '$Think'))
            $condition      =   preg_replace_callback('/(\$Think.*?)\s/is', array($this, 'parseThinkVar'), $condition);        
        return $condition;
    }
743079
public function is($condition, $field) {
		if (!isset($this->_fields[$field])) {
			return null;
		}
		return isset($this->_fields[$field][$condition]) && $this->_fields[$field][$condition];
	}
1305647
public function where( $condition ) {
		if ( ! $condition instanceof ConditionInterface ) {
			$condition = func_get_args();
		}

		$condition = $this->router->mergeConditionAttribute(
			$this->getAttribute( 'condition' ),
			$condition
		);

		return $this->attribute( 'condition', $condition );
	}
486330
public static function deleteAll($condition, $params = array())
    {
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        }
        /* @var $condition ModelCondition */
        $condition->setParams($params);
        return static::getDb()->execQuery($condition->forDelete(), $condition->getParams());
    }
224059
protected function parseCondition($condition)
	{
		$result = '';
		// 遍历条件数组
		foreach ($condition as $item)
		{
			if(is_string($item))
			{
				if ('' !== $result)
				{
					// 不是第一个条件，默认加上 and
					$result .= ' ' . $this->getOperator('and') . ' ';
				}
				$result .= $item;
				continue;
			}
			if(isset($item['__str'], $item['__values']))
			{
				// 参数化绑定
				if ('' !== $result)
				{
					// 不是第一个条件，默认加上 and
					$result .= ' ' . $this->getOperator('and') . ' ';
				}
				$count = 0;
				$result .= '(' . preg_replace_callback('/(((%)([bdsl]))|((:)([a-zA-Z0-9_-]+)))/', function($match)use($item, &$count){
					$name = array_pop($match);
					$prefix = array_pop($match);
					switch($prefix)
					{
						case '%':
							$paramName = ':' . $this->getParamName();
							$this->bindValue($paramName, $item['__values'][$count++], $this->getPDOParamType($name));
							return $paramName;
							break;
						case ':':
							$this->bindValue($match[0], $item['__values'][$count++]);
							return $match[0];
							break;
					}
				}, $item['__str']) . ')';
				continue;
			}
			foreach($item as $key => $value)
			{
				$skey = strtolower($key);
				// 判断是否是逻辑运算符
				if (in_array($skey, $this->logicOperators))
				{
					if('' !== $result)
					{
						// 当前键名是逻辑运算符
						$result .= ' ' . $this->getOperator($skey);
					}
					$result .= ' (' . $this->parseCondition(array($value)) . ')';
				}
				else
				{
					if ('' !== $result)
					{
						// 不是第一个条件，默认加上 and
						$result .= ' ' . $this->getOperator('and') . ' ';
					}
					if (is_array($value))
					{
						$s = count($value);
						// 条件解析
						if ($s > 0)
						{
							if('between' === $value[0])
							{
								if ($s >= 3)
								{
									$betweenParamName = $this->getParamName();
									$this->operationOption['params'][$betweenParamName] = $value[1];
									$endParamName = $this->getParamName();
									$this->operationOption['params'][$betweenParamName] = $value[2];
									$result .= $this->parseKeyword($key) . ' between :' . $betweenParamName . ' and :' . $endParamName;
								}
							}
							else if('in' === $value[0] || 'not in' === $value[0])
							{
								if ($s === 2)
								{
									$operationName = $value[0];
									if(is_array($value[1]))
									{
										$listData = $value[1];
									}
									else
									{
										$value[1] = explode(',', $value[1]);
									}
								}
								else if ($s > 2)
								{
									$operationName = array_shift($value);
									$listData = $value;
								}
								$list = array();
								foreach($listData as $item)
								{
									$paramName = $this->getParamName();
									$list[] = ':' . $paramName;
									$this->operationOption['params'][$paramName] = $item;
								}
								$result .= $this->parseKeyword($key) . ' ' . $this->getOperator($operationName) . '(' . implode(',', $list) . ')';
							}
							else
							{
								if ($s > 0)
								{
									$result .= $this->parseKeyword($key) . ' ' . $this->getOperator($value[0]);
									for ($i = 1; $i < $s; ++$i)
									{
										$paramName = $this->getParamName();
										$result .= ' :' . $paramName;
										$this->operationOption['params'][$paramName] = $value[$i];
									}
								}
							}
						}
					}
					else if(is_numeric($key))
					{
						$result .= $value;
					}
					else
					{
						// 直接等于
						$paramName = $this->getParamName();
						$this->operationOption['params'][$paramName] = $value;
						$result .= $this->parseKeyword($key) . '=:' . $paramName;
					}
				}
			}
		}
		return $result;
	}
190537
public function action(string $query, array $params = [])
    {
        // Prepares the query, then stores it
        $PDOStatement = $this->pdo->prepare($query);

        // Executes the query, then returns the boolean value
        return $PDOStatement->execute($params);
    }
609630
public function count(string $condition = '', array $params = array()) {
        $this->model->builder->select('COUNT(*)')
            ->from($this->model->tableName);
        if ($condition) {
            $this->model->builder->where($condition, $params);
        }
        $r = $this->model->builder->query();
        if (!is_array($r) || 0 === count($r)) {
            return false;
        }
        return (int) reset($r[0]);
    }
382986
public function update($table, $data, $condition)
    {
        if ( empty($condition) ) return false;
        $_T_fields = $this->getTableFields($table);
        $_keys = '';
        foreach ( $data as $_key => $_val ) {

            //过滤不存在的字段
            if ( !in_array($_key, $_T_fields) ) continue;
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_keys .= $_keys == ''? "`{$_key}`={$_val}" : ", `{$_key}`={$_val}";
        }
        if ( $_keys !== '' ) {
            $_query = "UPDATE {$table} SET " . $_keys . $condition;
            $result = $this->execute($_query);
            if ( $result != false ) {
                return $result->rowCount() > 0 ? $result->rowCount() : true;
            }
        }
        return false;
    }
1064265
public function many(string $condition = '', array $params = array(), $offset = null, $limit = null) {
        $this->model->builder
            ->select('*')
            ->from($this->model->tableName);

        if ($condition) {
            $this->model->builder->where($condition, $params);
        }

        if (null !== $offset) {
            if (null === $limit) {
                $this->model->builder->limit($offset);
            } else {
                $this->model->builder->limit($offset, $limit);
            }
        }
        $r = $this->model->builder->query();
        if (!is_array($r) || 0 === count($r)) {
            return [];
        }

        return $this->model->setup($r);
    }
555950
public function delete($condition=null, $params=null) {
		return $this->driver->delete($condition, $params);
	}
44494
protected function parseCondition($condition)
    {
        $tableAlias = $this->getAlias();
        $parts = [];

        if ($condition instanceof QueryBuilderAwareInterface) {
            $condition->setQueryBuilder($this);
        }

        if ($condition instanceof Expression) {
            $parts[] = $this->getAdapter()->quoteSql($condition->toSQL());
        } elseif ($condition instanceof Q) {
            $condition->setLookupBuilder($this->getLookupBuilder());
            $condition->setAdapter($this->getAdapter());
            $condition->setTableAlias($tableAlias);
            $parts[] = $condition->toSQL();
        } elseif ($condition instanceof ToSqlInterface) {
            $parts[] = $condition->toSQL();
        } elseif (is_array($condition)) {
            foreach ($condition as $key => $value) {
                if ($value instanceof Q) {
                    $parts[] = $this->parseCondition($value);
                } else {
                    list($lookup, $column, $lookupValue) = $this->lookupBuilder->parseLookup($this, $key, $value);
                    $column = $this->getLookupBuilder()->fetchColumnName($column);
                    if (false === empty($tableAlias) && false === strpos($column, '.')) {
                        $column = $tableAlias.'.'.$column;
                    }
                    $parts[] = $this->lookupBuilder->runLookup($this->getAdapter(), $lookup, $column, $lookupValue);
                }
            }
        } elseif (is_string($condition)) {
            $parts[] = $condition;
        } elseif ($condition instanceof Expression) {
            $parts[] = $condition->toSQL();
        }

        if (1 === count($parts)) {
            return $parts[0];
        }

        return '('.implode(') AND (', $parts).')';
    }
856935
public function filterCondition(array $data, $condition)
    {
        if (empty($condition)) {
            return $data;
        }

        if (!is_array($condition)) {
            throw new InvalidParamException('Condition must be an array');
        }

        if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
            $operator = strtoupper($condition[0]);
            if (isset($this->conditionFilters[$operator])) {
                $method = $this->conditionFilters[$operator];
            } else {
                $method = 'filterSimpleCondition';
            }

            array_shift($condition);

            return $this->$method($data, $operator, $condition);
        } else { // hash format: 'column1' => 'value1', 'column2' => 'value2', ...
            return $this->filterHashCondition($data, $condition);
        }
    }