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

Connection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 19
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A lastInsertId() 0 6 2
A trackLastInsertId() 0 2 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
 * @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