Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
addiks committed Nov 14, 2016
2 parents 751ab3a + 24a74e6 commit 8cf2880
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 66 deletions.
237 changes: 237 additions & 0 deletions src/Addiks/PHPSQL/Iterators/AliasedResourceIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?php
/**
* Copyright (C) 2015 Gerrit Addiks.
* This package (including this file) was released under the terms of the GPL-3.0.
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
* @license GPL-3.0
* @author Gerrit Addiks <[email protected]>
*/

namespace Addiks\PHPSQL\Iterators;

use Iterator;
use Addiks\PHPSQL\Iterators\DataProviderInterface;
use Addiks\PHPSQL\Iterators\UsesBinaryDataInterface;
use IteratorAggregate;

class AliasedResourceIterator implements Iterator, DataProviderInterface, UsesBinaryDataInterface
{

public function __construct(
DataProviderInterface $dataProvider,
$alias
) {
$this->dataProvider = $dataProvider;
$this->alias = $alias;
}

/**
* @var DataProviderInterface
*/
protected $dataProvider;

/**
* @var string
*/
protected $alias;

/**
*
* @return TableSchema
*/
public function getTableSchema()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->getTableSchema();
}

public function doesRowExists($rowId = null)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->doesRowExists($rowId);
}

public function getRowData($rowId = null)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->getRowData($rowId);
}

public function getCellData($rowId, $columnId)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->getCellData($rowId, $columnId);
}

public function tell()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->tell();
}

public function seek($rowId)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->seek($rowId);
}

public function count()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

return $dataProvider->count();
}

public function usesBinaryData()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

/* @var $usesBinaryData boolean */
$usesBinaryData = false;

if ($dataProvider instanceof UsesBinaryDataInterface) {
$usesBinaryData = $dataProvider->usesBinaryData();
}

return $usesBinaryData;
}

public function convertDataRowToStringRow(array $row)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

/* @var $convertedRow array */
$convertedRow = $row;

#if ($dataProvider instanceof UsesBinaryDataInterface && $dataProvider->usesBinaryData()) {
# $convertedRow = $dataProvider->convertDataRowToStringRow($row);
#}

return $convertedRow;
}

public function convertStringRowToDataRow(array $row)
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

/* @var $convertedRow array */
$convertedRow = $row;

if ($dataProvider instanceof UsesBinaryDataInterface && $dataProvider->usesBinaryData()) {
$convertedRow = $dataProvider->convertStringRowToDataRow($row);
}

return $convertedRow;
}

public function rewind()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

if ($dataProvider instanceof IteratorAggregate) {
$dataProvider = $dataProvider->getIterator();
}

if ($dataProvider instanceof Iterator) {
$dataProvider->rewind();
}
}

public function valid()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

if ($dataProvider instanceof IteratorAggregate) {
$dataProvider = $dataProvider->getIterator();
}

if ($dataProvider instanceof Iterator) {
return $dataProvider->valid();
}
}

public function key()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

if ($dataProvider instanceof IteratorAggregate) {
$dataProvider = $dataProvider->getIterator();
}

if ($dataProvider instanceof Iterator) {
return $dataProvider->key();
}
}

public function current()
{
/* @var $row array */
$row = null;

/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

/* @var $alias string */
$alias = $this->alias;

/* @var $iterator Iterator */
$iterator = $dataProvider;

if ($iterator instanceof IteratorAggregate) {
$iterator = $iterator->getIterator();
}

if ($dataProvider instanceof Iterator) {
$row = $dataProvider->current();

if ($dataProvider instanceof UsesBinaryDataInterface && $dataProvider->usesBinaryData()) {
$row = $dataProvider->convertDataRowToStringRow($row);
}

/* @var $newRow array */
$newRow = $row;

foreach ($row as $key => $value) {
$newRow["{$alias}.{$key}"] = $value;
}

$row = $newRow;
}

return $row;
}

public function next()
{
/* @var $dataProvider DataProviderInterface */
$dataProvider = $this->dataProvider;

if ($dataProvider instanceof IteratorAggregate) {
$dataProvider = $dataProvider->getIterator();
}

if ($dataProvider instanceof Iterator) {
$dataProvider->next();
}
}
}
46 changes: 40 additions & 6 deletions src/Addiks/PHPSQL/Job/Statement/ShowStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Addiks\PHPSQL\Value\Enum\Sql\Show\ShowType;
use Addiks\PHPSQL\Job\StatementJob;
use Addiks\PHPSQL\Executor\ShowExecutor;
use Addiks\PHPSQL\Job\Part\ValuePart;

/**
*
Expand All @@ -24,30 +25,63 @@ class ShowStatement extends StatementJob
const EXECUTOR_CLASS = ShowExecutor::class;

private $type;

public function setType(ShowType $type)
{
$this->type = $type;
}

public function getType()
{
return $this->type;
}

private $database;

public function setDatabase($database)
{
$this->database = (string)$database;
}

public function getDatabase()
{
return $this->database;
}

public function getResultSpecifier()
{
}

protected $isFull = false;

public function setIsFull($isFull)
{
$this->isFull = (bool)$isFull;
}

public function isFull()
{
return $this->isFull;
}

/**
* @var ValuePart
*/
protected $conditionValue;

public function setConditionValue(ValuePart $conditionValue)
{
if (is_null($conditionValue)) {
$this->conditionValue = null;

} else {
$this->conditionValue = $conditionValue;
}
}

public function getConditionValue()
{
return $this->conditionValue;
}

}
6 changes: 3 additions & 3 deletions src/Addiks/PHPSQL/SqlParser/CreateSqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ protected function parseCreateTable(SQLTokenIterator $tokens)
case $tokens->seekTokenNum(SqlToken::T_FULLTEXT(), TokenIterator::NEXT, [SqlToken::T_CONSTRAINT(), T_STRING]):
case $tokens->seekTokenNum(SqlToken::T_SPATIAL(), TokenIterator::NEXT, [SqlToken::T_CONSTRAINT(), T_STRING]):

/* @var $indexJob Index */
$indexJob = new Index();
/* @var $indexJob IndexPart */
$indexJob = new IndexPart();

switch($tokens->getCurrentTokenNumber()){
case SqlToken::T_UNIQUE():
Expand Down Expand Up @@ -881,6 +881,6 @@ protected function parseCreateIndex(SQLTokenIterator $tokens)

protected function parseCreateView(SQLTokenIterator $tokens)
{

}
}
Loading

0 comments on commit 8cf2880

Please sign in to comment.