conn, $sql, $bindings, $incarnation); } function __construct(PdoConn $conn, ?string $sql=null, ?array $filter=null, ?IRowIncarnation $incarnation=null) { $this->conn = $conn; if ($incarnation === null) $incarnation = $this->newRowIncarnation(); $this->setIncarnation($incarnation); $this->select($sql, $filter); } protected function _execute(bool $commit): IRowIterator { $sql = $this->validateFilter(); if ($sql === null) $sql = $this->sql; $incarnation = $this->incarnation; switch ($this->type) { case self::TYPE_SELECT: $incarnation->createBindings($bindings, $this->filter); return $this->newRowIterator($sql, $bindings, $incarnation); case self::TYPE_UPDATE; $incarnation->createBindings($bindings, $this->filter, $this->row, $this->results); $incarnation->prepareBindings($bindings); ["num_rows" => $numRows ] = $this->conn->_execute($sql, $bindings, PdoConn::EXECUTE_PARAMS_DML_UPDATE); $incarnation->loadResults($this->results, $bindings); if ($commit) $this->commit(); return new OneRowIterator([ "num_rows" => $numRows, ]); case self::TYPE_INSERT: $incarnation->createBindings($bindings, $this->filter, $this->row, $this->results); $incarnation->prepareBindings($bindings); ["insert_id" => $insertId ] = $this->conn->_execute($sql, $bindings, PdoConn::EXECUTE_PARAMS_DML_INSERT); $incarnation->loadResults($this->results, $bindings); if ($commit) $this->commit(); return new OneRowIterator([ "insert_id" => $insertId, ]); default: throw IllegalAccessException::unexpected_state(); } } function beginTransaction(): IQuery { $this->conn->beginTransaction(); return $this; } function commit(): IQuery { $this->conn->commit(); return $this; } function rollback(): IQuery { $this->conn->rollback(); return $this; } }