silverstripe-framework/tests/model/TransactionTest.php
Damian Mooyman d8e9af8af8 API New Database abstraction layer. Ticket #7429
Database abstraction broken up into controller, connector, query builder, and schema manager, each independently configurable via YAML / Injector
Creation of new DBQueryGenerator for database specific generation of SQL
Support for parameterised queries, move of code base to use these over escaped conditions
Refactor of SQLQuery into separate query classes for each of INSERT UPDATE DELETE and SELECT
Support for PDO
Installation process upgraded to use new ORM
SS_DatabaseException created to handle database errors, maintaining details of raw sql and parameter details for user code designed interested in that data.
Renamed DB static methods to conform correctly to naming conventions (e.g. DB::getConn -> DB::get_conn)
3.2 upgrade docs
Performance Optimisation and simplification of code to use more concise API
API Ability for database adapters to register extensions to ConfigureFromEnv.php
2014-07-09 18:04:05 +12:00

64 lines
1.7 KiB
PHP

<?php
/**
* @package framework
* @subpackage tests
*/
class TransactionTest extends SapphireTest {
protected $extraDataObjects = array(
'TransactionTest_Object'
);
public function testCreateWithTransaction() {
if(DB::get_conn()->supportsTransactions()==true){
DB::get_conn()->transactionStart();
$obj=new TransactionTest_Object();
$obj->Title='First page';
$obj->write();
$obj=new TransactionTest_Object();
$obj->Title='Second page';
$obj->write();
//Create a savepoint here:
DB::get_conn()->transactionSavepoint('rollback');
$obj=new TransactionTest_Object();
$obj->Title='Third page';
$obj->write();
$obj=new TransactionTest_Object();
$obj->Title='Fourth page';
$obj->write();
//Revert to a savepoint:
DB::get_conn()->transactionRollback('rollback');
DB::get_conn()->transactionEnd();
$first=DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
$second=DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
$third=DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
$fourth=DataObject::get('TransactionTest_Object', "\"Title\"='Fourth page'");
//These pages should be in the system
$this->assertTrue(is_object($first) && $first->exists());
$this->assertTrue(is_object($second) && $second->exists());
//These pages should NOT exist, we reverted to a savepoint:
$this->assertFalse(is_object($third) && $third->exists());
$this->assertFalse(is_object($fourth) && $fourth->exists());
} else {
$this->markTestSkipped('Current database does not support transactions');
}
}
}
class TransactionTest_Object extends DataObject implements TestOnly {
private static $db = array(
'Title' => 'Varchar(255)'
);
}