Merge branch 'notes-2.x' of https://git.mcnd.ca/mcndave/ulmus into notes-2.x
This commit is contained in:
commit
d4181065cf
|
@ -27,7 +27,7 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||||
public function connect() : PdoObject
|
public function connect() : PdoObject
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$pdo = new PdoObject($this->buildDataSourceName(), null, null);
|
$pdo = new PdoObject\SqlitePdoObject($this->buildDataSourceName(), null, null);
|
||||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||||
|
@ -64,6 +64,7 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||||
public function escapeIdentifier(string $segment, int $type) : string
|
public function escapeIdentifier(string $segment, int $type) : string
|
||||||
{
|
{
|
||||||
switch($type) {
|
switch($type) {
|
||||||
|
default:
|
||||||
case static::IDENTIFIER_DATABASE:
|
case static::IDENTIFIER_DATABASE:
|
||||||
case static::IDENTIFIER_TABLE:
|
case static::IDENTIFIER_TABLE:
|
||||||
case static::IDENTIFIER_FIELD:
|
case static::IDENTIFIER_FIELD:
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Ulmus\Common\PdoObject;
|
||||||
|
|
||||||
|
class SqlPdoObject extends \Ulmus\Common\PdoObject
|
||||||
|
{
|
||||||
|
protected int $openedTransaction = 0;
|
||||||
|
|
||||||
|
public function beginTransaction(): bool
|
||||||
|
{
|
||||||
|
if ( 0 === ++$this->openedTransaction ) {
|
||||||
|
return parent::beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commit() : bool
|
||||||
|
{
|
||||||
|
if ( 0 === --$this->openedTransaction) {
|
||||||
|
return parent::commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rollback() : bool
|
||||||
|
{
|
||||||
|
if (0 !== $this->openedTransaction) {
|
||||||
|
return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::rollback();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Ulmus\Common\PdoObject;
|
||||||
|
|
||||||
|
class SqlitePdoObject extends SqlPdoObject
|
||||||
|
{
|
||||||
|
public function beginTransaction(): bool
|
||||||
|
{
|
||||||
|
if ( 0 === ++$this->openedTransaction ) {
|
||||||
|
return $this->beginImmediateTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beginImmediateTransaction(): bool
|
||||||
|
{
|
||||||
|
return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue