本文整理汇总了PHP中Illuminate\Database\Query\Grammars\Grammar类的典型用法代码示例。如果您正苦于以下问题:PHP Grammar类的具体用法?PHP Grammar怎么用?PHP Grammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Grammar类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rollBack
/**
* Rollback the active database transaction.
*
* @return void
*/
public function rollBack()
{
if ($this->transactions == 1) {
$this->getPdo()->rollBack();
} elseif ($this->transactions > 1 && $this->queryGrammar->supportsSavepoints()) {
$this->getPdo()->exec($this->queryGrammar->compileSavepointRollBack('trans' . $this->transactions));
}
$this->transactions = max(0, $this->transactions - 1);
$this->fireConnectionEvent('rollingBack');
}
示例2: rollBack
/**
* Rollback the active database transaction.
*
* @param int|null $toLevel
* @return void
*/
public function rollBack($toLevel = null)
{
if (is_null($toLevel)) {
$toLevel = $this->transactions - 1;
}
if ($toLevel < 0 || $toLevel >= $this->transactions) {
return;
}
if ($toLevel == 0) {
$this->getPdo()->rollBack();
} elseif ($this->queryGrammar->supportsSavepoints()) {
$this->getPdo()->exec($this->queryGrammar->compileSavepointRollBack('trans' . ($toLevel + 1)));
}
$this->transactions = $toLevel;
$this->fireConnectionEvent('rollingBack');
}
示例3: getMockConnection
protected function getMockConnection()
{
$connection = m::mock('Illuminate\\Database\\Connection');
$connection->shouldReceive('getQueryGrammar')->andReturn($grammar = new Grammar());
$grammar->setTablePrefix('prefix_');
$connection->shouldReceive('getPostProcessor')->andReturn(m::mock('Illuminate\\Database\\Query\\Processors\\Processor'));
$connection->shouldReceive('getPdo')->andReturn($pdo = m::mock('stdClass'));
return $connection;
}
示例4: compileInsert
/**
* Compile an insert statement into SQL.
*
* @param Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileInsert(Builder $query, array $values)
{
// Essentially we will force every insert to be treated as a batch insert which
// simply makes creating the SQL easier for us since we can utilize the same
// basic routine regardless of an amount of records given to us to insert.
$table = $this->wrapTable($query->from);
if (!is_array(reset($values))) {
$values = array($values);
}
// If there is only one record being inserted, we will just use the usual query
// grammar insert builder because no special syntax is needed for the single
// row inserts in SQLite. However, if there are multiples, we'll continue.
if (count($values) == 1) {
return parent::compileInsert($query, $values[0]);
}
$names = $this->columnize(array_keys($values[0]));
$columns = array();
// SQLite requires us to build the multi-row insert as a listing of select with
// unions joining them together. So we'll build out this list of columns and
// then join them all together with select unions to complete the queries.
foreach (array_keys($values[0]) as $column) {
$columns[] = '? as ' . $this->wrap($column);
}
$columns = array_fill(9, count($values), implode(', ', $columns));
return "insert into {$table} ({$names}) select " . implode(' union select ', $columns);
}
示例5: compileSelect
/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileSelect(Builder $query)
{
$sql = parent::compileSelect($query);
if ($query->unions) {
$sql = '(' . $sql . ') ' . $this->compileUnions($query);
}
return $sql;
}
示例6: compileFrom
/**
* Compile the "from" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @return string
*/
protected function compileFrom(Builder $query, $table)
{
$from = parent::compileFrom($query, $table);
if (is_string($query->lock)) {
return $from . ' ' . $query->lock;
}
if (!is_null($query->lock)) {
return $from . ' with(rowlock,' . ($query->lock ? 'updlock,' : '') . 'holdlock)';
}
return $from;
}
示例7: compileUpdate
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileUpdate(Builder $query, $values)
{
$sql = parent::compileUpdate($query, $values);
if (isset($query->orders)) {
$sql .= ' ' . $this->compileOrders($query, $query->orders);
}
if (isset($query->limit)) {
$sql .= ' ' . $this->compileLimit($query, $query->limit);
}
return rtrim($sql);
}
示例8: delete
/**
* Delete a record from the database.
*
* @param array $values
* @return int
*/
public function delete($id = null)
{
// If an ID is passed to the method, we will set the where clause to check
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
if (!is_null($id)) {
$this->where('id', '=', $id);
}
$sql = $this->grammar->compileDelete($this);
return $this->connection->delete($sql, $this->bindings);
}
示例9: compileSelect
/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder
* @return string
*/
public function compileSelect(Builder $query)
{
$sql = parent::compileSelect($query);
if ($query->unions) {
$sql = '(' . $sql . ') ' . $this->compileUnions($query);
}
if (isset($query->limit) || isset($query->offset)) {
$limit = isset($query->limit) ? ' first ' . (int) $query->limit : '';
$offset = isset($query->offset) ? ' skip ' . (int) $query->offset : '';
$sql = str_replace("select", "select" . $limit . $offset, $sql);
}
return $sql;
}
示例10: truncate
/**
* Run a truncate statement on the table.
*
* @return void
*/
public function truncate()
{
foreach ($this->grammar->compileTruncate($this) as $sql => $bindings) {
$this->connection->statement($sql, $bindings);
}
}
示例11: wrapTable
/**
* Wrap a table in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $table
* @return string
*/
public function wrapTable($table)
{
return $this->wrapTableValuedFunction(parent::wrapTable($table));
}
示例12: wrapValue
/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if (Config::get('oracledb::database.quoting') === true) {
return parent::wrapValue($value);
}
return $value;
}
示例13: prepareBindingsForUpdate
/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
foreach ($values as $column => $value) {
if ($this->isJsonSelector($column) && in_array(gettype($value), ['boolean', 'integer', 'double'])) {
unset($values[$column]);
}
}
return parent::prepareBindingsForUpdate($bindings, $values);
}
示例14: wrapValue
/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if ($this->isReserved($value)) {
return parent::wrapValue($value);
}
return $value !== '*' ? sprintf($this->wrapper, $value) : $value;
}