Process an "insert get ID" query.

@param  \Fly\Database\Query\Builder  $query
@param  string  $sql
@param  array   $values
@param  string  $sequence
@return int
547841
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
	{
		$query->getConnection()->insert($sql, $values);

		$id = $query->getConnection()->getPdo()->lastInsertId();

		return is_numeric($id) ? (int) $id : $id;
	}
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);
    }
1234229
public static function insert( $table, $values = array(), $handler = null )
	{
		return Query_Insert::create( $table, $handler )->values( $values );
	}
245791
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
    {
        $connection = $query->getConnection();

        $connection->insert($sql, $values);

        if ($connection->getConfig('odbc') === true) {
            $id = $this->processInsertGetIdForOdbc($connection);
        } else {
            $id = $connection->getPdo()->lastInsertId();
        }

        return is_numeric($id) ? (int) $id : $id;
    }
211075
public function query(
		string $query, 
		$values=null, 
		$table=null
	) {
		// set the main action
		$this->action('QUERY');
		// set the table
		$this->Table = $table;
		// set the query
		$this->Query = $query;
		// set the array of values
		$this->Values = $values;
		// detetect the action
		$action = substr($query, 0, 6);
		// if action can alter a table (INSERT, UPDATE, DELETE)
		if(in_array($action, array('INSERT', 'UPDATE', 'DELETE', 'SELECT'))) {
			// in case of INSERT
			if($action == 'INSERT') {
				// explode after INTO
				list(,$table) = explode('INTO ', $this->Query);
				// isolate the table name
				list($this->Table) = explode(' ', $table);
			}
			// in case of UPDATE
			elseif($action == 'UPDATE') {
				// explode after UPDATE
				list(,$table) = explode('UPDATE ', $this->Query);
				// isolate the table name
				list($this->Table) = explode(' ', $table);
			}
			// in case of DELETE or SELECT
			elseif($action == 'DELETE' || $action == 'SELECT') {
				// explode after FROM 
				list(,$table) = explode('FROM ', $this->Query);
				// isolate the table name
				list($this->Table) = explode(' ', $table);
			}
			// clean the table name from any quotes
			$this->Table = trim($this->Table, '\'/"`');
		}
		// return self to the next method
		return $this;
	}
571054
public function prepareInsert($table, array $values) {

        // Initialize the query.
        $query = [];

        $query[] = "INSERT INTO ";
        $query[] = $table;
        $query[] = " (`";
        $query[] = implode("`, `", array_keys($values));
        $query[] = "`) VALUES (";
        $query[] = implode(", ", array_values($values));
        $query[] = ")";

        // Return the query.
        return implode("", $query);
    }
217497
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->connection()->sqlExecute($sql, $params);
    }
396812
public function query(string $sql, array $values = []): int
    {
        return $this->dbConnection->prepare($sql)
                ->execute($values)
                ->count();
    }
1054060
public function insert($table, $values)
    {
        $keys = array();
        $params = array();
        $placeholders = array();
        foreach ($values as $k => $v) {
            $keys[] = $this->db->quoteColumn($k);
            $params[':' . $k] = $v;
            $placeholders[] = ':' . $k;
        }
        $sql = "INSERT INTO " . $this->db->quoteTable($table) . ' (' . implode(', ', $keys) . ') VALUES (' . implode(',', $placeholders) . ')';
        $result = $this->setSql($sql)->execute($params);
        if (!$result) {
            return false;
        }

        return $this->db->lastInsertId();
    }
265238
public function compile_insert( &$query )
	{
		$build = ( $query->ignore ? 'insert ignore' : 'insert' ).' into '.$this->escape_table( $query ).' ';

		$value_collection = $query->values;

		// Get the array keys from the first array in the collection.
		// We use them as insert keys.
		$build .= '('.$this->escape_list( array_keys( reset( $value_collection ) ) ).') values ';

		// add the array values.
		foreach( $value_collection as $values )
		{
			$build .= '('.$this->parameterize( $values ).'), ';
		}

		// cut the last comma away
		return substr( $build, 0, -2 );
	}
378819
public function insert( $query, array $data = [ ] )
    {
        $id = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $this->database->lastInsertId();
        }

        return $result;
    }
333611
protected function _insert($query, $params)
    {
        $db = $this->db;
        $sth = $db->prepare($query);

        foreach ($params as $key => $val) {
            if (is_int($val)) {
                $sth->bindValue("$key", $val, $db::PARAM_INT);
            } else {
                $sth->bindValue("$key", $val);
            }
        }

        $response = $sth->execute();

        if ($response) {

            $class = $this->_rowClass;
            $row = new $class($this, $db->lastInsertId());

            return $row;
        }
        return false;
    }
526540
protected function insertAndSetId(Builder $query, $attributes)
    {
        $id = $this->generateUuid();
        $attributes[$keyName = $this->getKeyName()] = $id;
        $query->insert($attributes);
        $this->setAttribute($keyName, $id);
    }
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();
    }
994671
protected function insertExecute(string $statement, array $values): ?array {
		
		// our insert method should return either a single ID or a list of created IDs.
		// we can use the ExtendedPdo's fetchAffected method to determine how many were
		// inserted and then use that to determine our return value.  if nothing at all
		// was inserted, we return null.
		
		$affected = $this->dbConn->fetchAffected($statement, array_values($values));
		
		if ($affected === 0) {
			return null;
		}
		
		if ($affected === 1) {
			return [$this->getInsertedId()];
		}
		
		// if we haven't returned, then we inserted more than 1 row.  we can construct a
		// list of the IDs that were created by using the last ID and range as follows.
		// to identify our first ID, it would seem like $lastId - $affected would be enough,
		// but if we inserted 5 rows ending at 10, 10 - 5 = 5 and we don't want a range to
		// be [10,9,8,7,6,5] because that's six IDs.  so, we want to do 10 - (5 - 1) which
		// would result in [10,9,8,7,6] which is the correct response.
		
		$lastId = $this->getInsertedId();
		$firstId = $lastId - ($affected - 1);
		return range($lastId, $firstId);
	}
971858
public function execute($sequence = null)
    {
        $result = Db::query($this->getSql(), $this->params, $this->types);
        if ($result) {
            return Db::handler()->lastInsertId($sequence);
        }
        return $result;
    }
205805
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->prepare($sql, $params)->rowCount();
    }