Insert a new record and get the value of the primary key.

@param  array   $values
@param  string  $sequence
@return int
180824
public function insertGetId(array $values, $sequence = null)
    {
        $sql = $this->grammar->compileInsertGetId($this, $values, $sequence);
        $values = $this->cleanBindings($values);
        $this->connection->query($sql, $values);

        return $this->connection->insert_id();
    }
1299555
public function insertInList(array $values, $index, $value)
    {
        for ($i=count($values); $i < $index; $i++) {
            $values[$i] = null;
        }

        $values[$index] = $value;

        return $values;
    }
436420
public function insertGetId(array $values): int {
    $this->coerceDataTypesToDatabase($values);
    return $this->builder->insertGetId($values);
  }
1324632
public function insertGetId(array $values, $sequence = null)
    {
        // create a neo4j Node
        $node = $this->client->makeNode();

        // set its properties
        foreach ($values as $key => $value)
        {
            $value = $this->formatValue($value);

            $node->setProperty($key, $value);
        }

        // save the node
        $node->save();

        // get the saved node id
        $id = $node->getId();

        // set the labels
        $node->addLabels(array_map(array($this, 'makeLabel'), $this->from));

        return $id;
    }
198006
public function insert(array $values = []): bool
	{
		$query = $this->compiler->insert($values);

		return $this->connection->query($query['sql'], $query['params']);
	}
448764
static function massinsert(\fenrir\system\MysqlDatabaseSignature $db, $table, array $values, $map = null) {
		$db->begin();
		try {
			foreach ($values as $value) {
				static::insert($db, $table, $value, $map);
			}
			$db->commit();
		}
		catch (\Exception $e) {
			$db->rollback();
			throw $e;
		}
	}
930597
public function insertGetId(array $values, $sequence = null)
    {
        $sql = $this->grammar->compileInsertGetId($this, $values, $sequence);

        $values = $this->cleanBindings($values);

        return $this->processor->processInsertGetId($this, $sql, $values, $sequence);
    }
864536
protected function prepareInsert($table, $values){
        $sql= 'INSERT INTO ' . $table . ' (';
        $value= 'values(';
        foreach ($values as $key => $val) {
            $sql.= $key . ',';
            $value.= ':' . $key . ',';
        }
        $sql = trim($sql, ',');
        $value = trim($value, ',');
        $sql .= ') ' . $value . ')';
        //Preparo la consulta y la retorno
        return $this->connection->prepare($sql);
    }
731441
public function insert($table, $values){
		$statement = Statement::createInsert($this->connection, $table, $values);
		foreach($this->observers as $observer){
			$statement->attachObserver($observer, $this->observers->getInfo());
		}
		return $statement;
	}
1180371
private function _insert($attrs, $calling, $pk, $pk_value)
    {
        $escape        = Driver::$escape_char;
        $vals          = array();
        $create_column = self::hasColumn("created_at");
        $update_column = self::hasColumn("updated_at");

        $sql = "insert into $escape".$calling::getTableName()."$escape (";

        // remove the current value when need to insert a NULL value to create 
        // the autoincrement value
        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_DELETE && !$pk_value) {
            unset($attrs[$pk]);
        }

        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_SEQUENCE && empty($pk_value)) {
            $seq_name   = self::resolveSequenceName();

            // check if the sequence exists
            self::_checkSequence();
            if (!self::_sequenceExists()) {
                $this->_addError($pk, "Sequence $seq_name could not be created");
                return false;
            }

            // get the sequence next value
            $attrs[$pk] = self::sequenceNextVal($seq_name);
        } 

        // use sequence, but there is already a value on the primary key.
        // remember that it will allow this only if is really a record that
        // wasn't found when checking for the primary key, specifying that its 
        // a new record!
        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_SEQUENCE && !empty($pk_value)) {
            $attrs[$pk] = $pk_value;
        }

        if ($create_column && array_key_exists($create_column, $attrs)) {
            unset($attrs[$create_column]);
        }

        if ($update_column && array_key_exists($update_column, $attrs)) {
            unset($attrs[$update_column]);
        }

        // marks to insert values on prepared statement
        $marks = array();

        foreach ($attrs as $attr => $value) {
            $sql .= "$escape".self::$_mapping[$calling][$attr]."$escape,";
            array_push($marks, "?");
        }

        // if is there a 'created_at' column ...
        if ($create_column) {
            $sql .= "$escape".self::$_mapping[$calling][$create_column]."$escape,";
            array_push($marks, Driver::$current_timestamp);
        }

        // if is there an 'updated_at' column ...
        if ($update_column) {
            $sql .= "$escape".self::$_mapping[$calling][$update_column]."$escape,";
            array_push($marks, Driver::$current_timestamp);
        }

        $marks = join(",", $marks);
        $sql   = substr($sql, 0, strlen($sql)-1);
        $sql  .= ") values ($marks)";

        // now fill the $vals array with all values to be inserted on the 
        // prepared statement
        foreach ($attrs as $attr => $value) {
            array_push($vals, $value);
        }
        $rtn = self::executePrepared($sql, $vals)->rowCount()==1;

        // if inserted
        if ($rtn) {
            // check for last inserted value
            $lid = null;
            if (Driver::$last_id_supported) {
                $lid = self::resolveConnection()->lastInsertId();
                if (empty($this->_data[$pk]) && !empty($lid)) {
                    $this->_data[$pk] = $lid;
                }
            }

            // or, like Oracle, if the database does not support last inserted id
            if (empty($this->_data[$pk]) && empty($lid) && !empty($attrs[$pk])) {
                $this->_data[$pk] = $attrs[$pk];
            }

            // check for database filled columns
            if ($this->_data[$pk]) {
                $found = self::find($this->_data[$pk]);
                if ($found) {
                    if ($create_column) {
                        $this->_data[$create_column] = $found->get($create_column);
                    }
                }
            }

            // push later objects
            foreach ($this->_push_later as $obj) {
                $this->push($obj);
            }
            $this->_push_later = array();
        }
        return $rtn;
    }
92126
public function getCreateSequenceSQLQueries(Sequence $sequence)
    {
        if (!$this->supportSequences()) {
            throw PlatformException::methodNotSupported(__METHOD__);
        }

        return array(
            'CREATE SEQUENCE '.$sequence->getName().
            ' INCREMENT BY '.$sequence->getIncrementSize().
            ' MINVALUE '.$sequence->getInitialValue().
            ' START WITH '.$sequence->getInitialValue()
        );
    }
541311
private function insertOne(array $value)
    {
        $fields = array_keys($value);

        $sql = 'insert into `' . $this->table . '` values (';

        $sql .= implode(', ', Util::add2points($fields, true));

        $sql .= ');';

        $stmt = $this->connection->prepare($sql);

        $this->bind($stmt, $value);

        $stmt->execute();

        return (int) $stmt->rowCount();
    }
99523
public function insert(array $values) : int
    {
        $fields = $this->fields;
        array_shift($fields);

        $sql = 'INSERT INTO `' . $this->table . '` (' . implode(', ', $fields) . ') VALUES (:' . implode(', :', $fields) . ')';
        $query = $this->pdo->prepare($sql);
        foreach ($values as $key => &$value) {
            $query->bindParam(':' . $fields[$key], $value);
        }
        $query->execute();

        return $this->pdo->lastInsertId();
    }
727042
protected function query_insert_id ( $tableName, $primaryKey = null )
    {
        $sequenceName = $tableName;
        if ($primaryKey) {
            $sequenceName .= "_$primaryKey";
        }
        $sequenceName .= '_seq';

        $sql = "
            SELECT
                CURRVAL('%s')
                ";
        $args = array($sql, $sequenceName);
        $sql = $this->sql_printf($args);
        if (!($res = pg_query($this->conn, $sql))) {
            return 0;
        }
        $val = pg_fetch_row($res, 0);
        if ($val && isset($val[0])) {
            $val = $val[0];
        }

        pg_free_result($res);
        return $val;
    }
1281655
public function insert(array $values)
	{
		// Since every insert gets treated like a batch insert, we will make sure the
		// bindings are structured in a way that is convenient for building these
		// inserts statements by verifying the elements are actually an array.
		if ( ! is_array(reset($values)))
		{
			$values = array($values);
		}

		// Since every insert gets treated like a batch insert, we will make sure the
		// bindings are structured in a way that is convenient for building these
		// inserts statements by verifying the elements are actually an array.
		else
		{
			foreach ($values as $key => $value)
			{
				ksort($value); $values[$key] = $value;
			}
		}

		// We'll treat every insert like a batch insert so we can easily insert each
		// of the records into the database consistently. This will make it much
		// easier on the grammars to just handle one type of record insertion.
		$bindings = array();

		foreach ($values as $record)
		{
			$bindings = array_merge($bindings, array_values($record));
		}

		$sql = $this->grammar->compileInsert($this, $values);

		// Once we have compiled the insert statement's SQL we can execute it on the
		// connection and return a result as a boolean success indicator as that
		// is the same type of result returned by the raw connection instance.
		$bindings = $this->cleanBindings($bindings);

		return $this->connection->insert($sql, $bindings);
	}
755175
public function update(array $values)
    {
        $result = $this->getBuilder()->update($values);

        // Reset query builder
        $this->resetBuilder();

        return (int) $result;
    }
242912
public function addSequence(Sequence $sequence)
    {
        if ($this->hasSequence($sequence->getName())) {
            throw SchemaException::schemaSequenceAlreadyExists($this->getName(), $sequence->getName());
        }

        $this->sequences[$sequence->getName()] = $sequence;
    }