插入一条记录

@param string $table
@param array $row
@param bool $pkval 是否获取插入的主键值

@return mixed
175004
public function insert($table, array $row, $pkval=false)
    {
    	$ds = $this->ds();
		list($holders, $values) = SqlHelper::placeholder($row);
        $holders = implode(',', $holders);
        
        $fields = SqlHelper::qfields(array_keys($values));        
        $table = SqlHelper::qtable($table);
		
        $result = Sql::write($ds, Sql::MODE_WRITE_INSERT, [
				SqlHelper::bind($ds, "INSERT INTO {$table} ({$fields}) VALUES ({$holders})", $row),
				$pkval
			]);
		return $result;
	}
830054
public function insertRows(array $rows, $table, $fieldArr = [], $isReplace = false)
    {
        $type = $isReplace ? 'REPLACE' : 'INSERT';

        // 数据中允许插入的字段
        $allowFields = $fieldArr ? $fieldArr : array_keys(current($rows));
        $allowFields = QueryBuilder::quoteFieldNames(implode(',', $allowFields));

        //
        $valueArr = [];
        foreach ($rows as $row) {
            $rowStr = '';
            foreach ($row as $key => $val) {
                // 去掉不允许写入的属性
                if ($fieldArr && !in_array($key, $fieldArr)) {
                    unset($row[$key]);
                }
            }

            $rowStr = implode(',', array_map('\wf\db\QueryBuilder::quoteInputVar', $row));
            $valueArr[] = "({$rowStr})";
        }
        $values = $rowStr = implode(',', $valueArr);

        return $this->exec("%x INTO %t (%x) VALUES %x", array($type, $table, $allowFields, $values));
    }
1030078
public function select_row($table ,$cond=null ,$fields='*', $sort=null)
    {
    	$ds = $this->ds();
		$cond = SqlHelper::parse_cond($ds,$cond);
		if ($cond) $cond = "WHERE {$cond}";
		if ($sort) $sort = "ORDER BY {$sort}";
		
		$qfields = SqlHelper::qfields($fields,$table);
		
		$result = Sql::read($ds, Sql::MODE_READ_GETROW, [
				"SELECT {$qfields} FROM {$table} {$cond} {$sort}"
			]);
		return $result;
	}
310440
public function buildRowSql(DataRow $row)
    {
        $sql = parent::buildRowSql($row);

        $table = $this->getTable();

        if ($table->hasAutoIncrementPrimaryKey() && $table->getIdMethod() == IDMethod::NATIVE) {
            foreach ($row->getColumnValues() as $colValue) {
                if ($colValue->getColumn()->isAutoIncrement()) {
                    if ($colValue->getValue() > $this->maxSeqVal) {
                        $this->maxSeqVal = $colValue->getValue();
                    }
                }
            }
        }

        return $sql;
    }
836965
public function getString($row, Table $table) {
        if (!$this->isVisible($row)) {
            return "";
        }
        $options = $this->htmlOptions;
        if ($this->title != "") {
            eval("\$options['title'] = {$this->title};");
        } elseif (!isset($options['title'])) {
            $options['title'] = '';
        }
        if ($this->confirmation && (!$this->post)) {
            if ($this->jsAction) {
                $options['onclick'] = "if (confirm('{$this->confirmation}')) {$this->jsAction}({$row->{$this->dataProvider->getPkKey()}}, '{$this->name}', this);";
            } else {
                $options['onclick'] = "return confirm('{$this->confirmation}');";
            }
        } elseif ($this->jsAction) {
            $options['onclick'] = "return {$this->jsAction}({$row->id}, '{$this->name}', this);";
        }

        if ('#' != $this->url) {
            eval("\$url = {$this->url};");
        } else {
            $url = '#';
        }
        if (false !== $this->post && is_array($this->post)) {
            $options['class'] = isset($options['class']) ? $options['class'] . ' mdata-table-post-link' : 'mdata-table-post-link';
            $parsed = array();
            foreach ($this->post as $name=>$value){
                eval('$value = '. $value.';');
                if ('{{modelKey}}' == $name){
                    $name = $table->dataProvider->filtersKey;
                }
                $parsed[$name] = $value;
            }
            $options['post-data'] = json_encode($parsed);
            if ($this->confirmation){
                $options['post-confirmation'] = $this->confirmation;
            }
        }
        $icon = $this->getIcon($options['title'], $table);
        return Html::get()->link($url, $icon . $this->label, $options);
    }
1264722
private function getValue(Row $row, $column)
	{
		if (!$this->rowCallback) {
			return $row->getValue($column->getColumn());
		}

		return call_user_func_array($this->rowCallback, [$row->getItem(), $column->getColumn()]);
	}
206304
public function insert($table, $row)
	{
		$keys = implode('`, `', array_keys($row));
        $holds = implode(',', array_fill(0, count($row), '?'));
		$vals = array_values($row);

		$sql = "INSERT INTO `{$table}` (`{$keys}`) VALUES({$holds})";

        $stmt = $this->prepare($sql);
        return $stmt ? $stmt->execute($vals) : false;
	}
186683
protected function callback($row)
    {
        foreach ($this->getConfig('callbacks') as $column => $callbacks) {
            if (strpos($column, '/') === 0) {
                // Interpret as a regex and apply to all matching columns.
                foreach (array_keys($row) as $name) {
                    if (preg_match($column, $name) === 1) {
                        foreach ((array) $callbacks as $callback) {
                            $row[$name] = call_user_func($callback, $row[$name]);
                        }
                    }
                }
            } else {
                // Apply to one explicitly named column.
                if (array_key_exists($column, $row) === false) {
                    throw new \RuntimeException('Unable to apply callback to missing column: ' . $column);
                }
                foreach ((array) $callbacks as $callback) {
                    $row[$column] = call_user_func($callback, $row[$column]);
                }
            }
        }
        return $row;
    }
85654
protected function checkRow(array $row) {
		foreach ($row as $column => $str) {
			$width = Colors::width( $str, $this->isAsciiPreColorized( $column ) );
			if (!isset($this->_width[$column]) || $width > $this->_width[$column]) {
				$this->_width[$column] = $width;
			}
		}

		return $row;
	}
1229479
public function buildRowSql(DataRow $row)
    {
        $sql = "";
        $platform = $this->getPlatform();
        $table = $this->getTable();

        $sql .= "INSERT INTO " . $this->quoteIdentifier($this->getTable()->getName()) . " (";

        // add column names to SQL
        $colNames = array();
        foreach ($row->getColumnValues() as $colValue) {
            $colNames[] = $this->quoteIdentifier($colValue->getColumn()->getName());
        }

        $sql .= implode(',', $colNames);

        $sql .= ") VALUES (";

        $colVals = array();
        foreach ($row->getColumnValues() as $colValue) {
            $colVals[] = $this->getColumnValueSql($colValue);
        }

        $sql .= implode(',', $colVals);
        $sql .= ");
";

        return $sql;
    }
179373
public function insertIgnore(array $row)
    {
        // 这两个字段是表必备字段,并自动更新
        $row = self::appendAutoField($row);

        // 执行前置钩子
        $ret = $this->before('Insert', 'InsertIgnore', $row);
        if ($ret === self::INTERRUPT) {
            return null;
        }
        $row = array_pop($ret);

        //Insert/Replace/InsertIgnore的后继处理
        return self::afterInsertReplaceInsertIgnore('InsertIgnore', $row);
    }
265659
public function getPk($table, $tablePrefix = null)
    {
        $rows = $this->getDbFields($table, $tablePrefix);
        foreach ($rows as $val) {
            if ($val['primary']) {
                return $val['name'];
            }
        }
        return false;
    }
152590
public function getColumnValue(Row $row)
	{
		$value = parent::getColumnValue($row);

		if (!is_numeric($value)) {
			return $value;
		}

		return number_format(
			(float) $value,
			(int) $this->number_format[0],
			(string) $this->number_format[1],
			(string) $this->number_format[2]
		);
	}
99545
public function insert(array $row): ?int
    {
        // 这两个字段是表必备字段,并自动更新
        $row = array_filter(self::appendAutoField($row));

        // 执行前置钩子
        $ret = $this->before('Insert', 'Insert', $row);
        if ($ret === self::INTERRUPT) {
            return null;
        }
        $row = array_pop($ret);

        //Insert/Replace/InsertIgnore的后继处理
        return self::afterInsertReplaceInsertIgnore('Insert', $row);
    }
1099339
private function getAgentFromRow(array $row)
    {
        if (isset($row['headers']['User-Agent'])) {
            return $row['headers']['User-Agent'];
        }

        if (class_exists('\http\Header')) {
            // pecl_http versions 2.x/3.x
            $headers = \http\Header::parse($row['headers']);
        } elseif (function_exists('\http_parse_headers')) {
            // pecl_http version 1.x
            $headers = \http_parse_headers($row['headers']);
        } else {
            return '';
        }

        if (isset($headers['User-Agent'])) {
            return $headers['User-Agent'];
        }

        return '';
    }
1147788
public function translateRowValues($row, $key)
    {
        $row = parent::translateRowValues($row, $key);

        if (! $row) {
            return false;
        }

        if ((! isset($row['grs_id_user'])) && isset($row['gr2o_patient_nr'], $row['gr2o_id_organization'])) {
            $sql = 'SELECT gr2o_id_user
                    FROM gems__respondent2org
                    WHERE gr2o_patient_nr = ? AND gr2o_id_organization = ?';

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

            if ($id) {
                $row['grs_id_user']  = $id;
                $row['gr2o_id_user'] = $id;
            }
        }

        if (empty($row['gr2o_email'])) {
            $row['calc_email'] = 1;
        }

        return $row;
    }
26006
public function getValue($row, Table $table) {
        $res = '';
        if ($this->value) {
            if (is_callable($this->value)){
                $res = call_user_func($this->value, $row, $table);
            } else {
                eval("\$res = {$this->value};");
            }
        } else {
            $res = ('select' == $this->type) ? ((isset($this->options[$row->{$this->name}]) ? $this->options[$row->{$this->name}] : $this->noValueDisplay)) : ($row->{$this->name}?:$this->noValueDisplay);
        }
        return $this->canEdit ? "<{$this->linkElement} class='inline-edit-column-edit-link' href='#'>" . $res . "</{$this->linkElement}>" . $this->getForm($row, $table) : $res;

    }