Replace,Insert,InsertIgnore的后继处理
@param $operator string 操作符,Insert/Replace/InsertIgnore
@param $row array 要插入的数据
@return mixed|null|string
499886
private function afterInsertReplaceInsertIgnore(string $operator, array $row)
    {
        // 执行具体插入操作
        if ($operator == 'Insert') {
            return self::processInsertOperation($row);
        }

        // 创建"忽略插入"
        if ($operator == 'InsertIgnore') {
            return self::processInsertIgnore($row);
        }

        //处理Replace
        if ($operator == 'Replace') {
            return self::processReplace($row);
        }

        trigger_error('不应该到达这里:' . $operator, E_USER_ERROR);
        return null;
    }
718667
function insertRow($row, $row_id = 0) {
        array_splice($this->_data, $row_id, 0, array($row));

        $this->_updateRowsCols($row);
    }
1155729
public function execute($row = null)
    {
        if ($row) {
            if ((! isset($row['grs_id_user'])) &&
                    isset($row['grs_ssn']) &&
                    $this->targetModel instanceof \Gems_Model_RespondentModel &&
                    $this->targetModel->hashSsn !== \Gems_Model_RespondentModel::SSN_HIDE) {

                if (\Gems_Model_RespondentModel::SSN_HASH === $this->targetModel->hashSsn) {
                    $search = $this->targetModel->saveSSN($row['grs_ssn']);
                } else {
                    $search = $row['grs_ssn'];
                }

                $sql = 'SELECT grs_id_user FROM gems__respondents WHERE grs_ssn = ?';
                $id  = $this->db->fetchOne($sql, $search);

                // Check for change in patient ID
                if ($id) {
                    if (isset($row['gr2o_id_organization']) &&
                            $this->targetModel instanceof \MUtil_Model_DatabaseModelAbstract) {

                        $sql = 'SELECT gr2o_patient_nr
                                FROM gems__respondent2org
                                WHERE gr2o_id_user = ? AND gr2o_id_organization = ?';

                        $patientId = $this->db->fetchOne($sql, array($id, $row['gr2o_id_organization']));

                        if ($patientId) {
                            // Change the patient number
                            $copyId       = $this->targetModel->getKeyCopyName('gr2o_patient_nr');
                            $row[$copyId] = $patientId;
                        }
                    }

                    $row['grs_id_user']  = $id;
                    $row['gr2o_id_user'] = $id;
                }
            }

            parent::execute($row);
        }
    }
706433
public function query($params = array(), $operator = "OR") {
		
		$page = intval(@$params['page']);
		$size = intval(@$params['size']);
		$sort = @$params['sort'];
		
		unset($params['page']);
		unset($params['size']);
		unset($params['sort']);
		
		if(!$size) $size = 20;
		
		$cond = array();
		$bindings = array();
		
		foreach($params as $key => $value) {
			$cond[] = sprintf("`%s` %s :where_%s", 
					str_replace('`', '``', $key), 
					is_null($value) ? 'is' : (strpos($value, '%') !== FALSE ? 'LIKE' : '='),
					$key);
			$bindings[":where_$key"] = $value;
		}
		
		$query = sprintf(self::SELECT_SEARCH,
            $this->params['table'],
			empty($cond) ? '1=1' : implode(" $operator ", $cond)
		);
		
		$query .= sprintf(" LIMIT %d, %d", $page * $size, $size);
		
		$stmt = $this->pdo->prepare($query);
		
		$stmt->execute($bindings);

		if(!$stmt) {
			$error = $this->pdo->errorInfo();
			
			throw new \Exception($error[2]);
		}
		
		$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
		
		$stmt = $this->pdo->query("SELECT FOUND_ROWS() as count");
		
		$count = $stmt->fetch(PDO::FETCH_ASSOC);
		
		if(!$count) {
			throw new \Exception("Error fetching count");
		}
		
 		$count = intval($count['count']);
		
		return array(
			'_embedded' => array(
				$this->params['table'] => $data
			),
			'page' => array(
				'size' => $size,
				'number' => $page,
				'totalElements' => $count,
				'totalPages' => ceil($count/$size)
 			)
		);
	}
18425
private function getOperator($operator)
    {
        $operators = $this->getOperators();

        $key = array_search(strtolower($operator), $operators);

        if ($key !== false && array_key_exists($key, $operators)) {
            return $operators[$key];
        }

        $operators = implode(', ', $operators);

        $message = "Operator: $operator cannot be used in an LDAP query. Available operators are $operators";

        throw new InvalidQueryOperator($message);
    }
551968
protected function sanitiseRow($table, $row)
    {
        $data = [];

        foreach ($this->keys[$table] as $key) {
            $data[$key] = isset($row[$key]) ? $row[$key] : null;
        }

        return $data;
    }
878917
public function format($row)
    {
        $data = $this->getArray($row);
        $prefix = $this->getHeaderPrefix($data);
        $data = $this->process($data);

        foreach ($data as &$element) {
            if (is_null($element)) {
                $element = $this->csvFormat->getNullValue();
            } else {
                $element = $this->csvFormat->getQuote() . $this->escape($element) . $this->csvFormat->getQuote();
            }
        }

        return $prefix . $this->encode(implode($this->csvFormat->getDelimiter(), $data));
    }
446819
private function crease(string $operator, $fields, $where, float $diff): int
    {
        // 执行前置钩子
        $ret = $this->before('Crease', $operator, $fields, $where, $diff);

        //如果被前置钩子阻止
        if ($ret === self::INTERRUPT) {
            return 0;
        }

        //钩子对参数进行修正
        list($operator, $fields, $where, $diff) = $ret;

        //创建语句
        $this->statement->crease($operator, $fields, $where, $diff);

        // 执行具体增减
        $result = self::log('crease', ['fields' => $fields, 'where' => $where, 'diff' => $diff], $fields, $where, true, true);

        // 执行后置钩子
        return intval($this->after('Crease', $result));
    }
12657
protected function replaceTemplateVars(array $row_data, string $field)
    {
        $pairs = [];

        foreach ($row_data as $k => $v) {
            if (!$this->isHtmlAllowed()) {
                $v = htmlspecialchars((string)$v, ENT_QUOTES);
            }
            $pairs['{%' . $k . '%}'] = $v;
        }

        if (strpos($field, '{%') !== false) {
            return strtr($field, $pairs);
        }

        return $field;
    }
1197241
public function orWhereRaw($column, $operator = null, ?string $raw = null)
	{
		return $this->whereRaw($column, $operator, $raw, 'OR');
	}
371356
protected function parseIUD($args,$operation)
	{
		if(isset($args[2]))
		{
			// 三个参数齐全
			list($table,$data,$return) = $args;
		}
		else if(isset($args[1]))
		{
			// 数据+返回值
			list($data,$return) = $args;
		}
		else if(isset($args[0]))
		{
			// 一个参数的情况
			if(is_array($args[0]))
			{
				// 数据
				$data = $args[0];
			}
			else
			{
				// 表名
				$table = $args[0];
			}
			$return = Db::RETURN_ISOK;
		}
		$result = $this->execute($this->{'build' . $operation . 'SQL'}($table, $data));
		if(Db::RETURN_ROWS === $return)
		{
			return $this->rowCount();
		}
		else if(Db::RETURN_INSERT_ID === $return)
		{
			return $this->lastInsertId();
		}
		else
		{
			return $result;
		}
	}
381996
function insert( $rows, $method = null ) {

        return $this->db->insert( $this->table, $rows, $method );

    }
328219
private function processInsertIgnore2(array $row): int
    {
        self::execute2();

        // 获取新记录的主键
        $id = $this->getInsertedId();
        if ($id) {
            //已经有ID了,什么都不做
            return intval($id);
        }

        if (isset($row['id'])) {
            // 取记录中的ID
            return intval($row['id']);
        }

        //已经存在时返回0
        return 0;
    }
610588
public function applyReplacements(Row $row)
	{
		$value = $row->getValue($this->column);

		if ((is_scalar($value) || $value === null) && isset($this->replacements[$value])) {
			return [true, $this->replacements[$value]];
		}

		return [false, null];
	}
1254027
public function replace($table, array $columns = null, array $where = null): ?array
    {
        if (\is_array($table)) {
            $columns = $this->getColumns($table, false);
            $table = $this->getTable($table);
            $where = $table;
        } elseif ($where) {
            $where = [SQL::WHERE => $where];
        }

        if (!\is_array($columns) || empty($columns)) {
            return null;
        }

        $map = [];
        $stack = [];

        foreach ($columns as $column => $replacements) {
            if (\is_array($replacements)) {
                foreach ($replacements as $old => $new) {
                    $mapKey = $this->mapKey();

                    $stack[] = $this->columnQuote($column) . ' = REPLACE(' . $this->columnQuote($column) . ', ' . $mapKey . 'a, ' . $mapKey . 'b)';

                    $map[$mapKey . 'a'] = [$old, PDO::PARAM_STR];
                    $map[$mapKey . 'b'] = [$new, PDO::PARAM_STR];
                }
            }
        }

        if ($stack === []) {
            return null;
        }

        $sql = 'UPDATE ' . $this->tableQuote($table) . ' SET ' .
            \implode(', ', $stack) . $this->suffixClause($where, $map);

        return [$sql, $map];
    }
932573
private function getInsertString($rows, $table)
    {
        $columns = array();
        $values = array();
        foreach ($rows as $row) {
            if (empty($columns)) {
                $columns = array_keys($row);
            }
            $rowValues = array();
            foreach ($row as $entry) {
                $entry = is_null($entry) ? "NULL" : \OxidEsales\Eshop\Core\DatabaseProvider::getMaster(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC)->quote($entry);
                $rowValues[] = $entry;
            }
            $values[] = "(". implode(", ", $rowValues).")";
        }

        $query = "INSERT INTO $table ";
        $query .= "(`".implode("`, `", $columns)."`) VALUES ".implode(", ", $values);

        return $query;
    }
559064
public function insert(Query $query, $replace = false)
    {
        // 分析并处理数据
        $options = $query->getOptions();

        $data = $this->parseData($query, $options['data']);

        $bulk = new BulkWrite;

        if ($insertId = $bulk->insert($data)) {
            $this->insertId = $insertId;
        }

        $this->log('insert', $data, $options);

        return $bulk;
    }