/**
  * @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::execute
  */
 public function testExecute()
 {
     $ibmdb2 = new IbmDb2($this->variables);
     $statement = $ibmdb2->createStatement("SELECT 'foo' FROM SYSIBM.SYSDUMMY1");
     $this->assertSame($statement, $statement->prepare());
     $result = $statement->execute();
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Result', $result);
     unset($resource, $ibmdb2);
 }
 /**
  * Execute
  *
  * @param null $parameters
  * @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);
     }
     /** END Standard ParameterContainer Merging Block */
     if ($this->profiler) {
         $this->profiler->profilerStart($this);
     }
     set_error_handler(function () {
     }, E_WARNING);
     // suppress warnings
     $response = db2_execute($this->resource, $this->parameterContainer->getPositionalArray());
     restore_error_handler();
     if ($this->profiler) {
         $this->profiler->profilerFinish();
     }
     if ($response === false) {
         throw new Exception\RuntimeException(db2_stmt_errormsg($this->resource));
     }
     $result = $this->driver->createResult($this->resource);
     return $result;
 }
 public function testCreateStatement()
 {
     $driver = new IbmDb2(array());
     $resource = db2_connect($this->variables['database'], $this->variables['username'], $this->variables['password']);
     $stmtResource = db2_prepare($resource, 'SELECT 1 FROM SYSIBM.SYSDUMMY1');
     $driver->getConnection()->setResource($resource);
     $stmt = $driver->createStatement('SELECT 1 FROM SYSIBM.SYSDUMMY1');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
     $stmt = $driver->createStatement($stmtResource);
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
     $stmt = $driver->createStatement();
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
     $this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidArgumentException', 'only accepts an SQL string or a ibm_db2 resource');
     $driver->createStatement(new \stdClass());
 }
 /**
  * {@inheritDoc}
  */
 public function execute($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     if ($this->profiler) {
         $this->profiler->profilerStart($sql);
     }
     set_error_handler(function () {
     }, E_WARNING);
     // suppress warnings
     $resultResource = db2_exec($this->resource, $sql);
     restore_error_handler();
     if ($this->profiler) {
         $this->profiler->profilerFinish($sql);
     }
     // if the returnValue is something other than a pg result resource, bypass wrapping it
     if ($resultResource === false) {
         throw new Exception\InvalidQueryException(db2_stmt_errormsg());
     }
     return $this->driver->createResult($resultResource === true ? $this->resource : $resultResource);
 }
Beispiel #5
0
 /**
  * @depends testRegisterConnection
  * @covers Zend\Db\Adapter\Driver\IbmDb2\IbmDb2::getConnection
  */
 public function testGetConnection($mockConnection)
 {
     $conn = new \Zend\Db\Adapter\Driver\IbmDb2\Connection(array());
     $this->ibmdb2->registerConnection($conn);
     $this->assertSame($conn, $this->ibmdb2->getConnection());
 }
 /**
  * @covers Zend\Db\Adapter\Driver\IbmDb2\Connection::execute
  */
 public function testExecute()
 {
     $ibmdb2 = new IbmDb2($this->variables);
     $connection = $ibmdb2->getConnection();
     $result = $connection->execute('SELECT \'foo\' FROM SYSIBM.SYSDUMMY1');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Result', $result);
 }