2017-03-09 03:16:35 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-03-09 03:16:35 +00:00
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse;
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
/**
|
2017-07-20 22:36:03 +00:00
|
|
|
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
|
|
|
|
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
|
2017-07-08 01:06:38 +00:00
|
|
|
class TestDbDriverSQLite3 extends Test\AbstractTest {
|
2017-03-10 02:39:42 +00:00
|
|
|
protected $data;
|
2017-04-07 01:41:21 +00:00
|
|
|
protected $drv;
|
2017-05-07 22:27:16 +00:00
|
|
|
protected $ch;
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function setUp() {
|
2017-12-19 17:11:49 +00:00
|
|
|
if (!Db\SQLite3\Driver::requirementsMet()) {
|
2017-05-22 14:02:36 +00:00
|
|
|
$this->markTestSkipped("SQLite extension not loaded");
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->clearData();
|
|
|
|
$conf = new Conf();
|
2017-07-22 19:29:12 +00:00
|
|
|
Arsse::$conf = $conf;
|
2017-04-07 01:41:21 +00:00
|
|
|
$conf->dbDriver = Db\SQLite3\Driver::class;
|
2017-10-19 19:32:18 +00:00
|
|
|
$conf->dbSQLite3Timeout = 0;
|
2017-04-07 01:41:21 +00:00
|
|
|
$conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
|
2017-10-19 19:32:18 +00:00
|
|
|
$this->drv = new Db\SQLite3\Driver();
|
2017-07-17 11:47:57 +00:00
|
|
|
$this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File);
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->ch->enableExceptions(true);
|
2017-03-09 03:16:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function tearDown() {
|
2017-03-09 03:16:35 +00:00
|
|
|
unset($this->drv);
|
2017-05-07 22:27:16 +00:00
|
|
|
unset($this->ch);
|
2017-08-29 14:50:31 +00:00
|
|
|
if (isset(Arsse::$conf)) {
|
2017-07-22 19:29:12 +00:00
|
|
|
unlink(Arsse::$conf->dbSQLite3File);
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->clearData();
|
2017-03-09 03:16:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testFetchDriverName() {
|
2017-07-17 11:47:57 +00:00
|
|
|
$class = Arsse::$conf->dbDriver;
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertTrue(strlen($class::driverName()) > 0);
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-11-29 23:14:59 +00:00
|
|
|
public function testCheckCharacterSetAcceptability() {
|
|
|
|
$this->assertTrue($this->drv->charsetAcceptable());
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecAValidStatement() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key)"));
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecAnInvalidStatement() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertException("engineErrorGeneral", "Db");
|
|
|
|
$this->drv->exec("And the meek shall inherit the earth...");
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecMultipleStatements() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertTrue($this->drv->exec("CREATE TABLE test(id integer primary key); INSERT INTO test(id) values(2112)"));
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(2112, $this->ch->querySingle("SELECT id from test"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecTimeout() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->ch->exec("BEGIN EXCLUSIVE TRANSACTION");
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertException("general", "Db", "ExceptionTimeout");
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecConstraintViolation() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->exec("CREATE TABLE test(id integer not null)");
|
|
|
|
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
|
|
|
$this->drv->exec("INSERT INTO test(id) values(null)");
|
|
|
|
}
|
2017-03-09 14:44:50 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testExecTypeViolation() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
$this->drv->exec("INSERT INTO test(id) values('ook')");
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testMakeAValidQuery() {
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->assertInstanceOf(Db\Result::class, $this->drv->query("SELECT 1"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testMakeAnInvalidQuery() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertException("engineErrorGeneral", "Db");
|
|
|
|
$this->drv->query("Apollo was astonished; Dionysus thought me mad");
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testQueryTimeout() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->ch->exec("BEGIN EXCLUSIVE TRANSACTION");
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertException("general", "Db", "ExceptionTimeout");
|
|
|
|
$this->drv->query("CREATE TABLE test(id integer primary key)");
|
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testQueryConstraintViolation() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->exec("CREATE TABLE test(id integer not null)");
|
|
|
|
$this->assertException("constraintViolation", "Db", "ExceptionInput");
|
|
|
|
$this->drv->query("INSERT INTO test(id) values(null)");
|
|
|
|
}
|
2017-03-09 14:44:50 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testQueryTypeViolation() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
|
|
|
$this->assertException("typeViolation", "Db", "ExceptionInput");
|
|
|
|
$this->drv->query("INSERT INTO test(id) values('ook')");
|
|
|
|
}
|
2017-03-09 19:48:42 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testPrepareAValidQuery() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$s = $this->drv->prepare("SELECT ?, ?", "int", "int");
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->assertInstanceOf(Db\Statement::class, $s);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 19:48:42 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testPrepareAnInvalidQuery() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertException("engineErrorGeneral", "Db");
|
|
|
|
$s = $this->drv->prepare("This is an invalid query", "int", "int");
|
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCreateASavepoint() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(2, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(3, $this->drv->savepointCreate());
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testReleaseASavepoint() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(true, $this->drv->savepointRelease());
|
2017-11-06 03:13:44 +00:00
|
|
|
$this->assertException("savepointInvalid", "Db");
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->drv->savepointRelease();
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testUndoASavepoint() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(true, $this->drv->savepointUndo());
|
2017-11-06 03:13:44 +00:00
|
|
|
$this->assertException("savepointInvalid", "Db");
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->drv->savepointUndo();
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testManipulateSavepoints() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(2, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(3, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(4, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(5, $this->drv->savepointCreate());
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->assertTrue($this->drv->savepointUndo(3));
|
|
|
|
$this->assertFalse($this->drv->savepointRelease(4));
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(6, $this->drv->savepointCreate());
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->assertFalse($this->drv->savepointRelease(5));
|
|
|
|
$this->assertTrue($this->drv->savepointRelease(6));
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(3, $this->drv->savepointCreate());
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->assertTrue($this->drv->savepointRelease(2));
|
2017-11-06 03:13:44 +00:00
|
|
|
$this->assertException("savepointStale", "Db");
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->drv->savepointRelease(2);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testManipulateSavepointsSomeMore() {
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->assertEquals(1, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(2, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(3, $this->drv->savepointCreate());
|
|
|
|
$this->assertEquals(4, $this->drv->savepointCreate());
|
|
|
|
$this->assertTrue($this->drv->savepointRelease(2));
|
|
|
|
$this->assertFalse($this->drv->savepointUndo(3));
|
2017-11-06 03:13:44 +00:00
|
|
|
$this->assertException("savepointStale", "Db");
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->drv->savepointUndo(2);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testBeginATransaction() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCommitATransaction() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr->commit();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testRollbackATransaction() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr->rollback();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(0, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testBeginChainedTransactions() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCommitChainedTransactions() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2->commit();
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
$tr1->commit();
|
|
|
|
$this->assertEquals(2, $this->ch->querySingle($select));
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCommitChainedTransactionsOutOfOrder() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
|
|
|
$tr1 = $this->drv->begin();
|
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
$tr2 = $this->drv->begin();
|
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1->commit();
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(2, $this->ch->querySingle($select));
|
|
|
|
$tr2->commit();
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testRollbackChainedTransactions() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2->rollback();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
$tr1->rollback();
|
|
|
|
$this->assertEquals(0, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testRollbackChainedTransactionsOutOfOrder() {
|
2017-05-07 22:27:16 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
|
|
|
$tr1 = $this->drv->begin();
|
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
$tr2 = $this->drv->begin();
|
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1->rollback();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(0, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
|
|
|
$tr2->rollback();
|
|
|
|
$this->assertEquals(0, $this->drv->query($select)->getValue());
|
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testPartiallyRollbackChainedTransactions() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$select = "SELECT count(*) FROM test";
|
|
|
|
$insert = "INSERT INTO test(id) values(null)";
|
|
|
|
$this->drv->exec("CREATE TABLE test(id integer primary key)");
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2 = $this->drv->begin();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->drv->query($insert);
|
|
|
|
$this->assertEquals(2, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr2->rollback();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(0, $this->ch->querySingle($select));
|
2017-05-06 16:02:27 +00:00
|
|
|
$tr1->commit();
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertEquals(1, $this->drv->query($select)->getValue());
|
2017-05-07 22:27:16 +00:00
|
|
|
$this->assertEquals(1, $this->ch->querySingle($select));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testFetchSchemaVersion() {
|
2017-04-07 01:41:21 +00:00
|
|
|
$this->assertSame(0, $this->drv->schemaVersion());
|
|
|
|
$this->drv->exec("PRAGMA user_version=1");
|
|
|
|
$this->assertSame(1, $this->drv->schemaVersion());
|
|
|
|
$this->drv->exec("PRAGMA user_version=2");
|
|
|
|
$this->assertSame(2, $this->drv->schemaVersion());
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
2017-03-09 22:25:50 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testLockTheDatabase() {
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->drv->savepointCreate(true);
|
|
|
|
$this->assertException();
|
|
|
|
$this->ch->exec("CREATE TABLE test(id integer primary key)");
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 22:25:50 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testUnlockTheDatabase() {
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->drv->savepointCreate(true);
|
|
|
|
$this->drv->savepointRelease();
|
2017-07-22 19:29:12 +00:00
|
|
|
$this->drv->savepointCreate(true);
|
|
|
|
$this->drv->savepointUndo();
|
2017-07-08 01:06:38 +00:00
|
|
|
$this->assertSame(true, $this->ch->exec("CREATE TABLE test(id integer primary key)"));
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|