/** * @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'); }
/** * Execute * * @param ParameterContainer|null $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) { $parameters = $this->parameterContainer->getPositionalArray(); } /** END Standard ParameterContainer Merging Block */ if ($this->profiler) { $this->profiler->profilerStart($this); } $resultResource = pg_execute($this->pgsql, $this->statementName, (array) $parameters); if ($this->profiler) { $this->profiler->profilerFinish(); } if ($resultResource === false) { throw new Exception\InvalidQueryException(pg_last_error()); } $result = $this->driver->createResult($resultResource); return $result; }
/** * @param string $sql * @throws Exception\InvalidQueryException * @return resource|\Zend\Db\ResultSet\ResultSetInterface */ public function execute($sql) { if (!$this->isConnected()) { $this->connect(); } $resultResource = pg_query($this->resource, $sql); //var_dump(pg_result_status($resultResource)); // if the returnValue is something other than a pg result resource, bypass wrapping it if ($resultResource === false) { throw new Exception\InvalidQueryException(pg_errormessage()); } $resultPrototype = $this->driver->createResult($resultResource === true ? $this->resource : $resultResource); return $resultPrototype; }
/** * @depends testRegisterConnection * @covers Zend\Db\Adapter\Driver\Pgsql\Pgsql::getConnection */ public function testGetConnection($mockConnection) { $conn = new \Zend\Db\Adapter\Driver\Pgsql\Connection(array()); $this->pgsql->registerConnection($conn); $this->assertSame($conn, $this->pgsql->getConnection()); }