Ejemplo n.º 1
0
 /**
  * @brief Apply a specific update on the database
  * @param DBUpdateDescriptor $update The update to apply
  */
 public function applyUpdate($update)
 {
     printf("Upgrading DB Schema to %s...\n", $update->getTargetVersion());
     $sql_commands = array();
     // New tables
     foreach ($update->getNewTables() as $table) {
         $sql_commands[] = $table->getSQL();
     }
     // New Column modifications
     foreach ($update->getNewColumns() as $columns) {
         $sql_commands[] = $columns->getSQL();
     }
     // Modified Columns
     foreach ($update->getModifiedColumns() as $modification) {
         $sql_commands[] = $modification->getSQL();
     }
     //Execute all SQL commands
     foreach ($sql_commands as $sql) {
         $res = $this->db_conn->query($sql);
         if (!$res) {
             printf($sql);
             throw new RuntimeException("Error executing SQL query: " . $this->db_conn->error);
         }
     }
     // Mark update log for this change
     $res = $this->db_conn->query("INSERT INTO `update_log` (`version_major`, `version_minor`) VALUES(" . "'" . $this->db_conn->real_escape_string($update->getTargetVersion()->getMajor()) . "'," . "'" . $this->db_conn->real_escape_string($update->getTargetVersion()->getMinor()) . "');");
     if (!$res) {
         throw new RuntimeException("Error executing SQL query: " . $this->db_conn->error);
     }
 }