コード例 #1
0
ファイル: UpdateExecutor.php プロジェクト: addiks/phpsql
 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;
 }