예제 #1
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');
 }
예제 #2
0
 /**
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Statement::execute
  */
 public function testExecute()
 {
     $sqlsrv = new Sqlsrv($this->variables);
     $statement = $sqlsrv->createStatement("SELECT 'foo'");
     $this->assertSame($statement, $statement->prepare());
     $result = $statement->execute();
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Result', $result);
     unset($resource, $sqlsrvResource);
 }
예제 #3
0
 public function testCreateStatement()
 {
     $driver = new Sqlsrv(array());
     $resource = sqlsrv_connect($this->variables['hostname'], array('UID' => $this->variables['username'], 'PWD' => $this->variables['password']));
     $driver->getConnection()->setResource($resource);
     $stmt = $driver->createStatement('SELECT 1');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $stmt);
     $stmt = $driver->createStatement($resource);
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $stmt);
     $this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidArgumentException', 'only accepts an SQL string or a Sqlsrv resource');
     $driver->createStatement(new \stdClass());
 }
예제 #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 $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');
 }
예제 #5
0
 /**
  * Execute
  *
  * @param  array|ParameterContainer $parameters
  * @throws Exception\RuntimeException
  * @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 */
     $resultValue = sqlsrv_execute($this->resource);
     if ($resultValue === false) {
         $errors = sqlsrv_errors();
         // ignore general warnings
         if ($errors[0]['SQLSTATE'] != '01000') {
             throw new Exception\RuntimeException($errors[0]['message']);
         }
     }
     $result = $this->driver->createResult($this->resource);
     return $result;
 }
예제 #6
0
 /**
  * Execute
  * 
  * @param  array|ParameterContainerInterface $parameters
  * @return type 
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     if ($parameters !== null) {
         if (is_array($parameters)) {
             $parameters = new ParameterContainer($parameters);
         }
         if (!$parameters instanceof ParameterContainerInterface) {
             throw new \InvalidArgumentException('ParameterContainer expected');
         }
         $this->parameterContainer = $parameters;
     }
     if ($this->parameterContainer) {
         $this->bindParametersFromContainer();
     }
     $resultValue = sqlsrv_execute($this->resource);
     if ($resultValue === false) {
         $errors = sqlsrv_errors();
         // ignore general warnings
         if ($errors[0]['SQLSTATE'] != '01000') {
             throw new \RuntimeException($errors[0]['message']);
         }
     }
     $result = $this->driver->createResult($this->resource);
     return $result;
 }
예제 #7
0
 /**
  * Prepare
  *
  * @param  string $sql
  * @return string
  */
 public function prepare($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $statement = $this->driver->createStatement($sql);
     return $statement;
 }
예제 #8
0
 /**
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Connection::prepare
  */
 public function testPrepare()
 {
     $sqlsrv = new Sqlsrv($this->variables);
     $connection = $sqlsrv->getConnection();
     $statement = $connection->prepare('SELECT \'foo\'');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Statement', $statement);
 }
예제 #9
0
 /**
  * @depends testRegisterConnection
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::getConnection
  */
 public function testGetConnection($mockConnection)
 {
     $conn = new \Zend\Db\Adapter\Driver\Sqlsrv\Connection(array());
     $this->sqlsrv->registerConnection($conn);
     $this->assertSame($conn, $this->sqlsrv->getConnection());
 }
예제 #10
0
 /**
  * @group integration-sqlserver
  * @covers Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv::checkEnvironment
  */
 public function testCheckEnvironment()
 {
     $sqlserver = new Sqlsrv(array());
     $this->assertNull($sqlserver->checkEnvironment());
 }