1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-09 09:22:40 +00:00
Arsse/vendor/JKingWeb/NewsSync/Db/Common.php
J. King 6ffe942f99 SQLite3 database driver in working condition
PDO stub for now; other drivers to come
2016-10-05 22:08:43 -04:00

47 lines
No EOL
1.1 KiB
PHP

<?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);
}
}