本文整理汇总了PHP中Illuminate\Database\Query\Builder::toSql方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::toSql方法的具体用法?PHP Builder::toSql怎么用?PHP Builder::toSql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::toSql方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getArrayFromQuery
/**
* Is used for quick selecting of big number of records from database without creating ORM objects
* @param \Illuminate\Database\Query\Builder $query - Query Builder object
* @return array $results - results of query
*/
private static function getArrayFromQuery($query)
{
$sql = $query->toSql();
foreach ($query->getBindings() as $binding) {
$value = is_numeric($binding) ? $binding : "'" . $binding . "'";
$sql = preg_replace('/\\?/', $value, $sql, 1);
}
$results = \DB::select($sql);
return $results;
}
示例2: vsprintf
/**
* Render query SQL string.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
function render_sql(\Illuminate\Database\Query\Builder $query)
{
return vsprintf($query->toSql(), $query->getBindings());
}
示例3: selectWhereIn
private function selectWhereIn($keys, Builder $query)
{
$results = [];
foreach (array_chunk($keys, 500) as $chunk) {
$results = array_merge($results, $this->connection->table($this->connection->raw("({$query->toSql()}) as query"))->whereIn("__key", $chunk)->get());
}
return collect($results)->keyBy("__key")->toArray();
}
示例4: getValue
/**
* Evaluate query as string.
*
* @return string
*/
public function getValue()
{
$sql = '(' . $this->query->toSql() . ')';
if ($this->alias) {
$alias = $this->query->getGrammar()->wrapTable($this->alias);
$sql .= ' as ' . $alias;
}
return $sql;
}
示例5: toSql
public static function toSql(Builder $query)
{
$sql = $query->toSql();
$connection = $query->getConnection();
$pdo = $connection->getPdo();
$bindings = $query->getBindings();
$bindings = $connection->prepareBindings($bindings);
if (!empty($bindings)) {
foreach ($bindings as $binding) {
$sql = preg_replace('/\\?/', $pdo->quote($binding), $sql, 1);
}
}
return $sql;
}
示例6: toSql
/**
* Get the SQL representation of the query.
*
* @return string
* @static
*/
public static function toSql()
{
return \Illuminate\Database\Query\Builder::toSql();
}
示例7: whereCountQuery
/**
* Add a sub query count clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $operator
* @param int $count
* @param string $boolean
* @return $this
*/
protected function whereCountQuery(QueryBuilder $query, $operator = '>=', $count = 1, $boolean = 'and')
{
if (is_numeric($count)) {
$count = new Expression($count);
}
$this->query->addBinding($query->getBindings(), 'where');
return $this->where(new Expression('(' . $query->toSql() . ')'), $operator, $count, $boolean);
}
示例8: getQueryKey
protected function getQueryKey(Builder $builder, $other = null)
{
$name = $builder->getConnection()->getName();
return md5($name . $builder->toSql() . serialize($builder->getBindings()) . $other);
}
示例9: getConditionStringFromQueryBuilder
/**
* Extracts a raw WHERE clause string from a QueryBuilder instance.
* Note that this is practically identical to the original Listify.
*
* @param QueryBuilder $query A Query Builder instance
* @return string
*/
protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
{
$initialQueryChunks = explode('where ', $query->toSql());
if (count($initialQueryChunks) == 1) {
throw new InvalidArgumentException('The query builder instance must have a where clause to build a condition string from');
}
$queryChunks = explode('?', $initialQueryChunks[1]);
$chunkCount = count($queryChunks);
$bindings = $query->getBindings();
$whereString = '';
for ($i = 0; $i < $chunkCount; $i++) {
$whereString .= $queryChunks[$i];
if (isset($bindings[$i])) {
if (gettype($bindings[$i]) === 'string') {
$whereString .= '"' . $bindings[$i] . '"';
}
}
}
return $whereString;
}
示例10: toSql
/**
* Return sql statement
*
* @param Builder $queryBuilder
* @return string
*/
public static function toSql(Builder $queryBuilder)
{
$params = $queryBuilder->getBindings();
$pdoStatement = $queryBuilder->toSql();
foreach ($params as $param) {
$param = is_int($param) ? $param : "'{$param}'";
$pdoStatement = str_replace_first('?', $param, $pdoStatement);
}
return str_replace('`', '', $pdoStatement);
}
示例11: toSql
/**
* Get the SQL representation of the query.
*
* @return string
*/
public function toSql()
{
return $this->query->toSql();
}
示例12: generateQueryHashFromQueryBuilder
/**
* @param Builder $qb
* @param array $attributes
*/
private function generateQueryHashFromQueryBuilder(Builder $qb, array $attributes)
{
$this->actualQueryHash = sha1(implode('_', [$this->cacheHashKeyPrefix, $qb->toSql(), serialize($qb->getBindings()), serialize($attributes)]));
}