/**
 * @var \Zend\Db\Adapter\Driver\Pdo\Result $results
 * @var \Zend\Db\Adapter\Driver\StatementInterface $statement
 */
function renderResults(Result $results, StatementInterface $statement = null)
{
    $headers = [];
    $queryInformation = null;
    $outputData = null;
    $resultContents = null;
    if ($statement) {
        $queryInformation = SqlFormatter::format($statement->getSql());
        if ($statement->getParameterContainer()->count()) {
            $queryInformation .= createTable(array_keys($statement->getParameterContainer()->getNamedArray()), [array_values($statement->getParameterContainer()->getNamedArray())]);
        }
    }
    if ($results->count()) {
        foreach ($results as $result) {
            $headers = array_keys($result);
            $outputData[] = $result;
        }
    }
    // Results
    if ($outputData) {
        $resultContents = createTable([$headers], $outputData);
    }
    // Wrapper Table
    $table = new Table(new ConsoleOutput());
    $table->setHeaders([['Query Results', 'Generated SQL']])->setRows([[$resultContents, $queryInformation]])->render();
}
예제 #2
0
 /**
  * Tests current method returns same data on consecutive calls.
  *
  * @covers Zend\Db\Adapter\Driver\Pdo\Result::current
  */
 public function testCurrent()
 {
     $stub = $this->getMock('PDOStatement');
     $stub->expects($this->any())->method('fetch')->will($this->returnCallback(function () {
         return uniqid();
     }));
     $result = new Result();
     $result->initialize($stub, null);
     $this->assertEquals($result->current(), $result->current());
 }
 private function MapResultSetToEntity(Result $rJobs)
 {
     /* @var $oJobQueueEntity JobQueueEntity */
     $oJobQueueEntity = $rJobs->getResource()->fetchObject('Classes\\Entities\\JobQueue');
     if ($oJobQueueEntity instanceof JobQueueEntity === false) {
         throw new ImporterException('Mapping result set to instance of JobQueue Entity failed');
     }
     return $oJobQueueEntity;
 }