Test Failed
Pull Request — master (#2765)
by Marco
04:16
created

Connection::trackLastInsertId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Driver\PDOPgSql;
21
22
use Doctrine\DBAL\Driver\PDOConnection;
23
24
/**
25
 * pdo_pgsql connection implementation.
26
 *
27
 * @author Steve Müller <[email protected]>
28
 */
29
class Connection extends PDOConnection
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function lastInsertId($name = null) : string
35
    {
36
        try {
37
            return $this->fetchLastInsertId($name);
38
        } catch (\PDOException $exception) {
39
            return '0';
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function trackLastInsertId() : void
47
    {
48
        // Do not track last insert ID as it is not considered "safe" and can cause transactions to fail.
49
        // If there is no last insert ID yet, we get an error with SQLSTATE 55000:
50
        // "Object not in prerequisite state: 7 ERROR:  lastval is not yet defined in this session"
51
        // That error can modify the transaction/connection state.
52
    }
53
}
54