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

Connection::lastInsertId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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