Example #1
0
 /**
  * @covers Zend\Db\Adapter\Driver\Pdo\Pdo::getDatabasePlatformName
  */
 public function testGetDatabasePlatformName()
 {
     // Test platform name for SqlServer
     $this->pdo->getConnection()->setConnectionParameters(array('pdodriver' => 'sqlsrv'));
     $this->assertEquals('SqlServer', $this->pdo->getDatabasePlatformName());
     $this->assertEquals('SQLServer', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL));
 }
Example #2
0
 /**
  * @param \Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return $this
  */
 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');
 }
Example #3
0
 /**
  * @param \Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return $this
  */
 public function setDriver($driver)
 {
     if ($driver instanceof Pgsql\Pgsql || $driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Postgresql' || is_resource($driver) && in_array(get_resource_type($driver), array('pgsql link', 'pgsql link persistent')) || $driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql') {
         $this->resource = $driver;
         return $this;
     }
     throw new Exception\InvalidArgumentException('$driver must be a Pgsql or Postgresql PDO Zend\\Db\\Adapter\\Driver, pgsql link resource or Postgresql PDO instance');
 }
Example #4
0
 /**
  * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  *
  * @return self
  */
 public function setDriver($driver)
 {
     // handle Zend\Db drivers
     if ($driver instanceof Pdo\Pdo && in_array($driver->getDatabasePlatformName(), ['SqlServer', 'Dblib']) || $driver instanceof \PDO && in_array($driver->getAttribute(\PDO::ATTR_DRIVER_NAME), ['sqlsrv', 'dblib'])) {
         $this->resource = $driver;
         return $this;
     }
     throw new Exception\InvalidArgumentException('$driver must be a Sqlsrv PDO Zend\\Db\\Adapter\\Driver or Sqlsrv PDO instance');
 }
Example #5
0
 /**
  * @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo||\mysqli|\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return $this
  */
 public function setDriver($driver)
 {
     // handle Zend\Db drivers
     if ($driver instanceof Mysqli\Mysqli || $driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql' || $driver instanceof \mysqli || $driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') {
         $this->resource = $driver;
         return $this;
     }
     throw new Exception\InvalidArgumentException('$driver must be a Mysqli or Mysql PDO Zend\\Db\\Adapter\\Driver, Mysqli instance or MySQL PDO instance');
 }
Example #6
0
 /**
  * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo||resource|\PDO $driver
  * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
  * @return $this
  */
 public function setDriver($driver)
 {
     // handle Zend_Db drivers
     if ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlsrv') {
         /** @var $driver \Zend\Db\Adapter\Driver\DriverInterface */
         $this->resource = $driver->getConnection()->getResource();
         return $this;
     }
     // handle
     if ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlsrv') {
         $this->resource = $driver;
         return $this;
     }
     throw new Exception\InvalidArgumentException('$driver must be a Sqlsrv PDO Zend\\Db\\Adapter\\Driver or Sqlsrv PDO instance');
 }
Example #7
0
 /**
  * @param mixed $parameters
  * @throws Exception\InvalidQueryException
  * @return Result
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     /** START Standard ParameterContainer Merging Block */
     if (!$this->parameterContainer instanceof ParameterContainer) {
         if ($parameters instanceof ParameterContainer) {
             $this->parameterContainer = $parameters;
             $parameters = null;
         } else {
             $this->parameterContainer = new ParameterContainer();
         }
     }
     if (is_array($parameters)) {
         $this->parameterContainer->setFromArray($parameters);
     }
     if ($this->parameterContainer->count() > 0) {
         $this->bindParametersFromContainer();
     }
     /** END Standard ParameterContainer Merging Block */
     try {
         $this->resource->execute();
     } catch (\PDOException $e) {
         throw new Exception\InvalidQueryException('Statement could not be executed', null, $e);
     }
     $result = $this->driver->createResult($this->resource, $this);
     return $result;
 }
Example #8
0
 /**
  * {@inheritDoc}
  */
 public function quoteValue($value)
 {
     if ($this->resource instanceof DriverInterface) {
         $this->resource = $this->resource->getConnection()->getResource();
     }
     if ($this->resource) {
         if ($this->resource instanceof PDO) {
             return $this->resource->quote($value);
         }
         if (get_resource_type($this->resource) == 'oci8 connection' || get_resource_type($this->resource) == 'oci8 persistent connection') {
             return "'" . addcslashes(str_replace("'", "''", $value), "\n\r\"") . "'";
         }
     }
     trigger_error('Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' . 'can introduce security vulnerabilities in a production environment.');
     return "'" . addcslashes(str_replace("'", "''", $value), "\n\r\"") . "'";
 }
Example #9
0
 /**
  * Prepare
  *
  * @param  string    $sql
  * @return Statement
  */
 public function prepare($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $statement = $this->driver->createStatement($sql);
     return $statement;
 }
Example #10
0
 /**
  * @todo  Should this use the ability of PDOStatement to return objects of a specified class?
  * @param mixed $parameters
  * @return Result
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     $parameters = $parameters ?: ($parameters = $this->parameterContainer);
     if ($parameters != null) {
         if (is_array($parameters)) {
             $parameters = new ParameterContainer($parameters);
         }
         if (!$parameters instanceof ParameterContainerInterface) {
             throw new \InvalidArgumentException('ParameterContainer expected');
         }
         $this->bindParametersFromContainer($parameters);
     }
     if ($this->resource->execute() === false) {
         throw new Exception\InvalidQueryException($this->resource->error);
     }
     $result = $this->driver->createResult($this->resource);
     return $result;
 }
 /**
  * @covers Zend\Db\Adapter\Driver\Pdo\Connection::prepare
  */
 public function testPrepare()
 {
     $sqlsrv = new Pdo($this->variables);
     $connection = $sqlsrv->getConnection();
     $statement = $connection->prepare('SELECT \'foo\'');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Pdo\\Statement', $statement);
 }