Example #1
0
 public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR)
 {
     if (!$this->schemaManager->databaseExists($name)) {
         // Check DB creation permisson
         if (!$create) {
             if ($errorLevel !== false) {
                 user_error("Attempted to connect to non-existing database \"{$name}\"", $errorLevel);
             }
             // Unselect database
             $this->connector->unloadDatabase();
             return false;
         }
         $this->schemaManager->createDatabase($name);
     }
     // Reconnect using the existing parameters
     $parameters = $this->parameters;
     $parameters['database'] = $name;
     $this->connect($parameters);
     return true;
 }
 public function checkAndRepairTable($tableName = null)
 {
     $ok = true;
     if (!SapphireTest::using_temp_db() && !self::$checked_and_repaired) {
         $this->alterationMessage("Checking database integrity", "repaired");
         // Check for any tables with failed integrity
         if ($messages = $this->query('PRAGMA integrity_check')) {
             foreach ($messages as $message) {
                 if ($message['integrity_check'] != 'ok') {
                     Debug::show($message['integrity_check']);
                     $ok = false;
                 }
             }
         }
         // If enabled vacuum (clean and rebuild) the database
         if (self::$vacuum) {
             $this->query('VACUUM', E_USER_NOTICE);
             $message = $this->database->getConnector()->getLastError();
             if (preg_match('/authoriz/', $message)) {
                 $this->alterationMessage("VACUUM | {$message}", "error");
             } else {
                 $this->alterationMessage("VACUUMing", "repaired");
             }
         }
         self::$checked_and_repaired = true;
     }
     return $ok;
 }