/**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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');
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
Esempio n. 6
0
 /**
  * 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);
 }
 /**
  * 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;
 }
Esempio n. 8
0
 /**
  * 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');
 }
Esempio n. 9
0
 /**
  * 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);
     }
 }
 /**
  * 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));
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
 /**
  * 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;
 }
Esempio n. 13
0
 /**
  * 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);
 }
 /**
  * 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;
 }