15 $reset =
new ScopedCallback(
function () use (
$fname ) {
16 if ( $this->db->explicitTrxActive() ) {
17 $this->db->rollback( $fname );
19 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'foo' ),
$fname );
23 "CREATE TEMPORARY TABLE {$this->db->tableName( 'foo' )} (i INTEGER NOT NULL PRIMARY KEY)",
26 $this->db->insert(
'foo', [ [
'i' => 1 ], [
'i' => 2 ] ], __METHOD__ );
29 $this->db->begin( __METHOD__ );
31 'foo', [ [
'i' => 3 ], [
'i' => 2 ], [
'i' => 5 ] ], __METHOD__, [
'IGNORE' ]
33 $this->assertSame( 2, $this->db->affectedRows() );
35 [
'1',
'2',
'3',
'5' ],
36 $this->db->selectFieldValues(
'foo',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
38 $this->db->rollback( __METHOD__ );
41 $this->db->begin( __METHOD__ );
42 $this->db->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
45 'foo', [ [
'i' => 7 ], [
'i' =>
null ] ], __METHOD__, [
'IGNORE' ]
47 $this->db->endAtomic( __METHOD__ );
48 $this->fail(
'Expected exception not thrown' );
49 }
catch ( DBQueryError
$e ) {
50 $this->assertSame( 0, $this->db->affectedRows() );
51 $this->db->cancelAtomic( __METHOD__ );
55 $this->db->selectFieldValues(
'foo',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
57 $this->db->rollback( __METHOD__ );
98 $reset =
new ScopedCallback(
function () use (
$fname ) {
99 if ( $this->db->explicitTrxActive() ) {
100 $this->db->rollback( $fname );
102 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'foo' ),
$fname );
103 $this->db->query(
'DROP TABLE IF EXISTS ' . $this->db->tableName(
'bar' ),
$fname );
107 "CREATE TEMPORARY TABLE {$this->db->tableName( 'foo' )} (i INTEGER)",
111 "CREATE TEMPORARY TABLE {$this->db->tableName( 'bar' )} (i INTEGER NOT NULL PRIMARY KEY)",
114 $this->db->insert(
'bar', [ [
'i' => 1 ], [
'i' => 2 ] ], __METHOD__ );
117 $this->db->begin( __METHOD__ );
118 $this->db->insert(
'foo', [ [
'i' => 3 ], [
'i' => 2 ], [
'i' => 5 ] ], __METHOD__ );
119 $this->db->insertSelect(
'bar',
'foo', [
'i' =>
'i' ], [], __METHOD__, [
'IGNORE' ] );
120 $this->assertSame( 2, $this->db->affectedRows() );
122 [
'1',
'2',
'3',
'5' ],
123 $this->db->selectFieldValues(
'bar',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
125 $this->db->rollback( __METHOD__ );
128 $this->db->begin( __METHOD__ );
129 $this->db->insert(
'foo', [ [
'i' => 7 ], [
'i' =>
null ] ], __METHOD__ );
130 $this->db->startAtomic( __METHOD__, IDatabase::ATOMIC_CANCELABLE );
132 $this->db->insertSelect(
'bar',
'foo', [
'i' =>
'i' ], [], __METHOD__, [
'IGNORE' ] );
133 $this->db->endAtomic( __METHOD__ );
134 $this->fail(
'Expected exception not thrown' );
135 }
catch ( DBQueryError
$e ) {
136 $this->assertSame( 0, $this->db->affectedRows() );
137 $this->db->cancelAtomic( __METHOD__ );
141 $this->db->selectFieldValues(
'bar',
'i', [], __METHOD__, [
'ORDER BY' =>
'i' ] )
143 $this->db->rollback( __METHOD__ );