예제 #1
0
 public function executeFunction(FunctionJob $function, ExecutionContext $context)
 {
     /* @var $result SelectResult */
     $result = $this->resultSet;
     /* @var $argumentValue Value */
     $argumentValue = current($function->getArguments());
     $count = 0;
     $beforeSourceRow = $context->getCurrentSourceRow();
     foreach ($context->getCurrentSourceSet() as $row) {
         $context->setCurrentSourceRow($row);
         $value = $this->valueResolver->resolveValue($argumentValue);
         if (!is_null($value)) {
             $count++;
         }
     }
     $context->setCurrentSourceRow($beforeSourceRow);
     return $count;
 }
예제 #2
0
 private function doesCurrentRowPassesFilters()
 {
     $row = $this->current();
     $result = false;
     if (is_array($row)) {
         if ($this->usesBinaryData()) {
             $row = $this->convertDataRowToStringRow($row);
         }
         $this->executionContext->setCurrentSourceRow($row);
         $result = $this->valueResolver->resolveValue($this->condition, $this->executionContext);
     }
     return (bool) $result;
 }
예제 #3
0
 public function executeFunction(FunctionJob $function, ExecutionContext $context)
 {
     /* @var $argumentValue Value */
     $argumentValue = current($function->getArguments());
     $beforeSourceRow = $context->getCurrentSourceRow();
     $sum = 0;
     foreach ($context->getCurrentSourceSet() as $row) {
         $context->setCurrentSourceRow($row);
         $value = $this->valueResolver->resolveValue($argumentValue, $context);
         if (is_numeric($value)) {
             $sum += $value;
         }
     }
     $context->setCurrentSourceRow($beforeSourceRow);
     return $sum;
 }
예제 #4
0
 public function executeJob(StatementJob $statement, array $parameters = array())
 {
     /* @var $statement UpdateStatement */
     $result = new TemporaryResult();
     // TODO: multiple tables or not?
     $executionContext = new ExecutionContext($this->schemaManager, $statement, $parameters, $this->valueResolver);
     /* @var $tableSpecifier TableSpecifier */
     $tableSpecifier = $statement->getTables()[0];
     /* @var $tableResource Table */
     $tableResource = $this->tableManager->getTable($tableSpecifier->getTable(), $tableSpecifier->getDatabase());
     /* @var $tableSchema TableSchema */
     $tableSchema = $tableResource->getTableSchema();
     $indicies = array();
     foreach ($tableSchema->getIndexIterator() as $indexId => $indexPage) {
         /* @var $indexPage Index */
         /* @var $index Index */
         $index = $tableResource->getIndex($indexPage->getName());
         $indicies[] = $index;
     }
     /* @var $condition Value */
     $condition = $statement->getCondition();
     foreach ($tableResource as $rowId => $row) {
         if ($tableResource instanceof UsesBinaryDataInterface && $tableResource->usesBinaryData()) {
             $row = $tableResource->convertDataRowToStringRow($row);
         }
         $executionContext->setCurrentSourceRow($row);
         $conditionResult = $this->valueResolver->resolveValue($condition, $executionContext);
         if ($conditionResult) {
             $newRow = $row;
             foreach ($statement->getDataChanges() as $dataChange) {
                 /* @var $dataChange DataChange */
                 $columnName = (string) $dataChange->getColumn();
                 $newValue = $dataChange->getValue();
                 $newValue = $this->valueResolver->resolveValue($newValue, $executionContext);
                 $newRow[$columnName] = $newValue;
             }
             $row = $tableResource->convertStringRowToDataRow($row);
             $newRow = $tableResource->convertStringRowToDataRow($newRow);
             foreach ($indicies as $index) {
                 /* @var $index Index */
                 $index->updateRow($row, $newRow, $rowId);
             }
             $tableResource->setRowData($rowId, $newRow);
         }
     }
     return $result;
 }
예제 #5
0
 public function executeJob(StatementJob $statement, array $parameters = array())
 {
     /* @var $statement DeleteStatement */
     $result = new TemporaryResult();
     $executionContext = new ExecutionContext($this->schemaManager, $statement, $parameters);
     /* @var $conditionValue Value */
     $conditionValue = $statement->getCondition();
     $rowCount = 0;
     $rowSkip = 0;
     $limitOffset = $statement->getLimitOffset();
     $limitCount = $statement->getLimitRowCount();
     foreach ($statement->getDeleteTables() as $tableSpecifier) {
         /* @var $tableSpecifier TableSpecifier */
         /* @var $tableResource Table */
         $tableResource = $this->tableManager->getTable($tableSpecifier->getTable(), $tableSpecifier->getDatabase());
         $sortedIterator = new SortedResourceIterator($tableResource, $this->valueResolver);
         /* @var $tableSchema TableSchema */
         $tableSchema = $tableResource->getTableSchema();
         if (!is_null($statement->getOrderColumn())) {
             $orderColumns = $statement->getOrderColumn();
             $sortedIterator->setTemporaryBuildChildIteratorByValue($orderColumns, $tableResource);
         } else {
             $primaryKeyColumns = $tableSchema->getPrimaryKeyColumns();
             $primaryIndexId = $tableSchema->getIndexIdByColumns(array_keys($primaryKeyColumns));
             if (!is_null($primaryIndexId)) {
                 /* @var $index Index */
                 $index = $tableResource->getIndex($primaryIndexId);
                 // TODO: try to extract begin/end values from conditions
                 $beginValue = null;
                 $endValue = null;
                 $iterator = $index->getIterator($beginValue, $endValue);
                 $sortedIterator->setChildIterator($iterator);
             } else {
                 /* @var $sortIndex Quicksort */
                 $sortIndex = $sortedIterator->getSortIndexByColumns($primaryKeyColumns);
                 foreach ($tableResource as $rowId => $row) {
                     $sortIndex->addRow($rowId, $row);
                 }
                 $sortIndex->sort();
                 $sortedIterator->setChildIterator($sortIndex);
             }
         }
         foreach ($sortedIterator as $rowId => $row) {
             $executionContext->setCurrentSourceRow($row);
             $isConditionMatch = true;
             if (!is_null($conditionValue)) {
                 $isConditionMatch = $this->valueResolver->resolveValue($conditionValue, $executionContext);
             }
             if ($isConditionMatch) {
                 if (!is_null($limitOffset) && $rowSkip < $limitOffset) {
                     $rowSkip++;
                     continue;
                 }
                 if (!is_null($limitCount) && $rowCount > $limitCount) {
                     continue;
                 }
                 $rowCount++;
                 foreach ($tableResource->getTableSchema()->getIndexIterator() as $indexId => $indexPage) {
                     /* @var $indexPage Index */
                     /* @var $indexResource Index */
                     $indexResource = $tableResource->getIndex($indexId);
                     $originalRow = $tableResource->getRowData($rowId);
                     $rowIdStr = $this->decstr($rowId);
                     $indexResource->removeRow($originalRow, $rowIdStr);
                 }
                 $tableResource->removeRow($rowId);
             }
         }
     }
     return $result;
 }