Skip to content

Commit

Permalink
added single execution functional #7
Browse files Browse the repository at this point in the history
added more test cases #5
  • Loading branch information
KonstantinKuklin committed Sep 15, 2014
1 parent 9e249ae commit b21e987
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 48 deletions.
6 changes: 6 additions & 0 deletions docs/eng/Decrement.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ if($decrementQuery->getResult()->isSuccessfully()){
}
```

Another way to execute the query:
```php
$decrementQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$decrementResult = $decrementQuery->getResult();
```

Decrement with the opening index
------------
This command will check whether there is a required index if it is not, first open and then perform Decrement.
Expand Down
6 changes: 6 additions & 0 deletions docs/eng/Delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ $deleteQuery = $writer->delete(
$writer->getResultList();
```

Another way to execute the query:
```php
$deleteQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$deleteResult = $deleteQuery->getResult();
```

Delete using QueryBuilder
------------
When initializing specify which columns and how much will be raised. If you specify a value with out number,
Expand Down
6 changes: 6 additions & 0 deletions docs/eng/Increment.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ if($incrementQuery->getResult()->isSuccessfully()){
}
```

Another way to execute the query:
```php
$incrementQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$incrementResult = $incrementQuery->getResult();
```

Increment with the opening index
------------
This command will check whether there is a required index if it is not, first open and then perform Increment.
Expand Down
6 changes: 6 additions & 0 deletions docs/eng/Insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ $insertQuery = $writer->insert(
);
```

Another way to execute the query:
```php
$insertQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$insertResult = $insertQuery->getResult();
```

Insert with QueryBuilder
------------
When adding entries to all arrays of records must contain the same keys.
Expand Down
12 changes: 10 additions & 2 deletions docs/eng/OpenIndex.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ $indexId = $reader->getIndexId(
'PRIMARY',
array('key', 'text')
);
$reader->getResultList();
```

If we just need to open the subscript c number 12 (for example), and we don't want to check:

```php
$indexIndexQuery = $reader->openIndex(
$openIndexQuery = $reader->openIndex(
'12'
'database',
'tableName',
'PRIMARY',
array('key', 'text'),
array('num')
);
$reader->getResultList();
```

Here we open the index with identifier 12, columns `key`,` text`, and the column to filter `num`.
Method returns us to the class OpenIndexQuery.
Method returns us to the class OpenIndexQuery.

Another way to execute the query:
```php
$insertQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$insertResult = $insertQuery->getResult();
```
6 changes: 6 additions & 0 deletions docs/eng/Select.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ To send all queries and get the results you need to do:
$resultList = $reader->getResultList();
```

Another way to execute the query:
```php
$selectQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$selectResult = $selectQuery->getResult();
```

The variable `$resultList` contains a list of all results.
Just the desired result can be obtained

Expand Down
6 changes: 6 additions & 0 deletions docs/eng/Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ $updateQuery = $writer->update(
);
```

Another way to execute the query:
```php
$updateQuery->execute(); // query was sent and the results on this query and all from the queue were parsed
$updateResult = $updateQuery->getResult();
```

Update with QueryBuilder
------------
When initializing specify which columns to which data will be replaced.
Expand Down
7 changes: 7 additions & 0 deletions docs/rus/Decrement.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ if($decrementQuery->getResult()->isSuccessfully()){
}
```

Другой способ выполнить запрос:
```php
$decrementQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$decrementResult = $decrementQuery->getResult();
```


Decrement с открытием индекса
------------
Данная команда проверит есть ли нужный индекс, если его нет, то сначала откроет, а затем выполнит Decrement.
Expand Down
6 changes: 6 additions & 0 deletions docs/rus/Delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ if($deleteQuery->getResult()->isSuccessfully()){
}
```

Другой способ выполнить запрос:
```php
$deleteQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$deleteResult = $deleteQuery->getResult();
```

Delete с открытием индекса
------------
Данная команда проверит есть ли нужный индекс, если его нет, то сначала откроет, а затем выполнит Delete.
Expand Down
6 changes: 6 additions & 0 deletions docs/rus/Increment.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ if($incrementQuery->getResult()->isSuccessfully()){
}
```

Другой способ выполнить запрос:
```php
$incrementQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$incrementResult = $incrementQuery->getResult();
```

Increment с открытием индекса
------------
Данная команда проверит есть ли нужный индекс, если его нет, то сначала откроет, а затем выполнит Increment.
Expand Down
6 changes: 6 additions & 0 deletions docs/rus/Insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ if($insertQuery->getResult()->isSuccessfully()){
}
```

Другой способ выполнить запрос:
```php
$insertQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$insertResult = $insertQuery->getResult();
```

Insert с открытием индекса
------------
Вставка данных происходит в `'key', 'date', 'float', 'varchar', 'text', 'set', 'union'`.
Expand Down
14 changes: 12 additions & 2 deletions docs/rus/OpenIndex.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@ $indexId = $reader->getIndexId(
'PRIMARY',
array('key', 'text')
);

$reader->getResultList();
```

Если нам нужно просто открыть индекс c номер 12(например), и мы ничего не хотим проверять:

```php
$indexIndexQuery = $reader->openIndex(
$openIndexQuery = $reader->openIndex(
'12'
'database',
'tableName',
'PRIMARY',
array('key', 'text'),
array('num')
);

$reader->getResultList();
```

Здесь мы открываем индекс c номером 12, колонками `key`, `text`, а так же колонкой для фильтров `num`.
Метод вернет нам класс OpenIndexQuery.
Метод вернет нам класс OpenIndexQuery.

Другой способ выполнить запрос:
```php
$openIndexQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$openIndexResult = $openIndexQuery->getResult();
```
5 changes: 5 additions & 0 deletions docs/rus/Select.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ $selectQuery = $reader->selectByIndex($indexId, Comparison::EQUAL, array(42));
```php
$resultList = $reader->getResultList();
```
Другой способ выполнить запрос:
```php
$selectQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$selectResult = $selectQuery->getResult();
```
Переменная $resultList содержит список всех результатов.
Так же нужный нам результат можно получить
```php
Expand Down
6 changes: 6 additions & 0 deletions docs/rus/Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ if($updateQuery->getResult()->getNumberModifiedRows() == 0){
}
```

Другой способ выполнить запрос:
```php
$updateQuery->execute(); // отправлен запрос + получен ответ на этот запрос + все, что было в очереди на отправку
$updateResult = $updateQuery->getResult();
```

Update с открытием индекса
------------
Данная команда проверит есть ли нужный индекс, если его нет, то сначала откроет, а затем выполнит Update.
Expand Down
80 changes: 55 additions & 25 deletions src/HS/Query/QueryAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use HS\Component\ParameterBag;
use HS\Driver;
use HS\Exception\WrongParameterException;
use HS\ReaderInterface;
use HS\Result\SelectResult;
use HS\Validator;

Expand All @@ -25,6 +27,11 @@ abstract class QueryAbstract implements QueryInterface
'HS\Query\DecrementQuery' => 'HS\Result\DecrementResult',
);

/**
* {@inheritdoc}
*/
abstract public function getQueryParameters();

/**
* @param array $parameterList
*/
Expand Down Expand Up @@ -56,14 +63,6 @@ public function __construct(array $parameterList)

}

private function initIndexName()
{
$indexName = $this->getParameter('indexName');
if (!$this->getParameterBag()->isExists('indexName') || empty($indexName)) {
$this->getParameterBag()->setParameter('indexName', 'PRIMARY');
}
}

/**
* @param string $parameterName
* @param mixed $defaultValue
Expand Down Expand Up @@ -91,11 +90,6 @@ public function getQueryString()
return Driver::prepareSendDataStatic($this->getQueryParameters());
}

/**
* {@inheritdoc}
*/
abstract public function getQueryParameters();

/**
* @return int
*/
Expand All @@ -119,6 +113,48 @@ public function setResultData($data)
$this->setResultObject($this->queryResultMap[$queryClassName], $data);
}

/**
* @return $this
* @throws WrongParameterException
*/
public function execute()
{
$this->getSocket()->addQuery($this);
$this->getSocket()->getResultList();

return $this;
}

/**
* @return string
*/
protected function getQueryClassName()
{
return $this->getParameter('queryClassName');
}

/**
* @return ParameterBag
*/
protected function getParameterBag()
{
return $this->parameterBag;
}

/**
* @throws WrongParameterException
* @return ReaderInterface
*/
protected function getSocket()
{
$socket = $this->getParameter('socket');
if (!($socket instanceof ReaderInterface)) {
throw new WrongParameterException('Socket not found');
}

return $socket;
}

/**
* @param string $className
* @param mixed $data
Expand Down Expand Up @@ -150,19 +186,13 @@ private function setSelectResultObject($data)
}

/**
* @return string
*/
protected function getQueryClassName()
{
return $this->getParameter('queryClassName');
}

/**
* @return ParameterBag
* @return void
*/
protected function getParameterBag()
private function initIndexName()
{
return $this->parameterBag;
$indexName = $this->getParameter('indexName');
if (!$this->getParameterBag()->isExists('indexName') || empty($indexName)) {
$this->getParameterBag()->setParameter('indexName', 'PRIMARY');
}
}

}
Loading

0 comments on commit b21e987

Please sign in to comment.