diff --git a/src/HS/Builder/DeleteQueryBuilder.php b/src/HS/Builder/DeleteQueryBuilder.php index b77d6a5..63f71e1 100644 --- a/src/HS/Builder/DeleteQueryBuilder.php +++ b/src/HS/Builder/DeleteQueryBuilder.php @@ -32,7 +32,7 @@ public function getQueryClassPath() public function where($comparison, array $list) { $columnList = array_keys($list); - $this->getParameterBag()->setParameter('columnList', $columnList); + $this->columnList = $columnList; parent::where($comparison, $list); return $this; diff --git a/src/HS/Builder/FindQueryBuilderAbstract.php b/src/HS/Builder/FindQueryBuilderAbstract.php index 0ae0e61..0313c0a 100644 --- a/src/HS/Builder/FindQueryBuilderAbstract.php +++ b/src/HS/Builder/FindQueryBuilderAbstract.php @@ -5,6 +5,7 @@ use HS\Component\Filter; use HS\Component\InList; use HS\Exception\InvalidArgumentException; +use HS\Query\SelectQuery; /** * @author KonstantinKuklin @@ -16,7 +17,7 @@ abstract class FindQueryBuilderAbstract extends QueryBuilderAbstract */ public function __construct(array $columnList) { - parent::__construct(array('columnList' => $columnList)); + $this->columnList = $columnList; } /** @@ -26,7 +27,7 @@ public function __construct(array $columnList) */ public function fromDataBase($databaseName) { - $this->getParameterBag()->setParameter('dbName', $databaseName); + $this->dbName = $databaseName; return $this; } @@ -38,7 +39,7 @@ public function fromDataBase($databaseName) */ public function fromTable($tableName) { - $this->getParameterBag()->setParameter('tableName', $tableName); + $this->tableName = $tableName; return $this; } @@ -50,7 +51,7 @@ public function fromTable($tableName) */ public function fromIndex($indexName) { - $this->getParameterBag()->setParameter('indexName', $indexName); + $this->indexName = $indexName; return $this; } @@ -60,7 +61,7 @@ public function fromIndex($indexName) */ public function getColumnList() { - return $this->getParameter('columnList', array()); + return $this->columnList; } /** @@ -72,9 +73,9 @@ public function getColumnList() */ public function where($comparison, array $list) { - $this->getParameterBag()->setParameter('comparison', $comparison); - $keyList = $this->getParameter('keyList', array()); + $this->comparison = $comparison; $columnList = $this->getColumnList(); + // check is ordered list of keys for ($i = 0, $countWhere = count($list); $i < $countWhere; $i++) { $key = $columnList[$i]; @@ -83,9 +84,8 @@ public function where($comparison, array $list) "The key`s must be set with out skip on select( key1, key2). Where(key2,key1)" ); } - $keyList[] = $list[$key]; + $this->keyList[] = $list[$key]; } - $this->getParameterBag()->setParameter('keyList', $keyList); return $this; } @@ -100,14 +100,14 @@ public function where($comparison, array $list) public function whereIn($key, array $values) { $columnList = $this->getColumnList(); - $this->getParameterBag()->setParameter('comparison', Comparison::EQUAL); - $this->getParameterBag()->setParameter('keyList', array(1)); + $this->comparison = Comparison::EQUAL; + $this->keyList = array(1); if (false === $index = array_search($key, $columnList)) { throw new InvalidArgumentException("Can't find key in columns list."); } $inList = new InList($index, $values); - $this->getParameterBag()->setParameter('inKeyList', $inList); + $this->inKeyList = $inList; return $this; } @@ -122,16 +122,13 @@ public function whereIn($key, array $values) */ public function andWhere($columnName, $comparison, $key, $type = Filter::FILTER_TYPE_SKIP) { - $filterColumnList = $this->getParameter('filterColumnList', array()); - $position = array_search($columnName, $filterColumnList); + $position = array_search($columnName, $this->filterColumnList); if ($position === false) { - $filterColumnList[] = $columnName; - $position = count($filterColumnList) - 1; - $this->getParameterBag()->setParameter('filterColumnList', $filterColumnList); + $this->filterColumnList[] = $columnName; + $position = count($this->filterColumnList) - 1; } $filter = new Filter($comparison, $position, $key, $type); - - $this->getParameterBag()->addRowToParameter('filterList', $filter); + $this->filterList[] = $filter; return $this; } @@ -141,7 +138,7 @@ public function andWhere($columnName, $comparison, $key, $type = Filter::FILTER_ */ public function getFilterList() { - return $this->getParameter('filterList', array()); + return $this->filterList; } /** @@ -149,7 +146,7 @@ public function getFilterList() */ public function getFilterColumnList() { - return $this->getParameter('filterColumnList', array()); + return $this->filterColumnList; } /** @@ -159,7 +156,7 @@ public function getFilterColumnList() */ public function limit($limit) { - $this->getParameterBag()->setParameter('limit', $limit); + $this->limit = $limit; return $this; } @@ -171,7 +168,7 @@ public function limit($limit) */ public function offset($offset) { - $this->getParameterBag()->setParameter('offset', $offset); + $this->offset = $offset; return $this; } @@ -181,7 +178,7 @@ public function offset($offset) */ public function withSuffix() { - $this->getParameterBag()->setParameter('suffix', true); + $this->suffix = true; return $this; } diff --git a/src/HS/Builder/InsertQueryBuilder.php b/src/HS/Builder/InsertQueryBuilder.php index 31a6c1b..edabf0a 100644 --- a/src/HS/Builder/InsertQueryBuilder.php +++ b/src/HS/Builder/InsertQueryBuilder.php @@ -10,7 +10,6 @@ class InsertQueryBuilder extends QueryBuilderAbstract public function __construct() { - parent::__construct(array()); } /** @@ -20,10 +19,10 @@ public function __construct() */ public function addRow(array $row) { - if ($this->getParameter('columnList') === null) { - $this->getParameterBag()->setParameter('columnList', array_keys($row)); + if (empty($this->columnList)) { + $this->columnList = array_keys($row); } - $this->getParameterBag()->addRowToParameter('valueList', array_values($row)); + $this->valueList[] = array_values($row); return $this; } @@ -49,7 +48,7 @@ public function addRowList(array $rowList) */ public function toDatabase($dbName) { - $this->getParameterBag()->setParameter('dbName', $dbName); + $this->dbName = $dbName; return $this; } @@ -61,7 +60,7 @@ public function toDatabase($dbName) */ public function toTable($tableName) { - $this->getParameterBag()->setParameter('tableName', $tableName); + $this->tableName = $tableName; return $this; } @@ -73,7 +72,7 @@ public function toTable($tableName) */ public function toIndex($indexName) { - $this->getParameterBag()->setParameter('indexName', $indexName); + $this->indexName = $indexName; return $this; } @@ -83,7 +82,7 @@ public function toIndex($indexName) */ public function getQueryClassPath() { - return "HS\\Query\\InsertQuery"; + return 'HS\Query\InsertQuery'; } /** @@ -93,7 +92,7 @@ public function getQueryClassPath() */ public function limit($limit) { - $this->getParameterBag()->setParameter('limit', $limit); + $this->limit = $limit; return $this; } @@ -105,7 +104,7 @@ public function limit($limit) */ public function offset($offset) { - $this->getParameterBag()->setParameter('offset', $offset); + $this->offset = $offset; return $this; } diff --git a/src/HS/Builder/QueryBuilderAbstract.php b/src/HS/Builder/QueryBuilderAbstract.php index d439690..4df79f1 100644 --- a/src/HS/Builder/QueryBuilderAbstract.php +++ b/src/HS/Builder/QueryBuilderAbstract.php @@ -2,14 +2,38 @@ namespace HS\Builder; use HS\Component\ParameterBag; +use HS\Query\DeleteQuery; +use HS\Query\IncrementQuery; +use HS\Query\InsertQuery; use HS\Query\QueryInterface; +use HS\Query\SelectQuery; +use HS\Query\UpdateQuery; /** * @author KonstantinKuklin */ abstract class QueryBuilderAbstract implements QueryBuilderInterface { - private $parameterBag = null; + protected $dbName = ''; + protected $tableName = ''; + protected $indexName = 'PRIMARY'; + + protected $indexId = null; + protected $offset = 0; + protected $limit = 1; + + protected $columnList = array(); + protected $valueList = array(); + protected $filterList = array(); + + protected $comparison = null; + protected $keyList = array(); + protected $inKeyList = null; + protected $filterColumnList = array(); + + protected $suffix = false; + protected $returnType = SelectQuery::ASSOC; + protected $openIndexQuery = null; /** * @return string @@ -17,45 +41,84 @@ abstract class QueryBuilderAbstract implements QueryBuilderInterface abstract public function getQueryClassPath(); /** - * @param array $parameterList - */ - public function __construct(array $parameterList) - { - $this->parameterBag = new ParameterBag($parameterList); - } - - /** - * @param $indexId - * @param null $openIndexQuery - * - * @return QueryInterface + * {@inheritdoc} */ - public function getQuery($indexId, $openIndexQuery = null) + public function getQuery($indexId, $socket, $openIndexQuery = null) { - $this->getParameterBag()->setParameter('indexId', $indexId); - $this->getParameterBag()->setParameter('openIndexQuery', $openIndexQuery); + $this->indexId = $indexId; + $this->openIndexQuery = $openIndexQuery; $classPath = $this->getQueryClassPath(); - return new $classPath($this->getParameterBag()->getAsArray()); - } + $query = null; + switch ($classPath) { + case 'HS\Query\InsertQuery': + $query = new InsertQuery($indexId, $this->valueList, $socket, $openIndexQuery); + break; + case 'HS\Query\DeleteQuery': + $query = new DeleteQuery( + $indexId, + $this->comparison, + $this->keyList, + $socket, + $this->columnList, + $this->offset, + $this->limit, + $openIndexQuery, + $this->inKeyList, + $this->filterList, + $this->suffix + ); + break; + case 'HS\Query\SelectQuery': + $query = new SelectQuery( + $indexId, + $this->comparison, + $this->keyList, + $socket, + $this->columnList, + $this->offset, + $this->limit, + $openIndexQuery, + $this->inKeyList, + $this->filterList, null - /** - * @param string $parameterName - * @param mixed $defaultValue - * - * @return mixed - */ - public function getParameter($parameterName, $defaultValue = null) - { - return $this->getParameterBag()->getParameter($parameterName, $defaultValue); - } + ); + break; + case 'HS\Query\UpdateQuery': + $query = new UpdateQuery( + $indexId, + $this->comparison, + $this->keyList, + $socket, + $this->columnList, + $this->offset, + $this->limit, + $openIndexQuery, + $this->inKeyList, + $this->filterList, + $this->suffix, + $this->valueList + ); + break; + default: + $query = new $classPath( + $indexId, + $this->comparison, + $this->keyList, + $socket, + $this->columnList, + $this->offset, + $this->limit, + $openIndexQuery, + $this->inKeyList, + $this->filterList, + $this->suffix, + $this->valueList + ); + break; + } - /** - * @return ParameterBag - */ - public function getParameterBag() - { - return $this->parameterBag; + return $query; } /** @@ -63,7 +126,7 @@ public function getParameterBag() */ public function getDatabase() { - return $this->getParameter('dbName'); + return $this->dbName; } /** @@ -71,7 +134,7 @@ public function getDatabase() */ public function getTable() { - return $this->getParameter('tableName'); + return $this->tableName; } /** @@ -79,7 +142,7 @@ public function getTable() */ public function getIndex() { - return $this->getParameter('indexName', 'PRIMARY'); + return $this->indexName; } /** @@ -87,7 +150,7 @@ public function getIndex() */ public function getColumnList() { - return $this->getParameter('columnList', array()); + return $this->columnList; } /** @@ -95,7 +158,7 @@ public function getColumnList() */ public function getFilterList() { - return $this->getParameter('filterList', array()); + return $this->filterList; } /** diff --git a/src/HS/Builder/QueryBuilderInterface.php b/src/HS/Builder/QueryBuilderInterface.php index c70232b..ffc7dfa 100644 --- a/src/HS/Builder/QueryBuilderInterface.php +++ b/src/HS/Builder/QueryBuilderInterface.php @@ -4,6 +4,7 @@ */ namespace HS\Builder; +use HS\Query\OpenIndexQuery; use HS\Query\QueryInterface; /** @@ -12,12 +13,14 @@ interface QueryBuilderInterface { /** - * @param int $indexId - * @param null $openIndexQuery + * @param int $indexId + * @param \HS\CommonClient $socket + * @param null|OpenIndexQuery $openIndexQuery + * * * @return QueryInterface */ - public function getQuery($indexId, $openIndexQuery = null); + public function getQuery($indexId, $socket, $openIndexQuery = null); /** * @param int $limit diff --git a/src/HS/Builder/SelectQueryBuilder.php b/src/HS/Builder/SelectQueryBuilder.php index b63d300..790b2f3 100644 --- a/src/HS/Builder/SelectQueryBuilder.php +++ b/src/HS/Builder/SelectQueryBuilder.php @@ -8,12 +8,13 @@ */ class SelectQueryBuilder extends FindQueryBuilderAbstract { + /** * @return $this */ public function returnAsVector() { - $this->getParameterBag()->setParameter('returnType', SelectQuery::VECTOR); + $this->returnType = SelectQuery::VECTOR; return $this; } @@ -23,7 +24,7 @@ public function returnAsVector() */ public function returnAsAssoc() { - $this->getParameterBag()->setParameter('returnType', SelectQuery::ASSOC); + $this->returnType = SelectQuery::ASSOC; return $this; } diff --git a/src/HS/Builder/UpdateQueryBuilder.php b/src/HS/Builder/UpdateQueryBuilder.php index b47cf67..97ba47e 100644 --- a/src/HS/Builder/UpdateQueryBuilder.php +++ b/src/HS/Builder/UpdateQueryBuilder.php @@ -15,8 +15,7 @@ public function __construct(array $updateList) $columnList = array_keys($updateList); $valueList = array_values($updateList); parent::__construct($columnList); - $this->getParameterBag()->setParameter('valueList', $valueList); - + $this->valueList = $valueList; } /** diff --git a/src/HS/CommonClient.php b/src/HS/CommonClient.php index 0770934..64b39df 100644 --- a/src/HS/CommonClient.php +++ b/src/HS/CommonClient.php @@ -182,10 +182,10 @@ public function addQueryBuilder(QueryBuilderInterface $queryBuilder) // if returned int if (is_int($openIndexQuery)) { /** @var int $openIndexQuery */ - $queryForAdd = $queryBuilder->getQuery($openIndexQuery); + $queryForAdd = $queryBuilder->getQuery($openIndexQuery, $this); } else { /** @var OpenIndexQuery $openIndexQuery */ - $queryForAdd = $queryBuilder->getQuery($openIndexQuery->getIndexId(), $openIndexQuery); + $queryForAdd = $queryBuilder->getQuery($openIndexQuery->getIndexId(), $this, $openIndexQuery); } $this->addQuery($queryForAdd); diff --git a/src/HS/Component/Filter.php b/src/HS/Component/Filter.php index 2b5b254..6625946 100644 --- a/src/HS/Component/Filter.php +++ b/src/HS/Component/Filter.php @@ -5,7 +5,6 @@ namespace HS\Component; - use HS\Exception\InvalidArgumentException; class Filter diff --git a/src/HS/Component/ParameterBag.php b/src/HS/Component/ParameterBag.php deleted file mode 100644 index 7012560..0000000 --- a/src/HS/Component/ParameterBag.php +++ /dev/null @@ -1,78 +0,0 @@ - - */ - -namespace HS\Component; - -class ParameterBag -{ - private $parameterList = array(); - - /** - * @param array $parameterList - */ - public function __construct(array $parameterList) - { - $this->parameterList = $parameterList; - } - - /** - * @param string $parameterName - * @param mixed $defaultValue - * - * @return mixed - */ - public function getParameter($parameterName, $defaultValue = null) - { - $checkFlag = array_key_exists($parameterName, $this->parameterList); - if (!$checkFlag) { - return $defaultValue; - } - - return $this->parameterList[$parameterName]; - } - - /** - * @param string $parameterName - * - * @return boolean - */ - public function isExists($parameterName) - { - return array_key_exists($parameterName, $this->parameterList); - } - - /** - * @param string $parameterName - * @param mixed $value - * - * @return void - */ - public function setParameter($parameterName, $value) - { - $this->parameterList[$parameterName] = $value; - } - - /** - * @param string $parameterName - * @param mixed $value - * - * @return void - */ - public function addRowToParameter($parameterName, $value) - { - if (empty($this->parameterList[$parameterName])) { - $this->parameterList[$parameterName] = array(); - } - $this->parameterList[$parameterName][] = $value; - } - - /** - * @return array - */ - public function getAsArray() - { - return $this->parameterList; - } -} \ No newline at end of file diff --git a/src/HS/Query/AuthQuery.php b/src/HS/Query/AuthQuery.php index 540d225..f5785cf 100644 --- a/src/HS/Query/AuthQuery.php +++ b/src/HS/Query/AuthQuery.php @@ -9,11 +9,22 @@ class AuthQuery extends QueryAbstract { + private $authKey = ''; + + /** + * @param string $authKey + */ + public function __construct($authKey) + { + parent::__construct(); + $this->authKey = $authKey; + } + /** * {@inheritdoc} */ public function getQueryString() { - return "A" . Driver::DELIMITER . "1" . Driver::DELIMITER . Driver::encodeData($this->getParameter('authKey')); + return 'A' . Driver::DELIMITER . '1' . Driver::DELIMITER . Driver::encodeData($this->authKey); } } \ No newline at end of file diff --git a/src/HS/Query/InsertQuery.php b/src/HS/Query/InsertQuery.php index f6a7019..8d69a93 100644 --- a/src/HS/Query/InsertQuery.php +++ b/src/HS/Query/InsertQuery.php @@ -12,17 +12,27 @@ class InsertQuery extends QueryAbstract /** * {@inheritdoc} */ - public function getQueryString() + public function __construct($indexId, $valueList, $socket, $openIndexQuery = null) { - $valueList = $this->getParameter('valueList', array()); + parent::__construct(); + $this->indexId = $indexId; + $this->valueList = $valueList; + $this->openIndexQuery = $openIndexQuery; + $this->socket = $socket; + } + /** + * {@inheritdoc} + */ + public function getQueryString() + { $queryString = sprintf( "%d" . Driver::DELIMITER . "+" . Driver::DELIMITER . "%d", $this->getIndexId(), - count($valueList[0]) + count($this->valueList[0]) ); - foreach ($valueList as $row) { + foreach ($this->valueList as $row) { $queryString .= "\t" . Driver::prepareSendDataStatic($row); } @@ -34,9 +44,6 @@ public function getQueryString() */ public function setResultData($data) { - $this->getParameterBag()->setParameter( - 'resultObject', - new InsertResult($this, $data, $this->getParameter('openIndexQuery')) - ); + $this->resultObject = new InsertResult($this, $data, $this->openIndexQuery); } } \ No newline at end of file diff --git a/src/HS/Query/ModifyQueryAbstract.php b/src/HS/Query/ModifyQueryAbstract.php index 5ed17f1..87aa714 100644 --- a/src/HS/Query/ModifyQueryAbstract.php +++ b/src/HS/Query/ModifyQueryAbstract.php @@ -9,8 +9,54 @@ abstract class ModifyQueryAbstract extends SelectQuery { + protected $suffix = false; + protected $valueList = array(); + abstract public function getModificator(); + public function __construct( + $indexId, $comparisonOperation, $keyList, $socket, array $columnList, $offset = null, + $limit = null, $openIndexQuery = null, $inKeyList = null, + array $filterList = array(), $suffix = false, $valueList = array() + ) { + parent::__construct( + $indexId, + $comparisonOperation, + $keyList, + $socket, + $columnList, + $offset, + $limit, + $openIndexQuery, + $inKeyList, + $filterList + ); + + $this->suffix = $suffix; + $this->valueList = $valueList; + } + + /** + * {@inheritdoc} + */ + public function setResultData($data) + { + $queryClassName = $this->getQueryClassName(); + if ($this->isSuffix()) { + $this->setSelectResultObject($data); + } else { + $this->setResultObject(self::$queryResultMap[$queryClassName], $data); + } + } + + /** + * {@inheritdoc} + */ + public function isSuffix() + { + return $this->suffix; + } + /** * {@inheritdoc} */ diff --git a/src/HS/Query/ModifyStepQueryAbstract.php b/src/HS/Query/ModifyStepQueryAbstract.php index c7e3039..365be03 100644 --- a/src/HS/Query/ModifyStepQueryAbstract.php +++ b/src/HS/Query/ModifyStepQueryAbstract.php @@ -15,8 +15,8 @@ abstract class ModifyStepQueryAbstract extends ModifyQueryAbstract public function getQueryString() { $queryString = parent::getQueryString(); - if (($valueList = $this->getParameter('valueList', array())) && !empty($valueList)) { - $queryString .= Driver::prepareSendDataStatic($valueList); + if (!empty($this->valueList)) { + $queryString .= Driver::prepareSendDataStatic($this->valueList); } return $queryString; diff --git a/src/HS/Query/OpenIndexQuery.php b/src/HS/Query/OpenIndexQuery.php index b3ad464..bffc410 100644 --- a/src/HS/Query/OpenIndexQuery.php +++ b/src/HS/Query/OpenIndexQuery.php @@ -9,13 +9,50 @@ */ class OpenIndexQuery extends QueryAbstract { + private $dbName = ''; + private $tableName = ''; + private $indexName = ''; + private $columnList = array(); + private $filterColumnList = array(); - public function __construct(array $parameterList) - { - parent::__construct($parameterList); + /** + * @param int $indexId + * @param string $dbName + * @param string $tableName + * @param string $indexName + * @param array $columnList + * @param $socket + * @param array $filterColumnList + */ + public function __construct( + $indexId, $dbName, $tableName, $indexName, array $columnList, $socket, array $filterColumnList = array() + ) { + parent::__construct(); + Validator::validateIndexId($indexId); + $this->indexId = $indexId; + + Validator::validateDbName($dbName); + $this->dbName = $dbName; + + Validator::validateTableName($tableName); + $this->tableName = $tableName; + + // add default index + if (empty($indexName)) { + $indexName = 'PRIMARY'; + } + + Validator::validateIndexName($indexName); + $this->indexName = $indexName; + + Validator::validateColumnList($columnList); + $this->columnList = $columnList; + + $this->socket = $socket; - if ($this->getParameterBag()->isExists('columnList')) { - Validator::validateColumnList($this->getParameter('columnList')); + if (!empty($filterColumnList)) { + Validator::validateColumnList($filterColumnList); + $this->filterColumnList = $filterColumnList; } } @@ -24,13 +61,14 @@ public function __construct(array $parameterList) */ public function getQueryString() { - return sprintf("P\t%d\t%s\t%s\t%s\t%s\t%s", - $this->getParameter('indexId'), - $this->getParameter('dbName'), - $this->getParameter('tableName'), - $this->getParameter('indexName'), - implode(',', $this->getParameter('columnList')), - implode(',', $this->getParameter('filterColumnList')) + return sprintf( + "P\t%d\t%s\t%s\t%s\t%s\t%s", + $this->indexId, + $this->dbName, + $this->tableName, + $this->indexName, + implode(',', $this->columnList), + implode(',', $this->filterColumnList) ); } } \ No newline at end of file diff --git a/src/HS/Query/QueryAbstract.php b/src/HS/Query/QueryAbstract.php index 68426de..f001673 100644 --- a/src/HS/Query/QueryAbstract.php +++ b/src/HS/Query/QueryAbstract.php @@ -5,15 +5,11 @@ namespace HS\Query; -use HS\Component\ParameterBag; use HS\Exception\InvalidArgumentException; use HS\ReaderInterface; -use HS\Result\SelectResult; -use HS\Validator; abstract class QueryAbstract implements QueryInterface { - private $parameterBag = null; static protected $queryResultMap = array( 'HS\Query\AuthQuery' => 'HS\Result\AuthResult', 'HS\Query\TextQuery' => 'HS\Result\TextResult', @@ -26,46 +22,16 @@ abstract class QueryAbstract implements QueryInterface 'HS\Query\DecrementQuery' => 'HS\Result\DecrementResult', ); - /** - * @param array $parameterList - */ - public function __construct(array $parameterList) - { - $parameterList['queryClassName'] = get_called_class(); - $this->parameterBag = new ParameterBag($parameterList); - - - // if indexId was set - check it - if ($this->parameterBag->isExists('indexId')) { - Validator::validateIndexId($this->getIndexId()); - } - - if ($this->parameterBag->isExists('dbName')) { - Validator::validateDbName($this->getParameter('dbName')); - } - - if ($this->parameterBag->isExists('tableName')) { - Validator::validateTableName($this->getParameter('tableName')); - } - - // init default values if it needs - $this->initIndexName(); + protected $resultObject = null; + protected $socket = null; + protected $indexId = null; + protected $openIndexQuery = null; + protected $valueList = array(); + protected $queryClassName = null; - if ($this->parameterBag->isExists('indexName')) { - Validator::validateIndexName($this->getParameter('indexName')); - } - - } - - /** - * @param string $parameterName - * @param mixed $defaultValue - * - * @return mixed - */ - public function getParameter($parameterName, $defaultValue = null) + public function __construct() { - return $this->getParameterBag()->getParameter($parameterName, $defaultValue); + $this->queryClassName = get_called_class(); } /** @@ -73,7 +39,7 @@ public function getParameter($parameterName, $defaultValue = null) */ public function getResult() { - return $this->getParameter('resultObject', null); + return $this->resultObject; } /** @@ -86,7 +52,7 @@ abstract public function getQueryString(); */ public function getIndexId() { - return $this->getParameter('indexId'); + return $this->indexId; } /** @@ -94,22 +60,7 @@ public function getIndexId() */ public function setResultData($data) { - $queryClassName = $this->getQueryClassName(); - if ($queryClassName === 'HS\Query\SelectQuery' || $this->isSuffix()) { - $this->setSelectResultObject($data); - - return true; - } - - $this->setResultObject(self::$queryResultMap[$queryClassName], $data); - } - - /** - * {@inheritdoc} - */ - public function isSuffix() - { - return $this->getParameter('suffix', false); + $this->setResultObject(self::$queryResultMap[$this->getQueryClassName()], $data); } /** @@ -129,15 +80,7 @@ public function execute() */ protected function getQueryClassName() { - return $this->getParameter('queryClassName'); - } - - /** - * @return ParameterBag - */ - protected function getParameterBag() - { - return $this->parameterBag; + return $this->queryClassName; } /** @@ -146,52 +89,19 @@ protected function getParameterBag() */ protected function getSocket() { - $socket = $this->getParameter('socket'); - if (!($socket instanceof ReaderInterface)) { + if (!($this->socket instanceof ReaderInterface)) { throw new InvalidArgumentException('Socket not found'); } - return $socket; + return $this->socket; } /** * @param string $className * @param mixed $data */ - private function setResultObject($className, $data) + protected function setResultObject($className, $data) { - $this->getParameterBag()->setParameter( - 'resultObject', - new $className($this, $data, $this->getParameter('openIndexQuery')) - ); - } - - /** - * @param mixed $data - */ - private function setSelectResultObject($data) - { - - $this->getParameterBag()->setParameter( - 'resultObject', - new SelectResult( - $this, - $data, - $this->getParameter('columnList', array()), - $this->getParameter('returnType', SelectQuery::ASSOC), - $this->getParameter('openIndexQuery') - ) - ); - } - - /** - * @return void - */ - private function initIndexName() - { - $indexName = $this->getParameter('indexName'); - if (!$this->getParameterBag()->isExists('indexName') || empty($indexName)) { - $this->getParameterBag()->setParameter('indexName', 'PRIMARY'); - } + $this->resultObject = new $className($this, $data, $this->openIndexQuery); } } \ No newline at end of file diff --git a/src/HS/Query/QueryInterface.php b/src/HS/Query/QueryInterface.php index 23a5af4..3b15a97 100644 --- a/src/HS/Query/QueryInterface.php +++ b/src/HS/Query/QueryInterface.php @@ -29,11 +29,6 @@ public function setResultData($data); */ public function getIndexId(); - /** - * @return boolean - */ - public function isSuffix(); - /** * @return $this * @throws \HS\Exception\InvalidArgumentException diff --git a/src/HS/Query/SelectQuery.php b/src/HS/Query/SelectQuery.php index 5c33036..2eda876 100644 --- a/src/HS/Query/SelectQuery.php +++ b/src/HS/Query/SelectQuery.php @@ -4,12 +4,12 @@ */ namespace HS\Query; -use HS\Component\Comparison; use HS\Component\ComparisonInterface; -use HS\Component\Filter; use HS\Component\InList; use HS\Driver; use HS\Exception\InvalidArgumentException; +use HS\Result\SelectResult; +use HS\Validator; class SelectQuery extends QueryAbstract { @@ -18,9 +18,60 @@ class SelectQuery extends QueryAbstract // const OBJECT = 3; TODO + protected $comparisonOparation = null; + protected $keyList = array(); + protected $offset = 0; + protected $limit = 1; + protected $columnList = array(); + protected $suffix = false; + /** @var null|InList */ + protected $inKeyList = null; + /** @var \HS\Component\Filter[] */ + protected $filterList = array(); + + protected $returnType = self::ASSOC; + + /** + * @param int $indexId + * @param string $comparisonOperation + * @param array $keyList + * @param null $socket + * @param array $columnList + * @param null|int $offset + * @param null|int $limit + * @param null|OpenIndexQuery $openIndexQuery + * @param null $inKeyList + * @param array $filterList + * @param null|int $position + */ + public function __construct( + $indexId, $comparisonOperation, $keyList, $socket, array $columnList, $offset = null, + $limit = null, $openIndexQuery = null, $inKeyList = null, + array $filterList = array(), $position = null + ) { + parent::__construct(); + + Validator::validateIndexId($indexId); + $this->indexId = $indexId; + + $this->comparisonOparation = $comparisonOperation; + $this->keyList = $keyList; + $this->offset = $offset; + $this->limit = $limit; + $this->columnList = $columnList; + $this->openIndexQuery = $openIndexQuery; + $this->socket = $socket; + if ($inKeyList instanceof InList) { + $this->inKeyList = $inKeyList; + } elseif ($inKeyList !== null) { + $this->inKeyList = new InList(is_numeric($position) ? $position : 0, $inKeyList); + } + $this->filterList = $filterList; + } + public function getReturnType() { - return $this->getParameter('returnType', self::VECTOR); + return $this->returnType; } /** @@ -34,19 +85,38 @@ public function setReturnType($type) || $type === self::VECTOR // || $type === self::OBJECT TODO ) { - $this->getParameterBag()->setParameter('returnType', $type); - + $this->returnType = $type; } else { throw new InvalidArgumentException("Got unknown return type."); } } + public function setResultData($data) + { + $this->setSelectResultObject($data); + } + + /** + * @param mixed $data + */ + protected function setSelectResultObject($data) + { + + $this->resultObject = new SelectResult( + $this, + $data, + $this->columnList, + $this->returnType, + $this->openIndexQuery + ); + } + /** * @return ComparisonInterface */ public function getComparison() { - return $this->getParameter('comparison', Comparison::EQUAL); + return $this->comparisonOparation; } /** @@ -54,7 +124,7 @@ public function getComparison() */ public function getKeyList() { - return $this->getParameter('keyList', array()); + return $this->keyList; } /** @@ -62,7 +132,7 @@ public function getKeyList() */ public function getLimit() { - return $this->getParameter('limit', 1); + return $this->limit; } /** @@ -70,7 +140,7 @@ public function getLimit() */ public function getOffset() { - return $this->getParameter('offset', 0); + return $this->offset; } /** @@ -78,9 +148,7 @@ public function getOffset() */ public function getIn() { - /** @var InList $inKeyList */ - $inKeyList = $this->getParameter('inKeyList'); - if ($inKeyList === null) { + if ($this->inKeyList === null) { return ''; } @@ -89,9 +157,9 @@ public function getIn() Driver::DELIMITER . "%d" . // position Driver::DELIMITER . "%d" . // count Driver::DELIMITER . "%s", // key list - $inKeyList->getPosition(), - $inKeyList->getCount(), - Driver::prepareSendDataStatic($inKeyList->getKeyList()) + $this->inKeyList->getPosition(), + $this->inKeyList->getCount(), + Driver::prepareSendDataStatic($this->inKeyList->getKeyList()) ); } @@ -100,14 +168,12 @@ public function getIn() */ public function getFilterList() { - /** @var Filter[] $filterList */ - $filterList = $this->getParameter('filterList'); - if ($filterList === null) { + if (empty($this->filterList)) { return ''; } $output = ''; - foreach ($filterList as $filter) { + foreach ($this->filterList as $filter) { $output .= sprintf( Driver::DELIMITER . "%s" . // type Driver::DELIMITER . "%s" . // comparison diff --git a/src/HS/Query/TextQuery.php b/src/HS/Query/TextQuery.php index a8fc0ed..b735d5b 100644 --- a/src/HS/Query/TextQuery.php +++ b/src/HS/Query/TextQuery.php @@ -5,16 +5,24 @@ namespace HS\Query; +use HS\Result\SelectResult; + class TextQuery extends QueryAbstract { + private $text = ''; + /** - * @param array $parameterList + * @param string $text + * @param $socket * @param string $queryObject */ - public function __construct(array $parameterList, $queryObject) + public function __construct($text, $socket, $queryObject) { - parent::__construct($parameterList); - $this->getParameterBag()->setParameter('queryClassName', $queryObject); + parent::__construct(); + $this->text = $text; + $this->socket = $socket; + + $this->queryClassName = $queryObject; } /** @@ -22,6 +30,25 @@ public function __construct(array $parameterList, $queryObject) */ public function getQueryString() { - return $this->getParameter('text'); + return $this->text; + } + + /** + * {@inheritdoc} + */ + public function setResultData($data) + { + if ($this->getQueryClassName() === 'HS\Query\SelectQuery') { + $this->resultObject = new SelectResult( + $this, + $data, + array(), + SelectQuery::VECTOR, + $this->openIndexQuery + ); + } else { + $this->setResultObject(self::$queryResultMap[$this->getQueryClassName()], $data); + + } } } \ No newline at end of file diff --git a/src/HS/Query/UpdateQuery.php b/src/HS/Query/UpdateQuery.php index 5d87316..6fc46f2 100644 --- a/src/HS/Query/UpdateQuery.php +++ b/src/HS/Query/UpdateQuery.php @@ -21,7 +21,7 @@ public function getQueryString() { $queryString = parent::getQueryString(); - $valueList = $this->getParameter('valueList', array()); + $valueList = $this->valueList; if (!empty($valueList)) { $queryString .= Driver::prepareSendDataStatic($valueList); } diff --git a/src/HS/Reader.php b/src/HS/Reader.php index 2ebf456..5428728 100644 --- a/src/HS/Reader.php +++ b/src/HS/Reader.php @@ -4,7 +4,6 @@ use HS\Component\Comparison; use HS\Component\Filter; -use HS\Component\InList; use HS\Exception\InvalidArgumentException; use HS\Query\AuthQuery; use HS\Query\OpenIndexQuery; @@ -30,7 +29,7 @@ public function authenticate($authKey) ) ); } - $authQuery = new AuthQuery(array('authKey' => trim($authKey), 'socket' => $this)); + $authQuery = new AuthQuery($authKey); $this->addQuery($authQuery); return $authQuery; @@ -44,7 +43,7 @@ public function authenticate($authKey) */ public function text($queryText, $queryClass) { - $textQuery = new TextQuery(array('text' => $queryText, 'socket' => $this), $queryClass); + $textQuery = new TextQuery($queryText, $this, $queryClass); $this->addQuery($textQuery); return $textQuery; @@ -57,15 +56,13 @@ public function openIndex( $indexId, $dbName, $tableName, $indexName, array $columnList, array $filterColumnList = array() ) { $indexQuery = new OpenIndexQuery( - array( - 'indexId' => $indexId, - 'dbName' => $dbName, - 'tableName' => $tableName, - 'indexName' => $indexName, - 'columnList' => $columnList, - 'filterColumnList' => $filterColumnList, - 'socket' => $this, - ) + $indexId, + $dbName, + $tableName, + $indexName, + $columnList, + $this, + $filterColumnList ); $this->addQuery($indexQuery); $this->setKeysToIndexId($indexId, $columnList); @@ -110,16 +107,12 @@ public function selectByIndex( $indexId, $comparisonOperation, array $keys, $offset = null, $limit = null, array $filterList = array() ) { $selectQuery = new SelectQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'filterList' => $filterList, - 'socket' => $this, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, $limit, null, null, $filterList ); $this->addQuery($selectQuery); @@ -137,17 +130,14 @@ public function selectInByIndex($indexId, $in, $offset = null, $limit = null, ar } $selectQuery = new SelectQuery( - array( - 'indexId' => $indexId, - 'comparison' => Comparison::EQUAL, - 'keyList' => array(1), - 'offset' => $offset, - 'limit' => ($limit !== null) ? $limit : count($in), - 'columnList' => $this->getKeysByIndexId($indexId), - 'inKeyList' => new InList(0, $in), - 'filterList' => $filterList, - 'socket' => $this, - ) + $indexId, + Comparison::EQUAL, + array(1), + $this, + $this->getKeysByIndexId($indexId), + $offset, + ($limit !== null) ? $limit : count($in), + null, $in, $filterList ); $this->addQuery($selectQuery); @@ -181,17 +171,12 @@ public function select( } $selectQuery = new SelectQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'openIndexQuery' => $openIndexQuery, - 'filterList' => $filterList, - 'socket' => $this, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, $limit, $openIndexQuery, null, $filterList ); $this->addQuery($selectQuery); @@ -208,11 +193,13 @@ public function select( * @param int $offset * @param int $limit * + * @param array $filterList + * * @throws InvalidArgumentException * @return SelectQuery */ public function selectIn( - $columns, $dbName, $tableName, $indexName, $in, $offset = null, $limit = null + $columns, $dbName, $tableName, $indexName, $in, $offset = null, $limit = null, array $filterList = array() ) { $indexId = $this->getIndexId($dbName, $tableName, $indexName, $columns, false); $openIndexQuery = null; @@ -228,16 +215,14 @@ public function selectIn( } $selectQuery = new SelectQuery( - array( - 'indexId' => $indexId, - 'comparison' => Comparison::EQUAL, - 'keyList' => array(1), - 'offset' => $offset, - 'limit' => ($limit !== null) ? $limit : count($in), - 'columnList' => $this->getKeysByIndexId($indexId), - 'inKeyList' => new InList(0, $in), - 'socket' => $this, - ) + $indexId, + Comparison::EQUAL, + array(1), + $this, + $this->getKeysByIndexId($indexId), + $offset, + ($limit !== null) ? $limit : count($in), + $openIndexQuery, $in, $filterList ); $this->addQuery($selectQuery); diff --git a/src/HS/Result/ResultAbstract.php b/src/HS/Result/ResultAbstract.php index 957b2d1..34e3257 100644 --- a/src/HS/Result/ResultAbstract.php +++ b/src/HS/Result/ResultAbstract.php @@ -81,66 +81,7 @@ public function __construct(QueryInterface $query, $data, $openIndexQuery = null if ($code !== "0") { // 4 because we need to skip 0 \t 1 \t $error = substr($data, 4); - - switch ($error) { - case 'cmd': - case 'syntax': - case 'notimpl': - $this->error = new CommandError($error); - break; - case 'authtype': - case 'unauth': - $this->error = new AuthenticationError($error); - break; - case 'open_table': - $this->error = new OpenTableError($error); - break; - case 'tblnum': - case 'stmtnum': - $this->error = new IndexOverFlowError($error); - break; - case 'invalueslen': - $this->error = new InListSizeError($error); - break; - case 'filtertype': - $this->error = new FilterTypeError($error); - break; - case 'filterfld': - $this->error = new FilterColumnError($error); - break; - case 'lock_tables': - $this->error = new LockTableError($error); - break; - case 'modop': - $this->error = new LockTableError($error); - break; - case 'idxnum': - $this->error = new KeyIndexError($error); - break; - case 'kpnum': - case 'klen': - $this->error = new KeyLengthError($error); - break; - case 'op': - $this->error = new ComparisonOperatorError($error); - break; - case 'readonly': - $this->error = new ReadOnlyError($error); - break; - case 'fld': - $this->error = new ColumnParseError($error); - break; - case 'filterblob': // unknown error TODO - default: - // Errors with wrong data - if (is_numeric($error)) { - $this->error = new InternalMysqlError($error); - } else { - $this->error = new UnknownError($error); - } - break; - } - throw $this->error; + $this->throwErrorClass($error); } else { $this->data = $data; } @@ -222,4 +163,68 @@ public function getTime() { return $this->time; } + + private function throwErrorClass($error) + { + $errorClass = null; + switch ($error) { + case 'cmd': + case 'syntax': + case 'notimpl': + $errorClass = new CommandError($error); + break; + case 'authtype': + case 'unauth': + $errorClass = new AuthenticationError($error); + break; + case 'open_table': + $errorClass = new OpenTableError($error); + break; + case 'tblnum': + case 'stmtnum': + $errorClass = new IndexOverFlowError($error); + break; + case 'invalueslen': + $errorClass = new InListSizeError($error); + break; + case 'filtertype': + $errorClass = new FilterTypeError($error); + break; + case 'filterfld': + $errorClass = new FilterColumnError($error); + break; + case 'lock_tables': + $errorClass = new LockTableError($error); + break; + case 'modop': + $errorClass = new LockTableError($error); + break; + case 'idxnum': + $errorClass = new KeyIndexError($error); + break; + case 'kpnum': + case 'klen': + $errorClass = new KeyLengthError($error); + break; + case 'op': + $errorClass = new ComparisonOperatorError($error); + break; + case 'readonly': + $errorClass = new ReadOnlyError($error); + break; + case 'fld': + $errorClass = new ColumnParseError($error); + break; + case 'filterblob': // unknown error TODO + default: + // Errors with wrong data + if (is_numeric($error)) { + $errorClass = new InternalMysqlError($error); + } else { + $errorClass = new UnknownError($error); + } + break; + } + throw $errorClass; + } } \ No newline at end of file diff --git a/src/HS/Writer.php b/src/HS/Writer.php index 6836e2b..f6959ed 100644 --- a/src/HS/Writer.php +++ b/src/HS/Writer.php @@ -29,18 +29,17 @@ public function update( } $query = new UpdateQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'valueList' => $values, - 'openIndexQuery' => $openIndexQuery, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + $openIndexQuery, + null, + array(), + $suffix, $values ); $this->addQuery($query); @@ -54,22 +53,23 @@ public function update( public function updateByIndex( $indexId, $comparisonOperation, array $keys, array $values, $suffix = false, $limit = null, $offset = null ) { - $updateQuery = new UpdateQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'valueList' => $values, - 'socket' => $this, - 'suffix' => $suffix, - ) + $query = new UpdateQuery( + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + null, + null, + array(), + $suffix, $values ); - $this->addQuery($updateQuery); - return $updateQuery; + $this->addQuery($query); + + return $query; } /** @@ -88,17 +88,17 @@ public function delete( } $deleteQuery = new DeleteQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'openIndexQuery' => $openIndexQuery, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + $openIndexQuery, + null, + array(), + $suffix ); $this->addQuery($deleteQuery); @@ -111,16 +111,17 @@ public function delete( public function deleteByIndex($indexId, $comparisonOperation, array $keys, $suffix = false, $offset = 0, $limit = 1) { $deleteQuery = new DeleteQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + null, + null, + array(), + $suffix ); $this->addQuery($deleteQuery); @@ -143,18 +144,17 @@ public function increment( } $incrementQuery = new IncrementQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'openIndexQuery' => $openIndexQuery, - 'valueList' => $valueList, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + $openIndexQuery, + null, + array(), + $suffix, $valueList ); $this->addQuery($incrementQuery); @@ -168,17 +168,17 @@ public function incrementByIndex( $indexId, $comparisonOperation, array $keys, array $valueList, $suffix = false, $offset = 0, $limit = 1 ) { $incrementQuery = new IncrementQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'valueList' => $valueList, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + null, + null, + array(), + $suffix, $valueList ); $this->addQuery($incrementQuery); @@ -201,18 +201,17 @@ public function decrement( } $decrementQuery = new DecrementQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'openIndexQuery' => $openIndexQuery, - 'valueList' => $valueList, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + $openIndexQuery, + null, + array(), + $suffix, $valueList ); $this->addQuery($decrementQuery); @@ -226,17 +225,17 @@ public function decrementByIndex( $indexId, $comparisonOperation, array $keys, array $valueList, $suffix = false, $offset = 0, $limit = 1 ) { $decrementQuery = new DecrementQuery( - array( - 'indexId' => $indexId, - 'comparison' => $comparisonOperation, - 'keyList' => $keys, - 'offset' => $offset, - 'limit' => $limit, - 'columnList' => $this->getKeysByIndexId($indexId), - 'valueList' => $valueList, - 'socket' => $this, - 'suffix' => $suffix, - ) + $indexId, + $comparisonOperation, + $keys, + $this, + $this->getKeysByIndexId($indexId), + $offset, + $limit, + null, + null, + array(), + $suffix, $valueList ); $this->addQuery($decrementQuery); @@ -256,14 +255,7 @@ public function insert( $indexId = $openIndexQuery->getIndexId(); } - $insertQuery = new InsertQuery( - array( - 'indexId' => $indexId, - 'valueList' => $valueList, - 'openIndexQuery' => $openIndexQuery, - 'socket' => $this, - ) - ); + $insertQuery = new InsertQuery($indexId, $valueList, $openIndexQuery); $this->addQuery($insertQuery); return $insertQuery; @@ -274,16 +266,9 @@ public function insert( */ public function insertByIndex($indexId, array $valueList) { - $updateQuery = new InsertQuery( - array( - 'indexId' => $indexId, - 'valueList' => $valueList, - 'socket' => $this, - ) - ); - - $this->addQuery($updateQuery); + $insertQuery = new InsertQuery($indexId, $valueList, null); + $this->addQuery($insertQuery); - return $updateQuery; + return $insertQuery; } } diff --git a/tests/HS/Builder/IncrementQueryBuilderTest.php b/tests/HS/Builder/IncrementQueryBuilderTest.php index b1c66a4..f82eb4b 100644 --- a/tests/HS/Builder/IncrementQueryBuilderTest.php +++ b/tests/HS/Builder/IncrementQueryBuilderTest.php @@ -53,4 +53,35 @@ public function testIncrementException() $this->fail('Not fall incrementBuilder with wrong parameters.'); } + + // limit value increase num ?? TODO + public function testBugSingleIncrement() + { + $incrementQueryBuilder = QueryBuilder::increment(array('key' => 0, 'num')) + ->fromDataBase($this->getDatabase()) + ->fromTable($this->getTableName()) + ->where(Comparison::EQUAL, array('key' => 104)) + ->limit(100); + + $incrementQuery = $this->getWriter()->addQueryBuilder($incrementQueryBuilder); + var_dump($incrementQuery->getQueryString()); + $selectQuery = $this->getWriter()->selectByIndex($incrementQuery->getIndexId(), Comparison::EQUAL, array('104')); + + $this->getWriter()->getResultList(); + + $incrementResult = $incrementQuery->getResult(); + $this->assertTrue($incrementResult->isSuccessfully(), 'Fall incrementQuery is not successfully done.'); + + + $this->assertEquals( + array( + array( + 'key' => '104', + 'num' => '111' + ) + ), + $selectQuery->getResult()->getData(), + 'Fall returned data not valid.' + ); + } } \ No newline at end of file diff --git a/tests/HS/Builder/SelectQueryBuilderTest.php b/tests/HS/Builder/SelectQueryBuilderTest.php index 997e0fc..3e20b76 100644 --- a/tests/HS/Builder/SelectQueryBuilderTest.php +++ b/tests/HS/Builder/SelectQueryBuilderTest.php @@ -94,7 +94,7 @@ public function testSingleSelectWithFilter() ); } - public function testBugSingleSelectWithWhereIn() + public function testSingleSelectWithWhereIn() { $selectQueryBuilder = QueryBuilder::select( array('key', 'float') diff --git a/tests/HS/Component/ParameterBagTest.php b/tests/HS/Component/ParameterBagTest.php deleted file mode 100644 index 36263b9..0000000 --- a/tests/HS/Component/ParameterBagTest.php +++ /dev/null @@ -1,64 +0,0 @@ - - */ - -namespace HS\Tests\Component; - -use HS\Component\ParameterBag; -use PHPUnit_Framework_TestCase; - -class ParameterBagTest extends PHPUnit_Framework_TestCase -{ - - private $bag = null; - - public function __construct() - { - $this->bag = new ParameterBag(array("int" => 50, "text" => 'simple text')); - } - - public function testGetParameter() - { - $this->assertEquals(50, $this->bag->getParameter('int'), 'Wrong parameter'); - } - - public function testGetDefaultParameter() - { - $this->assertEquals(null, $this->bag->getParameter('none'), 'Wrong parameter'); - } - - public function testGetDefaultUserParameter() - { - $this->assertEquals('default', $this->bag->getParameter('none', 'default'), 'Wrong parameter'); - } - - public function testSetParameter() - { - $this->bag->setParameter('none2', 'default2'); - $this->assertEquals('default2', $this->bag->getParameter('none2'), 'Wrong parameter'); - } - - public function testIsExists() - { - $this->assertTrue($this->bag->isExists('int'), 'Wrong parameter'); - $this->assertFalse($this->bag->isExists('int_none'), 'Wrong parameter'); - } - - public function testIsExistsEmpty() - { - $this->bag->setParameter('empty', ''); - $this->assertTrue($this->bag->isExists('empty'), 'Wrong parameter'); - } - - public function testAddRowToParameter() - { - $this->bag->addRowToParameter("array", 'list'); - $this->assertEquals(array('list'), $this->bag->getParameter('array')); - } - - public function testGetAsArray() - { - $this->assertEquals(array('int' => 50, 'text' => 'simple text'), $this->bag->getAsArray()); - } -} \ No newline at end of file diff --git a/tests/HS/Writer/IncrementQueryTest.php b/tests/HS/Writer/IncrementQueryTest.php index 2674734..c0a1622 100644 --- a/tests/HS/Writer/IncrementQueryTest.php +++ b/tests/HS/Writer/IncrementQueryTest.php @@ -20,7 +20,7 @@ public function testSingleIncrementByIndexId() 'PRIMARY', array('key', 'num') ); - $incrementQuery = $writer->incrementByIndex($indexId, '=', array(106), array(0, 3)); + $incrementQuery = $writer->incrementByIndex($indexId, '=', array(106), array(0, 3), false); $selectQuery = $writer->selectByIndex($indexId, '=', array(106)); $writer->getResultList();