Connection.php 2.02 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\DBAL\Portability;

5
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
6
use Doctrine\DBAL\Driver\Result as DriverResult;
7
use Doctrine\DBAL\Driver\Statement as DriverStatement;
8
use Doctrine\DBAL\ParameterType;
9

10 11 12
/**
 * Portability wrapper for a Connection.
 */
13
final class Connection implements ConnectionInterface
14
{
15 16 17 18 19 20
    public const PORTABILITY_ALL           = 255;
    public const PORTABILITY_NONE          = 0;
    public const PORTABILITY_RTRIM         = 1;
    public const PORTABILITY_EMPTY_TO_NULL = 4;
    public const PORTABILITY_FIX_CASE      = 8;

21 22
    /** @var ConnectionInterface */
    private $connection;
23

24 25
    /** @var Converter */
    private $converter;
26

27 28 29 30
    public function __construct(ConnectionInterface $connection, Converter $converter)
    {
        $this->connection = $connection;
        $this->converter  = $converter;
31 32
    }

33
    public function prepare(string $sql): DriverStatement
34
    {
35 36 37 38 39
        return new Statement(
            $this->connection->prepare($sql),
            $this->converter
        );
    }
40

41 42 43 44 45 46 47
    public function query(string $sql): DriverResult
    {
        return new Result(
            $this->connection->query($sql),
            $this->converter
        );
    }
48

49 50 51 52 53 54 55
    /**
     * {@inheritDoc}
     */
    public function quote($input, $type = ParameterType::STRING)
    {
        return $this->connection->quote($input, $type);
    }
Benjamin Morel's avatar
Benjamin Morel committed
56

57
    public function exec(string $sql): int
58
    {
59
        return $this->connection->exec($sql);
60
    }
61

Benjamin Morel's avatar
Benjamin Morel committed
62
    /**
63
     * {@inheritDoc}
Benjamin Morel's avatar
Benjamin Morel committed
64
     */
65
    public function lastInsertId($name = null)
66
    {
67
        return $this->connection->lastInsertId($name);
68
    }
69

70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function beginTransaction()
74
    {
75
        return $this->connection->beginTransaction();
76
    }
77

78 79 80 81
    /**
     * {@inheritDoc}
     */
    public function commit()
82
    {
83
        return $this->connection->commit();
84 85
    }

86 87 88 89
    /**
     * {@inheritDoc}
     */
    public function rollBack()
90
    {
91
        return $this->connection->rollBack();
92 93
    }
}