Creates database view.

@param string $name View name.
@param Query  $query Query that is used to create view.
@param bool   $replace Whether to replace existing view with the same name.

@throws \yii\db\Exception
@see dropView
501581
public function createView ($name, Query $query, $replace = true)
		{
			echo "    > create table $name ...";
			$time = microtime(true);

			$sql = 'CREATE' . ( $replace ? ' OR REPLACE' : '' ) . ' VIEW ' . $this->db->quoteTableName($name) . ' AS ' . $query->createCommand()->getRawSql();
			$this->db->createCommand($sql)->execute();

			echo '    > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
		}
1048081
protected function createView($name = null)
    {
        if ($name == null) {
            $name = $this->action();
        }
        Artisan::call('make:view', [
            'name' => $name
        ]);
        $this->info('View ' . undot_path($name) .'.blade.php created.');
    }
942617
public function dropView ($name)
		{
			echo "    > drop view $name ...";
			$time = microtime(true);
			$this->db->createCommand('DROP VIEW IF EXISTS ' . $this->db->quoteTableName($name))->execute();
			echo '    > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
		}
455165
public function exec($query, $args = array(), $removeCache = null)
    {
        if ($this->connection) {
            if ($this->getCache() && $removeCache) {
                $this->getCache()->remove($removeCache);
            }
            return $this->connection->select($query, $args, false);
        }
        throw new \Exception('Database connection is not open!');
    }
1085415
public function get_view( $name, $args = [], $echo = false, $error = true, $remove_nl = false ) {
		$name = trim( $name, '/' . DS );
		$name = str_replace( '/', DS, $name );
		$name .= '.php';
		$path = null;
		foreach ( $this->get_check_view_dirs() as $dir ) {
			$dir = rtrim( $dir, DS . '/' );
			if ( is_readable( $dir . DS . $name ) ) {
				$path = $dir . DS . $name;
				break;
			}
		}

		$view = '';
		if ( isset( $path ) ) {
			unset( $name );
			$args = $this->get_presenter_args( $args );
			extract( $args, EXTR_SKIP );

			ob_start();
			/** @noinspection PhpIncludeInspection */
			@include $path;
			$view = ob_get_contents();
			ob_end_clean();
		} elseif ( $error ) {
			$this->app->log( sprintf( 'View file [ %s ] not found.', $name ) );
		}

		if ( $remove_nl ) {
			$view = str_replace( [ "\r\n", "\r", "\n" ], ' ', $view );
		}

		if ( $echo ) {
			echo $view;
		}

		return $view;
	}
888970
public function create($name)
	{
		$model = Bauhaus::getInstance($name)->buildForm();

		return View::make($model->getView('create'))
			->with('name',  $name)
			->with('model', $model);
	}
122236
public function createFilter($search, $replace)
    {
        if (!isset($this->filters[$search][$replace])) {
            if (!isset($this->filters[$search])) {
                $this->filters[$search] = [];
            }

            if (!isset($this->filters[$search][$replace])) {
                $this->filters[$search][$replace] = [];
            }

            $this->filters[$search][$replace] = new Swift_StreamFilters_StringReplacementFilter($search, $replace);
        }

        return $this->filters[$search][$replace];
    }
1105836
public function selectDatabase($name)
    {
        $response = $this->client->request('GET', sprintf('/%s/', $name));

        if (404 === $response->getStatusCode()) {
            throw new Exception(sprintf('The database "%s" does not exist', $name));
        }

        return $this->wrapDatabase($name);
    }
485207
public function createView(View $view)
    {
        $this->_execSql($this->_platform->getCreateViewSQL($view->getQuotedName($this->_platform), $view->getSql()));
    }
82142
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
    {
        $where = $query->getWhere();
        if (!$where && !$this->wantsTemporary($query)) {
            $from = array_values($query->getFrom());
            $query->addWhere("{$from[0]}.\"MultiFormIsTemporary\" = '0'");
            return;
        }
        $filterKey = key($where[0]);
        if (strpos($filterKey, ".`ID` = ") === false
            && strpos($filterKey, ".ID = ") === false
            && strpos($filterKey, "ID = ") !== 0
            && !$this->wantsTemporary($query)
        ) {
            $from = array_values($query->getFrom());
            $query->addWhere("{$from[0]}.\"MultiFormIsTemporary\" = '0'");
        }
    }
139928
private function cloneQuery(Query $query)
    {
        /* @var $cloneQuery Query */
        $cloneQuery = clone $query;
        $cloneQuery->setParameters($query->getParameters());
        foreach ($query->getHints() as $name => $value) {
            $cloneQuery->setHint($name, $value);
        }

        return $cloneQuery;
    }
241826
public function setParam($name, $value, $replace = true)
    {
        if (is_array($name)) {
            if (!isset($this->components[self::QUERY])) {
                $this->components[self::QUERY] = [];
            }
            TreeTools::setByPath($this->components[self::QUERY], $name, $value);
        } else {
            if (isset($this->components[self::QUERY][$name]) && !$replace) {
                return $this;
            }
            $this->components[self::QUERY][$name] = $value;
        }
        return $this;
    }
355597
public function dropIndex($name)
    {
        if (is_array($name))
            $name = $this->name.'___'.implode('__', $name);
        elseif(!is_int(strpos($name,'___')))
            $name = $this->name.'___'.$name;
        $name = $this->db->quotekey($name);
        $table = $this->db->quotekey($this->name);
        $cmd = array(
            'pgsql|sqlite2?|ibm' =>
                "DROP INDEX $name;",
            'mssql|sybase|dblib|odbc|sqlsrv' =>
                "DROP INDEX $table.$name;",
            'mysql'=>
                "ALTER TABLE $table DROP INDEX $name;",
        );
        $query = $this->findQuery($cmd);
        $this->queries[] = $query;
    }
617017
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
    {
        /** @var Locale|null $locale */
        $locale = $this->getDataQueryLocale($dataQuery);
        if (!$locale) {
            return;
        }

        // Rewrite query un-versioned
        parent::augmentSQL($query, $dataQuery);

        // Rewrite based on versioned rules
        if (!$dataQuery->getQueryParam('Versioned.mode')) {
            return;
        }

        $tables = $this->getLocalisedTables();
        $versionedMode = $dataQuery->getQueryParam('Versioned.mode');
        switch ($versionedMode) {
            // Reading a specific stage (Stage or Live)
            case 'stage':
            case 'stage_unique':
                // Rename all localised tables (note: alias remains unchanged). This is only done outside of draft.
                $stage = $dataQuery->getQueryParam('Versioned.stage');
                if ($stage !== Versioned::DRAFT) {
                    $this->renameLocalisedTables($query, $tables);
                }
                break;
            // Return all version instances
            case 'archive':
            case 'all_versions':
            case 'latest_versions':
            case 'latest_version_single':
            case 'version':
                $this->rewriteVersionedTables($query, $tables, $locale);
                break;
            default:
                throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: {$versionedMode}");
        }
    }
187886
private function addSelectionMethod(QueryBuilderResult $query, $methodName)
    {
        $findMethod = function () use ($query, $methodName) {

            $sth = $this->pdo->prepare($query->getSql());
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass->getName());
            try {
                $sth->execute(func_get_args());
            } catch (PDOException $e) {
                throw new DslSyntaxException('Failed to run query [' . $methodName . '] with parameters ' . print_r(func_get_args(), true));
            }

            switch ($query->getResultMode()) {
                case QueryBuilderResult::RESULT_SELECT_SINGLE:
                    return $sth->fetch();
                case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
                    return $sth->fetchAll();
            }

            throw new DslSyntaxException('Result Mode ' . $query->getResultMode() . ' is not implemented', DATADO_ILLEGAL_RESULT_MODE);

        };

        $this->methods[$methodName] = \Closure::bind($findMethod, $this, get_class());
    }
481685
public static function dropDatabase($name, $ifExists = null)
    {
        $query = static::getQuery();

        return static::build(
            'DROP DATABASE',
            $ifExists ? 'IF EXISTS' : null,
            $query->quoteName($name)
        );
    }
1126021
public function createViewQuery($designDocName, $viewName, DesignDocument $designDoc = null)
    {
        return new View\Query($this->httpClient, $this->databaseName, $designDocName, $viewName, $designDoc);
    }