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

Connection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 19
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
class Connection extends PDOConnection
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function lastInsertId($name = null) : string
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