Get the full SQL statement.

@param  bool $usePlaceholders optional use ? placeholders, default true
@return string full SQL statement
2610
public function getStatement($usePlaceholders = true)
    {
        $statement = "";
        if ($this->isSelect()) {
            $statement = $this->getSelectStatement($usePlaceholders);
        } elseif ($this->isInsert()) {
            $statement = $this->getInsertStatement($usePlaceholders);
        } elseif ($this->isReplace()) {
            $statement = $this->getReplaceStatement($usePlaceholders);
        } elseif ($this->isUpdate()) {
            $statement = $this->getUpdateStatement($usePlaceholders);
        } elseif ($this->isDelete()) {
            $statement = $this->getDeleteStatement($usePlaceholders);
        }
        return $statement;
    }
1329482
public function getWhereString($usePlaceholders = true, $includeText = true)
    {
        $statement = $this->getCriteriaString($this->where, $usePlaceholders, $this->wherePlaceholderValues);

        if ($includeText && $statement) {
            $statement = "WHERE " . $statement;
        }

        return $statement;
    }
408557
public function buildString(array $variables = [], bool $useExisting = true): string
    {
        if ($useExisting === true) {
            $variables = \array_merge($this->variables, $variables);
        }

        $tmp = [];
        foreach ($variables as $name => $val) {
            if ($val !== null) {
                $tmp[] = $name.'='.\urlencode((string)$val);
            }
        }

        $ret = '';
        if (\count($tmp) > 0) {
            $ret .= '?'.\implode('&', $tmp);
        }
        return $ret;
    }
925759
private function getDeleteStatement($usePlaceholders = true)
    {
        $statement = "";

        if (!$this->isDelete()) {
            return $statement;
        }

        $statement .= $this->getDeleteString();

        if ($this->from) {
            $statement .= " " . $this->getFromString();
        }

        if ($this->where) {
            $statement .= " " . $this->getWhereString($usePlaceholders);
        }

        // ORDER BY and LIMIT are only applicable when deleting from a single
        // table.
        if ($this->isDeleteTableFrom()) {
            if ($this->orderBy) {
                $statement .= " " . $this->getOrderByString();
            }

            if ($this->limit) {
                $statement .= " " . $this->getLimitString();
            }
        }

        return $statement;
    }
848438
public function groupByToSql(bool $useClause = true): array
    {
        $sql = $params = [];

        foreach ($this->groupBy as $groupBy) {
            $sql[] = $groupBy['sql'];

            $groupBy['params'] && $params = array_merge($params, $groupBy['params']);
        }

        $sql = implode(', ', $sql);

        if ($sql and $useClause) {
            $sql = 'GROUP BY ' . $sql;
        }

        return [$sql, $params];
    }
854264
public function findAllPlatformRoles($includeRoleUser = true, $getBuilder = false)
    {
        $queryBuilder = $this
            ->createQueryBuilder('role')
            ->andWhere('role.type = :roleType')
            ->setParameter('roleType', Role::PLATFORM_ROLE);
        $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->eq('role.name', '?1')))
            ->setParameter(1, 'ROLE_ANONYMOUS');

        if (!$includeRoleUser) {
            $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->eq('role.name', '?2')))
                ->setParameter(2, 'ROLE_USER');
        }

        if ($getBuilder) {
            return $queryBuilder;
        }

        $query = $queryBuilder->getQuery();

        return $query->getResult();
    }
343574
public function getPHP($includeprevious=true) {

        $result = '';

        // The XMLDBTYPE
        switch ($this->getType()) {
            case XMLDB_TYPE_INTEGER:
                $result .= 'XMLDB_TYPE_INTEGER' . ', ';
                break;
            case XMLDB_TYPE_NUMBER:
                $result .= 'XMLDB_TYPE_NUMBER' . ', ';
                break;
            case XMLDB_TYPE_FLOAT:
                $result .= 'XMLDB_TYPE_FLOAT' . ', ';
                break;
            case XMLDB_TYPE_CHAR:
                $result .= 'XMLDB_TYPE_CHAR' . ', ';
                break;
            case XMLDB_TYPE_TEXT:
                $result .= 'XMLDB_TYPE_TEXT' . ', ';
                break;
            case XMLDB_TYPE_BINARY:
                $result .= 'XMLDB_TYPE_BINARY' . ', ';
                break;
            case XMLDB_TYPE_DATETIME:
                $result .= 'XMLDB_TYPE_DATETIME' . ', ';
                break;
            case XMLDB_TYPE_TIMESTAMP:
                $result .= 'XMLDB_TYPE_TIMESTAMP' . ', ';
                break;
        }
        // The length
        $length = $this->getLength();
        $decimals = $this->getDecimals();
        if (!empty($length)) {
            $result .= "'" . $length;
            if (!empty($decimals)) {
                $result .= ', ' . $decimals;
            }
            $result .= "', ";
        } else {
            $result .= 'null, ';
        }
        // Unsigned is not used any more since Moodle 2.3
        $result .= 'null, ';
        // Not Null
        $notnull = $this->getNotnull();
        if (!empty($notnull)) {
            $result .= 'XMLDB_NOTNULL' . ', ';
        } else {
            $result .= 'null, ';
        }
        // Sequence
        $sequence = $this->getSequence();
        if (!empty($sequence)) {
            $result .= 'XMLDB_SEQUENCE' . ', ';
        } else {
            $result .= 'null, ';
        }
        // Default
        $default =  $this->getDefault();
        if ($default !== null && !$this->getSequence()) {
            $result .= "'" . $default . "'";
        } else {
            $result .= 'null';
        }
        // Previous (decided by parameter)
        if ($includeprevious) {
            $previous = $this->getPrevious();
            if (!empty($previous)) {
                $result .= ", '" . $previous . "'";
            } else {
                $result .= ', null';
            }
        }
        // Return result
        return $result;
    }
1124653
protected function getTermPlaceholders()
    {
        $placeholders = [];

        foreach ($this->repository as $field) {
            $placeholders[$field->getName()] = $field->getOption('placeholder');
        }

        return $placeholders;
    }
817803
public function havingToSql($useClause = true): array
    {
        [$sql, $params] = $this->hConditions()->toSql();

        if ($sql and $useClause) {
            $sql = 'HAVING ' . $sql;
        }

        return [$sql, $params];
    }
764472
protected function prepareExpressionPlaceholders($sql)
    {
        if (!count($this->expressions)) {
            return $sql;
        }
        $sql = str_replace(array_keys($this->expressions), array_values($this->expressions), $sql);

        return $sql;
    }
1360049
static function Replace($placeholder)
    {
        $args = func_get_args();    
        array_shift($args);
        return self::ReplaceArgsUsing($placeholder, null, $args);
    }
154072
private function getInsertStatement($usePlaceholders = true)
    {
        $statement = "";

        if (!$this->isInsert()) {
            return $statement;
        }

        $statement .= $this->getInsertString();

        if ($this->isInto) {
            $statement .= " " . $this->getIntoString($usePlaceholders);
        } else {
            if ($this->set) {
                $statement .= " " . $this->getSetString($usePlaceholders);
            }
        }
        return $statement;
    }
1056144
public function getPlaces($layoutSrc)
	{
		$places = array();

		// Ignore CDATA
		$cdataCallback = function($cdata) {};

		// Collect place holders
		$macroCallback = function($func, array $args) use (&$places, $layoutSrc) {
					if ($func == HtmlProcessor::PLACE_HOLDER) {
						if ( ! array_key_exists(0, $args) || $args[0] == '') {
							throw new \RuntimeException("No placeholder name defined in the placeHolder macro in file {$layoutSrc}");
						}

						// Normalize placeholder ID for case insensitive MySQL varchar field
						$places[] = mb_strtolower($args[0]);
					}
				};

		$this->walk($layoutSrc, $cdataCallback, $macroCallback);

		return $places;
	}
783065
private function getUpdateClause()
	{
		$placeholders = [];

		foreach ($this->values as $key => $value) {
			$placeholders[] = sprintf('%s = %s', $key, $value);
		}

		return sprintf('UPDATE %s SET %s', $this->table, implode(', ', $placeholders));
	}
607913
protected function _getWhereQuery($useDirty = true)
    {
        $where = array();
        $db = $this->_getTable()->getAdapter();
        $primaryKey = $this->_getPrimaryKey($useDirty);
        $info = $this->_getTable()->info();
        $metadata = $info[Zend_Db_Table_Abstract::METADATA];

        // retrieve recently updated row using primary keys
        $where = array();
        foreach ($primaryKey as $column => $value) {
            $tableName = $db->quoteIdentifier($info[Zend_Db_Table_Abstract::NAME], true);
            $type = $metadata[$column]['DATA_TYPE'];
            $columnName = $db->quoteIdentifier($column, true);
            $where[] = $db->quoteInto("{$tableName}.{$columnName} = ?", $value, $type);
        }
        return $where;
    }
533624
private function getPlaceholders($navItemPageId, $placeholderVar, $prevId)
    {
        return (new Query())
            ->from('cms_nav_item_page_block_item t1')
            ->select(['t1.id', 't1.block_id', 't1.json_config_values', 't1.json_config_cfg_values', 't1.variation', 't2.class'])
            ->innerJoin('cms_block t2', 't2.id=t1.block_id')
            ->where(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId, 'is_hidden' => 0])
            ->orderBy(['sort_index' => SORT_ASC])
            ->all();
    }
611343
protected function placeholderResolver()
    {
        if (null === $this->placeholderResolver) {
            $this->placeholderResolver = new RegexPlaceholderResolver(new ConfigurationDataSource($this), '%', '%');
        }

        return $this->placeholderResolver;
    }