diff --git a/src/Adapter/SQLite.php b/src/Adapter/SQLite.php index 73d3949..3c1732a 100644 --- a/src/Adapter/SQLite.php +++ b/src/Adapter/SQLite.php @@ -27,7 +27,7 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface public function connect() : PdoObject { 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_EMULATE_PREPARES, false); $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 { switch($type) { + default: case static::IDENTIFIER_DATABASE: case static::IDENTIFIER_TABLE: case static::IDENTIFIER_FIELD: diff --git a/src/Common/PdoObject/SqlPdoObject.php b/src/Common/PdoObject/SqlPdoObject.php new file mode 100644 index 0000000..cc8c3f9 --- /dev/null +++ b/src/Common/PdoObject/SqlPdoObject.php @@ -0,0 +1,35 @@ +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(); + } +} \ No newline at end of file diff --git a/src/Common/PdoObject/SqlitePdoObject.php b/src/Common/PdoObject/SqlitePdoObject.php new file mode 100644 index 0000000..377c7db --- /dev/null +++ b/src/Common/PdoObject/SqlitePdoObject.php @@ -0,0 +1,20 @@ +openedTransaction ) { + return $this->beginImmediateTransaction(); + } + + return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false; + } + + protected function beginImmediateTransaction(): bool + { + return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false; + } +} \ No newline at end of file