/**
  * Tests that the statement will not be executed twice if the iterator
  * is requested more than once
  *
  * @return void
  */
 public function testNoDoubleExecution()
 {
     $inner = $this->getMockBuilder('\\PDOStatement')->getMock();
     $driver = $this->getMockBuilder('\\Cake\\Database\\Driver')->getMock();
     $statement = new StatementDecorator($inner, $driver);
     $inner->expects($this->once())->method('execute');
     $this->assertSame($inner, $statement->getIterator());
     $this->assertSame($inner, $statement->getIterator());
 }
 /**
  * Tests that calling lastInsertId will get the
  *
  * @return void
  */
 public function testLastInsertIdWithReturning()
 {
     $internal = $this->getMock('\\PDOStatement');
     $driver = $this->getMock('\\Cake\\Database\\Driver');
     $statement = new StatementDecorator($internal, $driver);
     $internal->expects($this->once())->method('columnCount')->will($this->returnValue(1));
     $internal->expects($this->once())->method('fetch')->with('assoc')->will($this->returnValue(['id' => 2]));
     $driver->expects($this->never())->method('lastInsertId');
     $this->assertEquals(2, $statement->lastInsertId('users', 'id'));
 }
 /**
  * Wrapper for bindValue function to gather each parameter to be later used
  * in the logger function.
  *
  * @param string|int $column name or param position to be bound
  * @param mixed $value The value to bind to variable in query
  * @param string|int $type PDO type or name of configured Type class
  * @return void
  */
 public function bindValue($column, $value, $type = 'string')
 {
     parent::bindValue($column, $value, $type);
     if ($type === null) {
         $type = 'string';
     }
     if (!ctype_digit($type)) {
         $value = $this->cast($value, $type)[0];
     }
     $this->_compiledParams[$column] = $value;
 }
 /**
  * Returns the number of rows returned of affected by last execution
  *
  * @return int
  */
 public function rowCount()
 {
     //        if (preg_match('/^(?:DELETE|UPDATE|INSERT)/i', $this->_statement->queryString)) {
     //            $changes = $this->_driver->prepare('SELECT CHANGES()');
     //            $changes->execute();
     //            $count = $changes->fetch()[0];
     //            $changes->closeCursor();
     //            return (int)$count;
     //        }
     return parent::rowCount();
 }
 public function __construct($sql, $driver)
 {
     $this->_sql = $sql;
     $this->_queryString = $sql;
     parent::__construct(null, $driver);
 }
 /**
  * VERY HACKY: Override fetch to UN-auto-shorten identifiers,
  * which is done in OracleDialectTrait "quoteIdentifier"
  *
  * {@inheritDoc}
  */
 public function fetch($type = 'num')
 {
     $row = parent::fetch($type);
     if ($type == 'assoc' && is_array($row) && !empty($this->_driver->autoShortenedIdentifiers)) {
         //Need to preserve order of row results
         $translatedRow = [];
         foreach ($row as $key => $val) {
             if (array_key_exists($key, $this->_driver->autoShortenedIdentifiers)) {
                 $translatedRow[$this->_driver->autoShortenedIdentifiers[$key]] = $val;
             } else {
                 $translatedRow[$key] = $val;
             }
         }
         $row = $translatedRow;
     }
     return $row;
 }