Failed Conditions
Pull Request — master (#3074)
by Sergei
12:41
created

Connection::lastInsertId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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
class Connection extends PDOConnection
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function lastInsertId($name = null) : int
16
    {
17
        try {
18
            return $this->fetchLastInsertId($name);
19
        } catch (\PDOException $exception) {
20
            return 0;
21
        }
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function trackLastInsertId() : void
28
    {
29
        // Do not track last insert ID as it is not considered "safe" and can cause transactions to fail.
30
        // If there is no last insert ID yet, we get an error with SQLSTATE 55000:
31
        // "Object not in prerequisite state: 7 ERROR:  lastval is not yet defined in this session"
32
        // That error can modify the transaction/connection state.
33
    }
34
}
35