Failed Conditions
Pull Request — master (#3074)
by Sergei
15:08
created

Connection::trackLastInsertId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 0
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Doctrine\DBAL\Driver\PDOPgSql;
4
5
use Doctrine\DBAL\Driver\PDOConnection;
6
7
/**
8
 * pdo_pgsql connection implementation.
9
 *
10
 * @author Steve Müller <[email protected]>
11
 */
12
class Connection extends PDOConnection
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function lastInsertId($name = null) : string
18
    {
19
        try {
20
            return $this->fetchLastInsertId($name);
21
        } catch (\PDOException $exception) {
22
            return '0';
23
        }
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function trackLastInsertId() : void
30
    {
31
        // Do not track last insert ID as it is not considered "safe" and can cause transactions to fail.
32
        // If there is no last insert ID yet, we get an error with SQLSTATE 55000:
33
        // "Object not in prerequisite state: 7 ERROR:  lastval is not yet defined in this session"
34
        // That error can modify the transaction/connection state.
35
    }
36
}
37