Author: Gabor de Mooij and the RedBeanPHP Community.
Inheritance: extends RedBeanPHP\Observable, implements RedBeanPHP\Adapter
Ejemplo n.º 1
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     $this->adapter->exec('SET CONSTRAINTS ALL DEFERRED');
     foreach ($this->getTables() as $t) {
         $t = $this->esc($t);
         $this->adapter->exec("DROP TABLE IF EXISTS {$t} CASCADE ");
     }
     $this->adapter->exec('SET CONSTRAINTS ALL IMMEDIATE');
 }
Ejemplo n.º 2
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     foreach ($this->getTables() as $t) {
         foreach ($this->getKeyMapForType($t) as $k) {
             $this->adapter->exec("ALTER TABLE \"{$t}\" DROP FOREIGN KEY \"{$k['name']}\"");
         }
     }
     foreach ($this->getTables() as $t) {
         $this->adapter->exec("DROP TABLE \"{$t}\"");
     }
 }
Ejemplo n.º 3
0
 /**
  * Trash all beans of a given type. Wipes an entire type of bean.
  *
  * @param string $type type of bean you wish to delete all instances of
  *
  * @return boolean
  *
  * @throws SQLException
  */
 public function wipe($type)
 {
     try {
         $this->writer->wipe($type);
         return TRUE;
     } catch (SQLException $exception) {
         if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) {
             throw $exception;
         }
         return FALSE;
     }
 }
Ejemplo n.º 4
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     $this->adapter->exec('SET CONSTRAINTS ALL DEFERRED');
     foreach ($this->getTables() as $t) {
         $t = $this->esc($t);
         //Some plugins (PostGIS have unremovable tables/views), avoid exceptions.
         try {
             $this->adapter->exec("DROP TABLE IF EXISTS {$t} CASCADE ");
         } catch (\Exception $e) {
         }
     }
     $this->adapter->exec('SET CONSTRAINTS ALL IMMEDIATE');
 }
Ejemplo n.º 5
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     foreach ($this->getTables() as $t) {
         try {
             $foreignKeys = $this->adapter->getAssoc("SELECT\n\t\t\t\t    'ALTER TABLE ' +  OBJECT_SCHEMA_NAME(parent_object_id) +\n\t\t\t\t    '.[' + OBJECT_NAME(parent_object_id) +\n\t\t\t\t    '] DROP CONSTRAINT ' + name\n\t\t\t\tFROM sys.foreign_keys\n\t\t\t\tWHERE referenced_object_id = object_id('{$t}')");
             if (count($foreignKeys)) {
                 foreach ($foreignKeys as $sql) {
                     $this->adapter->exec($sql);
                 }
             }
             $this->adapter->exec("IF OBJECT_ID('[{$t}]', 'U') IS NOT NULL DROP TABLE [{$t}];");
         } catch (SQLException $e) {
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     $this->adapter->exec('SET FOREIGN_KEY_CHECKS = 0;');
     foreach ($this->getTables() as $t) {
         try {
             $this->adapter->exec("DROP TABLE IF EXISTS `{$t}`");
         } catch (\Exception $e) {
         }
         try {
             $this->adapter->exec("DROP VIEW IF EXISTS `{$t}`");
         } catch (\Exception $e) {
         }
     }
     $this->adapter->exec('SET FOREIGN_KEY_CHECKS = 1;');
 }
Ejemplo n.º 7
0
 /**
  * @see QueryWriter::wipeAll
  */
 public function wipeAll()
 {
     $this->adapter->exec('PRAGMA foreign_keys = 0 ');
     foreach ($this->getTables() as $t) {
         try {
             $this->adapter->exec("DROP TABLE IF EXISTS `{$t}`");
         } catch (\Exception $e) {
         }
         try {
             $this->adapter->exec("DROP TABLE IF EXISTS `{$t}`");
         } catch (\Exception $e) {
         }
     }
     $this->adapter->exec('PRAGMA foreign_keys = 1 ');
 }
Ejemplo n.º 8
0
 /**
  * Returns the current logger instance being used by the
  * database object.
  *
  * @return Logger
  */
 public static function getLogger()
 {
     return self::$adapter->getDatabase()->getLogger();
 }
Ejemplo n.º 9
0
 /**
  * @see QueryWriter::wipe
  */
 public function wipe($type)
 {
     $table = $this->esc($type);
     $this->adapter->exec("TRUNCATE {$table} ");
 }
Ejemplo n.º 10
0
 /**
  * Closes the database connection.
  *
  * @return void
  */
 public static function close()
 {
     if (isset(self::$adapter)) {
         self::$adapter->close();
     }
 }