schemaGrammar)) { $this->useDefaultSchemaGrammar(); } return new FirebirdSchemaBuilder($this); } /** * Get the default schema grammar instance. * * @return \Firebird\Illuminate\Schema\Grammars\FirebirdGrammar */ protected function getDefaultSchemaGrammar() { return new FirebirdSchemaGrammar($this); // $this->withTablePrefix() } /** * Get the connection's last insert ID. * * @return string|int|null */ public function getLastInsertId() { return $this->lastInsertId; } /** * Get a new query builder instance. * * @return \Firebird\Illuminate\Query\FirebirdBuilder */ public function query() { return new FirebirdQueryBuilder( $this, $this->getQueryGrammar(), $this->getPostProcessor() ); } /** * Run an insert statement against the database. * * @param string $query * @param array $bindings * @param string|null $sequence * @return array */ public function insert($query, $bindings = [], $sequence = null) { return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) { if ($this->pretending()) { return true; } $statement = $this->getPdo()->prepare($query); $this->bindValues($statement, $this->prepareBindings($bindings)); $this->recordsHaveBeenModified(); $result = $statement->execute(); // Fetch the RETURNING clause result to get the actual ID used if ($result) { $row = $statement->fetch(\PDO::FETCH_ASSOC); if ($row) { // Get the first (and typically only) returned value $this->lastInsertId = reset($row); } } return $result; }); } /** * Run a select statement against the database. * * @param string $query * @param array $bindings * @param bool $useReadPdo * @return array */ public function select($query, $bindings = [], $useReadPdo = true) { return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { if ($this->pretending()) { return []; } // For select statements, we'll simply execute the query and return an array // of the database result set. Each element in the array will be a single // row from the database table, and will either be an array or objects. $statement = $this->prepared( $this->getPdoForSelect($useReadPdo)->prepare($query) ); $this->bindValues($statement, $this->prepareBindings($bindings)); $statement->execute(); $result = []; while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { $lowerCaseRow = array_change_key_case((array) $row, CASE_LOWER); $result[] = (object) $lowerCaseRow; } return count($result) > 0 ? $result : []; }); } /** * Run a select statement against the database and returns a generator. * * @param string $query * @param array $bindings * @param bool $useReadPdo * @return \Generator */ public function cursor($query, $bindings = [], $useReadPdo = true) { $statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { if ($this->pretending()) { return []; } // First we will create a statement for the query. Then, we will set the fetch // mode and prepare the bindings for the query. Once that's done we will be // ready to execute the query against the database and return the cursor. $statement = $this->prepared($this->getPdoForSelect($useReadPdo) ->prepare($query)); $this->bindValues( $statement, $this->prepareBindings($bindings) ); // Next, we'll execute the query against the database and return the statement // so we can return the cursor. The cursor will use a PHP generator to give // back one row at a time without using a bunch of memory to render them. $statement->execute(); return $statement; }); while ($record = $statement->fetch()) { $lowerCaseRow = array_change_key_case((array) $record, CASE_LOWER); yield (object) $lowerCaseRow; } } /** * Execute a stored procedure. * * @param string $procedure * @param array $values * @return Collection */ public function executeProcedure($procedure, array $values = []): Collection { return $this->query()->fromProcedure($procedure, $values)->get(); } }