public function injectProfilingStatementPrototype(array $options = array())
 {
     $profiler = $this->getProfiler();
     if (!$profiler instanceof Profiler) {
         throw new \InvalidArgumentException('No profiler attached!');
     }
     $driver = $this->getDriver();
     if (method_exists($driver, 'registerStatementPrototype')) {
         $driverName = get_class($driver);
         switch ($driverName) {
             case 'Zend\\Db\\Adapter\\Driver\\IbmDb2\\IbmDb2':
                 $statementPrototype = new ZdbDriver\IbmDb2\Statement();
                 break;
             case 'Zend\\Db\\Adapter\\Driver\\Mysqli\\Mysqli':
                 $defaults = array('buffer_results' => false);
                 $options = array_intersect_key(array_merge($defaults, $options), $defaults);
                 $statementPrototype = new ZdbDriver\Mysqli\Statement($options['buffer_results']);
                 break;
             case 'Zend\\Db\\Adapter\\Driver\\Oci8\\Oci8':
                 $statementPrototype = new ZdbDriver\Oci8\Statement();
                 break;
             case 'Zend\\Db\\Adapter\\Driver\\Sqlsrv\\Sqlsrv':
                 $statementPrototype = new ZdbDriver\Sqlsrv\Statement();
                 break;
             case 'Zend\\Db\\Adapter\\Driver\\Pgsql\\Pgsql':
                 $statementPrototype = new ZdbDriver\Pgsql\Statement();
                 break;
             case 'Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo':
             default:
                 $statementPrototype = new ZdbDriver\Pdo\Statement();
         }
         $statementPrototype->setProfiler($this->getProfiler());
         $driver->registerStatementPrototype($statementPrototype);
     }
 }
Example #2
0
 /**
  * @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement
  * @return int
  */
 public function getCountForStatement(Pdo\Statement $statement)
 {
     $countStmt = clone $statement;
     $sql = $statement->getSql();
     if ($sql == '' || stripos($sql, 'select') === false) {
         return null;
     }
     $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
     $countStmt->prepare($countSql);
     $result = $countStmt->execute();
     $countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
     unset($statement, $result);
     return $countRow['count'];
 }
Example #3
0
 /**
  * @covers Zend\Db\Adapter\Driver\Pdo\Statement::execute
  */
 public function testExecute()
 {
     $this->statement->setDriver(new Pdo(new Connection($pdo = new TestAsset\SqliteMemoryPdo())));
     $this->statement->initialize($pdo);
     $this->statement->prepare('SELECT 1');
     $this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\Pdo\\Result', $this->statement->execute());
 }
Example #4
0
 /**
  * Execute the statement
  *
  * @param   mixed $parameters
  * @return  \Zend\Db\Adapter\Driver\Pdo\Result
  * @throws  InvalidQueryException
  */
 public function execute($parameters = null)
 {
     try {
         return parent::execute($parameters);
     } catch (InvalidQueryException $exception) {
         throw new InvalidQueryException($exception->getMessage() . ':' . PHP_EOL . $this->resource->queryString, $exception->getCode(), $exception);
     }
 }
Example #5
0
 public function execute($parameters = null)
 {
     if ($parameters === null) {
         if ($this->parameterContainer != null) {
             $saveParams = (array) $this->parameterContainer->getNamedArray();
         } else {
             $saveParams = array();
         }
     } else {
         $saveParams = $parameters;
     }
     $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     $queryId = $this->getProfiler()->startQuery($this->getSql(), $saveParams, $stack);
     $result = parent::execute($parameters);
     $this->getProfiler()->endQuery($queryId);
     return $result;
 }
Example #6
0
 /**
  * Register statement prototype
  * 
  * @param Statement $statementPrototype 
  */
 public function registerStatementPrototype(Statement $statementPrototype)
 {
     $this->statementPrototype = $statementPrototype;
     $this->statementPrototype->setDriver($this);
 }
 public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding()
 {
     $this->pdoStatementMock->expects($this->any())->method('bindParam')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(\PDO::PARAM_STR));
     $this->statement->execute(array('foo' => 'bar'));
 }