1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-09 17:32:40 +00:00
Arsse/vendor/JKingWeb/NewsSync/Db/Common.php

47 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync\Db;
Trait Common {
protected $transDepth;
public function begin(): bool {
if($this->transDepth==0) {
$this->exec("BEGIN TRANSACTION");
} else{
$this->exec("SAVEPOINT newssync_".$this->transDepth);
}
$this->transDepth += 1;
return true;
}
public function commit(bool $all = false): bool {
if($this->transDepth==0) return false;
if(!$all) {
$this->exec("RELEASE SAVEPOINT newssync_".$this->transDepth-1);
$this->transDepth -= 1;
} else {
$this->exec("COMMIT TRANSACTION");
$this->transDepth = 0;
}
return true;
}
public function rollback(bool $all = false): bool {
if($this->transDepth==0) return false;
if(!$all) {
$this->exec("ROLLBACK TRANSACTION TO SAVEPOINT newssync_".$this->transDepth-1);
$this->transDepth -= 1;
if($this->transDepth==0) $this->exec("ROLLBACK TRANSACTION");
} else {
$this->exec("ROLLBACK TRANSACTION");
$this->transDepth = 0;
}
return true;
}
public function prepare(string $query, string ...$paramType): Statement {
return $this->prepareArray($query, $paramType);
}
}