14 $reset =
new ScopedCallback(
function () {
15 if ( $this->db->explicitTrxActive() ) {
16 $this->db->rollback( __METHOD__ );
18 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'foo' ) );
22 "CREATE TEMPORARY TABLE {$this->db->tableName( 'foo' )} (i INTEGER NOT NULL PRIMARY KEY)"
24 $this->db->insert(
'foo', [ [
'i' => 1 ], [
'i' => 2 ] ], __METHOD__ );
27 $this->db->begin( __METHOD__ );
29 'foo', [ [
'i' => 3 ], [
'i' => 2 ], [
'i' => 5 ] ], __METHOD__, [
'IGNORE' ]
31 $this->assertSame( 2, $this->db->affectedRows() );
33 [
'1',
'2',
'3',
'5' ],
34 $this->db->selectFieldValues(
'foo',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
36 $this->db->rollback( __METHOD__ );
39 $this->db->begin( __METHOD__ );
40 $this->db->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
43 'foo', [ [
'i' => 7 ], [
'i' =>
null ] ], __METHOD__, [
'IGNORE' ]
45 $this->db->endAtomic( __METHOD__ );
46 $this->fail(
'Expected exception not thrown' );
47 }
catch ( DBQueryError
$e ) {
48 $this->assertSame( 0, $this->db->affectedRows() );
49 $this->db->cancelAtomic( __METHOD__ );
53 $this->db->selectFieldValues(
'foo',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
55 $this->db->rollback( __METHOD__ );
95 $reset =
new ScopedCallback(
function () {
96 if ( $this->db->explicitTrxActive() ) {
97 $this->db->rollback( __METHOD__ );
99 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'foo' ) );
100 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'bar' ) );
104 "CREATE TEMPORARY TABLE {$this->db->tableName( 'foo' )} (i INTEGER)"
107 "CREATE TEMPORARY TABLE {$this->db->tableName( 'bar' )} (i INTEGER NOT NULL PRIMARY KEY)"
109 $this->db->insert(
'bar', [ [
'i' => 1 ], [
'i' => 2 ] ], __METHOD__ );
112 $this->db->begin( __METHOD__ );
113 $this->db->insert(
'foo', [ [
'i' => 3 ], [
'i' => 2 ], [
'i' => 5 ] ], __METHOD__ );
114 $this->db->insertSelect(
'bar',
'foo', [
'i' =>
'i' ], [], __METHOD__, [
'IGNORE' ] );
115 $this->assertSame( 2, $this->db->affectedRows() );
117 [
'1',
'2',
'3',
'5' ],
118 $this->db->selectFieldValues(
'bar',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
120 $this->db->rollback( __METHOD__ );
123 $this->db->begin( __METHOD__ );
124 $this->db->insert(
'foo', [ [
'i' => 7 ], [
'i' =>
null ] ], __METHOD__ );
125 $this->db->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
127 $this->db->insertSelect(
'bar',
'foo', [
'i' =>
'i' ], [], __METHOD__, [
'IGNORE' ] );
128 $this->db->endAtomic( __METHOD__ );
129 $this->fail(
'Expected exception not thrown' );
130 }
catch ( DBQueryError
$e ) {
131 $this->assertSame( 0, $this->db->affectedRows() );
132 $this->db->cancelAtomic( __METHOD__ );
136 $this->db->selectFieldValues(
'bar',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
138 $this->db->rollback( __METHOD__ );