modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-04-10 15:27:19 +04:00
parent 5c6d55ed46
commit ebbd9e06c0

View File

@ -7,6 +7,7 @@ use nulib\db\_private\Tvalues;
use nulib\db\IDatabase; use nulib\db\IDatabase;
use nulib\db\ITransactor; use nulib\db\ITransactor;
use nulib\php\func; use nulib\php\func;
use nulib\ValueException;
class Pgsql implements IDatabase { class Pgsql implements IDatabase {
use Tvalues; use Tvalues;
@ -163,28 +164,82 @@ class Pgsql implements IDatabase {
return $this->db; return $this->db;
} }
/**
* @return resource|false
*/
function _exec(string $query) {
return pg_query($this->db(), $query);
}
function exec($query, ?array $params=null) { function exec($query, ?array $params=null) {
// TODO: Implement exec() method. // TODO: Implement exec() method.
} }
function willUpdate(...$transactors): \nulib\db\ITransactor { /** @var ITransactor[] */
// TODO: Implement willUpdate() method. protected ?array $transactors = null;
function willUpdate(...$transactors): self {
foreach ($transactors as $transactor) {
if ($transactor instanceof ITransactor) {
$this->transactors[] = $transactor;
$transactor->willUpdate();
} else {
throw ValueException::invalid_type($transactor, ITransactor::class);
}
}
return $this;
} }
function inTransaction(): bool { function inTransaction(?bool &$inerror=null): bool {
// TODO: Implement inTransaction() method. $status = pg_transaction_status($this->db());
if ($status === PGSQL_TRANSACTION_ACTIVE || $status === PGSQL_TRANSACTION_INTRANS) {
$inerror = false;
return true;
} elseif ($status === PGSQL_TRANSACTION_INERROR) {
$inerror = true;
return true;
} else {
return false;
}
} }
function beginTransaction(?callable $func=null, bool $commit=true): void { function beginTransaction(?callable $func=null, bool $commit=true): void {
// TODO: Implement beginTransaction() method. $this->_exec("begin");
if ($this->transactors !== null) {
foreach ($this->transactors as $transactor) {
$transactor->beginTransaction();
}
}
if ($func !== null) {
$commited = false;
try {
func::call($func, $this);
if ($commit) {
$this->commit();
$commited = true;
}
} finally {
if ($commit && !$commited) $this->rollback();
}
}
} }
function commit(): void { function commit(): void {
// TODO: Implement commit() method. $this->_exec("commit");
if ($this->transactors !== null) {
foreach ($this->transactors as $transactor) {
$transactor->commit();
}
}
} }
function rollback(): void { function rollback(): void {
// TODO: Implement rollback() method. $this->_exec("rollback");
if ($this->transactors !== null) {
foreach ($this->transactors as $transactor) {
$transactor->rollback();
}
}
} }
function get($query, ?array $params=null, bool $entireRow=false) { function get($query, ?array $params=null, bool $entireRow=false) {