2023-03-11 12:04:29 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Zend Framework (http://framework.zend.com/)
|
|
|
|
*
|
|
|
|
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
2023-04-01 09:03:34 +03:00
|
|
|
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
2023-03-11 12:04:29 +03:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Zend\Db\Adapter\Platform;
|
|
|
|
|
|
|
|
use Zend\Db\Adapter\Driver\DriverInterface;
|
|
|
|
use Zend\Db\Adapter\Driver\Pdo;
|
|
|
|
use Zend\Db\Adapter\Exception;
|
|
|
|
|
2023-04-01 09:03:34 +03:00
|
|
|
class Sqlite extends AbstractPlatform
|
2023-03-11 12:04:29 +03:00
|
|
|
{
|
2023-04-01 09:03:34 +03:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected $quoteIdentifier = array('"','"');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected $quoteIdentifierTo = '\'';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PDO
|
|
|
|
*/
|
2023-03-11 12:04:29 +03:00
|
|
|
protected $resource = null;
|
|
|
|
|
2023-04-01 09:03:34 +03:00
|
|
|
/**
|
|
|
|
* @param null|\Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver
|
|
|
|
*/
|
2023-03-11 12:04:29 +03:00
|
|
|
public function __construct($driver = null)
|
|
|
|
{
|
|
|
|
if ($driver) {
|
|
|
|
$this->setDriver($driver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-01 09:03:34 +03:00
|
|
|
* @param \Zend\Db\Adapter\Driver\Pdo\Pdo|\PDO $driver
|
2023-03-11 12:04:29 +03:00
|
|
|
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
|
2023-04-01 09:03:34 +03:00
|
|
|
*
|
|
|
|
* @return self
|
2023-03-11 12:04:29 +03:00
|
|
|
*/
|
|
|
|
public function setDriver($driver)
|
|
|
|
{
|
|
|
|
if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite')
|
|
|
|
|| ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite')
|
|
|
|
) {
|
|
|
|
$this->resource = $driver;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception\InvalidArgumentException('$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-01 09:03:34 +03:00
|
|
|
* {@inheritDoc}
|
2023-03-11 12:04:29 +03:00
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'SQLite';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-01 09:03:34 +03:00
|
|
|
* {@inheritDoc}
|
2023-03-11 12:04:29 +03:00
|
|
|
*/
|
|
|
|
public function quoteValue($value)
|
|
|
|
{
|
|
|
|
$resource = $this->resource;
|
|
|
|
|
|
|
|
if ($resource instanceof DriverInterface) {
|
|
|
|
$resource = $resource->getConnection()->getResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($resource instanceof \PDO) {
|
|
|
|
return $resource->quote($value);
|
|
|
|
}
|
|
|
|
|
2023-04-01 09:03:34 +03:00
|
|
|
return parent::quoteValue($value);
|
2023-03-11 12:04:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-01 09:03:34 +03:00
|
|
|
* {@inheritDoc}
|
2023-03-11 12:04:29 +03:00
|
|
|
*/
|
|
|
|
public function quoteTrustedValue($value)
|
|
|
|
{
|
|
|
|
$resource = $this->resource;
|
|
|
|
|
|
|
|
if ($resource instanceof DriverInterface) {
|
|
|
|
$resource = $resource->getConnection()->getResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($resource instanceof \PDO) {
|
|
|
|
return $resource->quote($value);
|
|
|
|
}
|
|
|
|
|
2023-04-01 09:03:34 +03:00
|
|
|
return parent::quoteTrustedValue($value);
|
2023-03-11 12:04:29 +03:00
|
|
|
}
|
|
|
|
}
|