| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Pdo; |
| 13 |
|
| 14 |
if (\PHP_VERSION_ID < 80400 && \extension_loaded('pdo_sqlite')) { |
| 15 |
class Sqlite extends \PDO |
| 16 |
{ |
| 17 |
public const ATTR_EXTENDED_RESULT_CODES = \PHP_VERSION_ID >= 70400 ? \PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES : 1002; |
| 18 |
public const ATTR_OPEN_FLAGS = \PHP_VERSION_ID >= 70300 ? \PDO::SQLITE_ATTR_OPEN_FLAGS : 1000; |
| 19 |
public const ATTR_READONLY_STATEMENT = \PHP_VERSION_ID >= 70400 ? \PDO::SQLITE_ATTR_READONLY_STATEMENT : 1001; |
| 20 |
public const DETERMINISTIC = \PDO::SQLITE_DETERMINISTIC; |
| 21 |
public const OPEN_READONLY = \PHP_VERSION_ID >= 70300 ? \PDO::SQLITE_OPEN_READONLY : 1; |
| 22 |
public const OPEN_READWRITE = \PHP_VERSION_ID >= 70300 ? \PDO::SQLITE_OPEN_READWRITE : 2; |
| 23 |
public const OPEN_CREATE = \PHP_VERSION_ID >= 70300 ? \PDO::SQLITE_OPEN_CREATE : 4; |
| 24 |
|
| 25 |
public function __construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null) |
| 26 |
{ |
| 27 |
parent::__construct($dsn, $username, $password, $options); |
| 28 |
|
| 29 |
if ('sqlite' !== $driver = $this->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
| 30 |
throw new \PDOException(\sprintf('Pdo\Sqlite::__construct() cannot be used for connecting to the "%s" driver', $driver)); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): self |
| 35 |
{ |
| 36 |
try { |
| 37 |
return new self($dsn, $username, $password, $options); |
| 38 |
} catch (\PDOException $e) { |
| 39 |
throw preg_match('/^Pdo\\\\Sqlite::__construct\(\) cannot be used for connecting to the "([a-z]+)" driver/', $e->getMessage(), $matches) ? new \PDOException(\sprintf('Pdo\Sqlite::connect() cannot be used for connecting to the "%s" driver', $matches[1])) : $e; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
public function createAggregate(string $name, callable $step, callable $finalize, int $numArgs = -1): bool |
| 44 |
{ |
| 45 |
return $this->sqliteCreateAggregate($name, $step, $finalize, $numArgs); |
| 46 |
} |
| 47 |
|
| 48 |
public function createCollation(string $name, callable $callback): bool |
| 49 |
{ |
| 50 |
return $this->sqliteCreateCollation($name, $callback); |
| 51 |
} |
| 52 |
|
| 53 |
public function createFunction(string $function_name, callable $callback, int $num_args = -1, int $flags = 0): bool |
| 54 |
{ |
| 55 |
return $this->sqliteCreateFunction($function_name, $callback, $num_args, $flags); |
| 56 |
} |
| 57 |
} |
| 58 |
} |