statement() public method

Execute an SQL statement and return the boolean result.
public statement ( string $query, array $bindings = [] ) : boolean
$query string
$bindings array
return boolean
Example #1
0
 /**
  * function to safely drop trigger db object
  *
  * @param  string $name
  * @return boolean
  */
 public function drop($name)
 {
     if (!$name) {
         return false;
     }
     return $this->connection->statement("\n            declare\n                e exception;\n                pragma exception_init(e,-4080);\n            begin\n                execute immediate 'drop trigger {$name}';\n            exception\n            when e then\n                null;\n            end;");
 }
Example #2
0
 /**
  * function to safely drop sequence db object
  *
  * @param  string $name
  * @return boolean
  */
 public function drop($name)
 {
     // check if a valid name and sequence exists
     if (!$name or !$this->exists($name)) {
         return false;
     }
     return $this->connection->statement("\n            declare\n                e exception;\n                pragma exception_init(e,-02289);\n            begin\n                execute immediate 'drop sequence {$name}';\n            exception\n            when e then\n                null;\n            end;");
 }
Example #3
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);
     }
 }
Example #4
0
 /**
  * Disable foreign key constraints.
  *
  * @return bool
  */
 public function disableForeignKeyConstraints()
 {
     return $this->connection->statement($this->grammar->compileDisableForeignKeyConstraints());
 }
Example #5
0
 /**
  * Execute the statements against the database.
  *
  * @param  array $statements
  * @return void
  */
 protected function build($statements)
 {
     foreach ($statements as $statement) {
         $this->connection->statement($statement);
     }
 }
Example #6
0
 /**
  * Run the comment on column statement
  *
  * @param  string $table
  * @param  string $column
  * @param  string $comment
  */
 private function commentColumn($table, $column, $comment)
 {
     $table = $this->wrapValue($table);
     $column = $this->wrapValue($column);
     $this->connection->statement("comment on column {$table}.{$column} is '{$comment}'");
 }
 /**
  * @param Connection $db
  * @param array      $creds
  * @param string     $fromServer
  *
  * @return bool
  */
 protected function revokePrivileges($db, $creds, $fromServer)
 {
     return $db->transaction(function () use($db, $creds, $fromServer) {
         //  Create users
         $_users = $this->getDatabaseUsers($creds, $fromServer);
         try {
             foreach ($_users as $_user) {
                 //	Grants for instance database
                 if (!($_result = $db->statement('REVOKE ALL PRIVILEGES ON ' . $creds['database'] . '.* FROM ' . $_user))) {
                     $this->error('[provisioning:database] error revoking privileges from "' . $_user . '"');
                     continue;
                 }
                 $this->debug('[provisioning:database] grants revoked - complete');
                 if (!($_result = $db->statement('DROP USER ' . $_user))) {
                     $this->error('[provisioning:database] error dropping user "' . $_user . '"');
                 }
                 $_result && $this->debug('[provisioning:database] users dropped > ', $_users);
             }
             return true;
         } catch (\Exception $_ex) {
             $this->error('[provisioning:database] revoke grants - failure: ' . $_ex->getMessage());
             return false;
         }
     });
 }
Example #8
0
 /**
  * @param \Illuminate\Database\Connection $db
  */
 protected function configurePragma(Connection $db)
 {
     if ($this->configuration['driver'] !== 'sqlite') {
         return;
     }
     // Enable foreign keys for the current connection/file
     $db->statement('PRAGMA foreign_keys = ON;');
     // Create sqlite-journal in memory only (instead of creating disk files)
     $db->statement('PRAGMA journal_mode = MEMORY;');
     // Do not wait for OS after sending write commands
     $db->statement('PRAGMA synchronous = OFF;');
 }
 /**
  * Execute the blueprint against the database.
  *
  * @param  Illuminate\Database\Connection  $connection
  * @param  Illuminate\Database\Schema\Grammars\Grammar $grammar
  * @return void
  */
 public function build(Connection $connection, Grammar $grammar)
 {
     foreach ($this->toSql($grammar) as $statement) {
         $connection->statement($statement);
     }
 }